Date / time manipulation

Hello,
I'm trying to calculate an ETA from a laps of time, exemple :
duree = (duree / 1000).toLong(); // en secondes
ETA = Time.now().value()+duree ;
_ETA = Lang.format("$1$:$2$", [(ETA /3600 % 24).format("%02d"), (ETA / 60 % 60).format("%02d")]); // ETA en texte

But the ETA seem to be wrong, alway one hour too early
I think I'me wrong with the UTC or Something else

You help is welcome, please

Thanks
  • The value stored by a Time.Moment represents the number of seconds past the epoch in UTC time. If you are going to do calculations directly on this number, you need to remove your time zone offset (Sys.getClockTime().timeZoneOffset) from this. The simpler way would be to let the platform functions do it for you.

    function format_as_time_of_day(moment)
    {
    var info = Gregorian.info(moment, Time.FORMAT_SHORT);
    return Lang.format("$1$:$2$:$3$", [
    info.hour,
    info.min.format("%02u"),
    info.sec.format("%02u")
    ]);
    }


    // snipped

    var eta = Time.now();
    dc.drawText(cx, cy - fy, Gfx.FONT_LARGE, format_as_time_of_day(eta), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);

    eta = eta.add(new Time.Duration(duree));
    dc.drawText(cx, cy + fy, Gfx.FONT_LARGE, format_as_time_of_day(eta), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);