RationalTime::from_time_string rejects any time string with a leading '-', including the output of to_time_string

Abierto Apto para principiantes
#2,106 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@kolinabir ya está trabajando en esto.

Desde el 27/11/2026.

  • #2113 de @kolinabir — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp, python
Área
backend

Línea de trabajo

El bucle de análisis es from_time_string en src/opentime/rationalTime.cpp (alrededor de las líneas 395-410). Léelo contra el contrato documentado en rationalTime.h, líneas 214-218, y revisa to_time_string para ver las cadenas negativas exactas que emite. Compila el target opentime con CMake y ejecuta el programa de reproducción del issue. Después, añade casos a tests/test_opentime.py (test_time_time_string_negative_rational_time) y a las pruebas C++ de opentime. Está terminado cuando -01:00:00, -10 y -00:00:01.0 se analizan como los segundos negativos esperados y hacen el round trip.

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

RationalTime::from_time_string() returns INVALID_TIME_STRING for every string that starts with a minus sign, for example "-01:00:00", "-10" or "-00:00:01.0".

The header says a leading minus is allowed (rationalTime.h, lines 214-218):

/// @brief Parse a string in the form "hours:minutes:seconds".
///
/// The string may have a leading negative sign.

to_time_string() produces such strings for negative times (since #605), and the Python test test_time_time_string_negative_rational_time checks that RationalTime(-24, 24) gives "-00:00:01.0". Passing that exact string back to from_time_string() fails, so a negative time cannot make a round trip through a time string.

Expected: from_time_string("-01:00:00", 24) returns -3600 seconds (value -86400 at rate 24) with no error, and from_time_string("-00:00:01.0", 24) returns -1 second, like RationalTime(-24, 24).

Suggestion for the cause: in the backward scan of from_time_string (rationalTime.cpp, lines 395-404), the branch that rejects non-digit characters also runs when current reaches the leading '-', before the start == current branch (line 406) can call parseFloat(..., true, ...) with negatives allowed. Even past that point, the sign would only apply to the hours field ("-00:00:01.0" would give +1 s), so it may be simpler to strip a leading '-' first and negate the total at the end.

Reproduction Steps

Build against the C++ library (opentime) and run:

#include <opentime/errorStatus.h>
#include <opentime/rationalTime.h>

#include <cstdio>
#include <string>

using namespace opentime::OPENTIME_VERSION_NS;

static int failures = 0;

static void check(
    const char*        label,
    const std::string& input,
    double             rate,
    double             expected_seconds)
{
    ErrorStatus  es;
    RationalTime rt = RationalTime::from_time_string(input, rate, &es);

    const bool err = is_error(es);
    printf(
        "%s: input=\"%s\" rate=%g -> error=%s code=%d valid=%d value=%g "
        "rate=%g to_seconds=%.6f\n",
        label,
        input.c_str(),
        rate,
        err ? "yes" : "no",
        (int) es.outcome,
        (int) rt.is_valid_time(),
        rt.value(),
        rt.rate(),
        rt.to_seconds());

    if (err)
    {
        printf(
            "FAIL %s: \"%s\" rejected (outcome=%d details=\"%s\"); header "
            "says \"The string may have a leading negative sign\", expected "
            "to_seconds=%.6f\n",
            label,
            input.c_str(),
            (int) es.outcome,
            es.details.c_str(),
            expected_seconds);
        ++failures;
        return;
    }
    if (rt.to_seconds() != expected_seconds)
    {
        printf(
            "FAIL %s: parsed to_seconds=%.6f, expected %.6f\n",
            label,
            rt.to_seconds(),
            expected_seconds);
        ++failures;
    }
}

int main()
{
    // positive control
    {
        ErrorStatus  es;
        RationalTime rt = RationalTime::from_time_string("01:00:00", 24, &es);
        printf(
            "control positive: error=%s to_seconds=%.6f\n",
            is_error(es) ? "yes" : "no",
            rt.to_seconds());
        if (is_error(es) || rt.to_seconds() != 3600.0)
        {
            printf("FAIL control: positive string did not parse\n");
            ++failures;
        }
    }

    // leading negative sign
    check("minus-hhmmss", "-01:00:00", 24, -3600.0);
    check("minus-hhmmss-frac", "-01:00:00.0", 24, -3600.0);
    check("minus-min", "-1:00:00", 24, -3600.0);
    check("minus-seconds-only", "-10", 24, -10.0);

    // round trip through to_time_string() / from_time_string()
    {
        RationalTime rt(-24, 24);
        std::string  ts = rt.to_time_string();
        printf("to_time_string(RationalTime(-24,24)) = \"%s\"\n", ts.c_str());
        check("roundtrip-neg-1s", ts, 24, -1.0);
    }
    {
        RationalTime rt(-3600, 1);
        std::string  ts = rt.to_time_string();
        printf("to_time_string(RationalTime(-3600,1)) = \"%s\"\n", ts.c_str());
        check("roundtrip-neg-1h", ts, 24, -3600.0);
    }

    if (failures)
    {
        return 1;
    }
    printf("all negative time strings parsed as documented\n");
    return 0;
}

Log output if appropriate

Observed:

control positive: error=no to_seconds=3600.000000
minus-hhmmss: input="-01:00:00" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL minus-hhmmss: "-01:00:00" rejected (outcome=3 details="Error: '-01:00:00' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-3600.000000
minus-hhmmss-frac: input="-01:00:00.0" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL minus-hhmmss-frac: "-01:00:00.0" rejected (outcome=3 details="Error: '-01:00:00.0' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-3600.000000
minus-min: input="-1:00:00" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL minus-min: "-1:00:00" rejected (outcome=3 details="Error: '-1:00:00' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-3600.000000
minus-seconds-only: input="-10" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL minus-seconds-only: "-10" rejected (outcome=3 details="Error: '-10' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-10.000000
to_time_string(RationalTime(-24,24)) = "-00:00:01.0"
roundtrip-neg-1s: input="-00:00:01.0" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL roundtrip-neg-1s: "-00:00:01.0" rejected (outcome=3 details="Error: '-00:00:01.0' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-1.000000
to_time_string(RationalTime(-3600,1)) = "-01:00:00.0"
roundtrip-neg-1h: input="-01:00:00.0" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL roundtrip-neg-1h: "-01:00:00.0" rejected (outcome=3 details="Error: '-01:00:00.0' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-3600.000000

Expected: no FAIL line. Every negative string is accepted with no error and gives -3600 s, -3600 s, -3600 s, -10 s, -1 s and -3600 s respectively, and the program prints all negative time strings parsed as documented.

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 with AddressSanitizer (/fsanitize=address).
Python version if appropriate: n/a (C++ API; the same function is exposed as otio.opentime.from_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

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de AcademySoftwareFoundation/OpenTimelineIO

Todos los issues de AcademySoftwareFoundation/OpenTimelineIO

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.