Time() class seconds math producing incorrect results?
I was doing some extendscript work with dropping in markers and had to do some Time() math. I chose to do this with the .seconds method because tick math is a bit of a pain as it is stored as a string.
So as I was doing the math, I discovered that my results were randomly off by a frame. Dug a little deeper and found the issue was happening with performing float math with seconds.
var demo1 = new Time();
var demo2 = new Time();
// Ticks are a form of time measurement in Adobeland.
demo1.ticks = "13558104000000";
demo2.ticks = "12743136000000";
// Setting two variables to experiment with, as named.
var demo_seconds = new Time();
var demo_ticks = new Time();
// Seconds math is simple and done with float.
demo_seconds.seconds = demo1.seconds + demo2.seconds;
// Ticks, for some reason, are stored as strings and need to be converted to int, then converted back to a string to store.
var demo_ticks_string = parseInt(demo1.ticks) + parseInt(demo2.ticks);
demo_ticks.ticks = demo_ticks_string.toString();
// This is pulling some stuff Premiere to prepare to convert time to timecode HH:MM:SS:FF
var currentSeqSettings = app.project.activeSequence.getSettings();
// Formatting the results of the seconds
var timeAsText_secs = demo_seconds.getFormatted(currentSeqSettings.videoFrameRate, app.project.activeSequence.videoDisplayFormat);
// Formatting the results of the ticks
var timeAsText_ticks = demo_ticks.getFormatted(currentSeqSettings.videoFrameRate, app.project.activeSequence.videoDisplayFormat);
// Display results in seconds
$.writeln(demo1.seconds + " + " + demo2.seconds + " = " + demo_seconds.seconds);
$.writeln(timeAsText_secs);
// Display results in in ticks
$.writeln(demo1.seconds + " + " + demo2.seconds + " = " + demo_ticks.seconds);
$.writeln(timeAsText_ticks);
Seconds Math:
53.375 + 50.1666666666667 = 103.541666666663
00:01:43:12
Ticks Math (when converted to an integer)
53.375 + 50.1666666666667 = 103.541666666667
00:01:43:13
So what's going on here? Am I missing something obvious? Why is the float math seemingly wrong?
