RationalTime::to_time_string gives a malformed or wrong string when the fractional second is below 0.0001
Los mantenedores suelen responder en 1 día
@SoulmatelynchVFX ya está trabajando en esto.
Desde el 25/11/2026.
- #2112 de @SoulmatelynchVFX — abierto
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
El formato incorrecto proviene del código de fracciones de segundo en src/opentime/rationalTime.cpp (alrededor de las líneas 634-647), que usa %.7g junto con substr(1) y resize(7). Compila el programa de reproducción del issue y luego revisa el formato de la fracción y la ruta de parseo en from_time_string. Terminado cuando la reproducción no imprima líneas FAIL y el round trip se mantenga dentro de un microsegundo, con la prueba de Python test_long_running_time_string_24 todavía pasando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Required:
[x] I believe this isn't a duplicate topic
[x] This report is not related to an adapter
Select One:
[ ] Build problem
[x] Incorrect Functionality or bug
[ ] New feature or functionality
Description
When the fractional part of the seconds is between one microsecond and 0.0001 s, RationalTime::to_time_string() returns either a string with no decimal point, which from_time_string() rejects, or a well-formed string with the wrong value:
- 50 microseconds (
RationalTime(0.00005, 1.0), orRationalTime(1.0, 20000.0)) gives"00:00:00e-05"; - 3.00005 s gives
"00:00:03e-05"; - one sample at 24000 Hz (
RationalTime(1.0, 24000.0), about 0.0000417 s) gives"00:00:00.166667", which reads back as 0.166667 s, 4000 times too large; - one sample at 96000 Hz gives
"00:00:00.041667"instead of about 0.0000104 s.
The header promises microsecond precision in the "hours:minutes:seconds" form (rationalTime.h, lines 278-283):
/// @brief Return a string in the form "hours:minutes:seconds".
///
/// Seconds may have up to microsecond precision.
and the project's tests expect from_time_string(to_time_string(rt)) to give back rt (test_long_running_time_string_24). 0.0001 s and 0.001 s are formatted correctly ("00:00:00.0001", "00:00:00.001"); only fractions below 0.0001 s go wrong.
Expected: a decimal seconds field, for example "00:00:00.00005" for 50 microseconds and "00:00:00.000042" (or .000041) for 1/24000 s, which from_time_string() accepts and reads back as about the same time.
Suggestion for the cause: rationalTime.cpp, lines 634-647 formats the fraction with string_printf("%.7g", fractpart), which switches to exponent notation below 1e-4 ("5e-05", "4.166667e-05"), then substr(1) drops the first character assuming it is the 0 of "0.", and resize(7) cuts the rest. A fixed-point format for the fraction would avoid this.
Reproduction Steps
Build against the C++ library (opentime) and run:
#include <opentime/rationalTime.h>
#include <cmath>
#include <cstdio>
#include <string>
using namespace opentime::OPENTIME_VERSION_NS;
static int failures = 0;
static void
check(RationalTime rt, double parseRate, const char* label)
{
std::string ts = rt.to_time_string();
bool hasDot = ts.find('.') != std::string::npos;
ErrorStatus err;
RationalTime back = RationalTime::from_time_string(ts, parseRate, &err);
bool rejected = is_error(err);
std::string parseMsg =
rejected ? ("NO(" + err.details + ")") : std::string("yes");
printf(
"%-20s secs=%.12g -> \"%s\" (len=%zu, dot=%s) parse=%s\n",
label,
rt.to_seconds(),
ts.c_str(),
ts.size(),
hasDot ? "yes" : "NO",
parseMsg.c_str());
if (!hasDot)
{
printf(" FAIL: malformed time string, no '.' fraction field\n");
++failures;
}
if (rejected)
{
printf(" FAIL: from_time_string rejects the string to_time_string produced\n");
++failures;
}
else if (std::fabs(back.to_seconds() - rt.to_seconds()) > 1e-6)
{
// more than one microsecond away
printf(
" FAIL: round trip changes the value: got %.12g s, want %.12g s\n",
back.to_seconds(),
rt.to_seconds());
++failures;
}
}
int
main()
{
printf("=== fraction small enough for %%.7g exponential form ===\n");
check(RationalTime(0.00005, 1.0), 24.0, "5e-05 s");
check(RationalTime(3.00005, 1.0), 24.0, "3.00005 s");
check(RationalTime(1.0, 20000.0), 25.0, "1/20000 s");
printf("=== well-formed but wrong value (exponential, truncated) ===\n");
check(RationalTime(1.0, 24000.0), 24.0, "1/24000 s");
check(RationalTime(1.0, 96000.0), 24.0, "1/96000 s");
printf("=== ordinary cases (control) ===\n");
check(RationalTime(0.0, 24.0), 24.0, "zero");
check(RationalTime(0.0001, 1.0), 24.0, "1e-04 s");
check(RationalTime(0.001, 1.0), 24.0, "1e-03 s");
return failures ? 1 : 0;
}
Log output if appropriate
Observed:
=== fraction small enough for %.7g exponential form ===
5e-05 s secs=5e-05 -> "00:00:00e-05" (len=12, dot=NO) parse=NO(Error: '00:00:00e-05' - invalid time string)
FAIL: malformed time string, no '.' fraction field
FAIL: from_time_string rejects the string to_time_string produced
3.00005 s secs=3.00005 -> "00:00:03e-05" (len=12, dot=NO) parse=NO(Error: '00:00:03e-05' - invalid time string)
FAIL: malformed time string, no '.' fraction field
FAIL: from_time_string rejects the string to_time_string produced
1/20000 s secs=5e-05 -> "00:00:00e-05" (len=12, dot=NO) parse=NO(Error: '00:00:00e-05' - invalid time string)
FAIL: malformed time string, no '.' fraction field
FAIL: from_time_string rejects the string to_time_string produced
=== well-formed but wrong value (exponential, truncated) ===
1/24000 s secs=4.16666666667e-05 -> "00:00:00.166667" (len=15, dot=yes) parse=yes
FAIL: round trip changes the value: got 0.166667 s, want 4.16666666667e-05 s
1/96000 s secs=1.04166666667e-05 -> "00:00:00.041667" (len=15, dot=yes) parse=yes
FAIL: round trip changes the value: got 0.041667 s, want 1.04166666667e-05 s
=== ordinary cases (control) ===
zero secs=0 -> "00:00:00.0" (len=10, dot=yes) parse=yes
1e-04 s secs=0.0001 -> "00:00:00.0001" (len=13, dot=yes) parse=yes
1e-03 s secs=0.001 -> "00:00:00.001" (len=12, dot=yes) parse=yes
Expected: no FAIL line. The first five times are written with a decimal point and microsecond digits (for example "00:00:00.00005" and "00:00:03.00005"), from_time_string() accepts them, and the value read back is within one microsecond of the original time (not 0.166667 s for 1/24000 s).
Optional
Environment
OpenTimelineIO main at bad7ab5a40ac1a95d9d78a87c95a688d8b57cf28, and run again at f6c34bc6c3337cdd27db77c983c6074130c1c91c (20 Nov 2026) with the same result, C++ library opentime.
Operating System: Windows, MSVC (Visual Studio 2022 Build Tools), the project's CMake build in Debug configuration.
Python version if appropriate: n/a (C++ API; the same function is exposed as otio.opentime.to_time_string).
Found by VaultLens, an analysis tool that uses AI to catch bugs. If anything is wrong, please let us know.
- Lenguaje dominante
- C++
- Estrellas
- 2.1k
- Forks
- 367
- Merge medio
- 3 d 22 h
- PR fusionados (30 d)
- 14
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de AcademySoftwareFoundation/OpenTimelineIO
-
RationalTime::from_time_string rejects any time string with a leading '-', including the output of to_time_stringPosiblemente ocupada @kolinabir la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
AcademySoftwareFoundation/OpenTimelineIO#2106 ·
Los mantenedores suelen responder en 1 día
-
otio_imath.cpp fails to compile with the latest Imath/pybind11Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
AcademySoftwareFoundation/OpenTimelineIO#2037 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 64/100
AcademySoftwareFoundation/OpenTimelineIO#2108 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
AcademySoftwareFoundation/OpenTimelineIO#2098 ·
Los mantenedores suelen responder en 1 día
-
Rust bindings?Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
AcademySoftwareFoundation/OpenTimelineIO#2093 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de AcademySoftwareFoundation/OpenTimelineIO
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
godotengine/godot#125913 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
-
期待增加虚线线条样式Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 94/100
vllm-project/vllm#70568 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
mw00/project-maya#1368 ·
Los mantenedores suelen responder en 2 días