MongoLink icon indicating copy to clipboard operation
MongoLink copied to clipboard

ToMillisecondUnixTime truncates milliseconds of DateObject[]'s

Open christophergeyer opened this issue 3 years ago • 0 comments

ToMillisecondUnixTime[] truncates milliseconds when it converts DateObject[]'s to milliseconds from epoch. As a result, you can't perform sub-second date/time queries. That prevents efficiently finding records in the case where you might be looking for records in a 20ms window where you have records stored at 100 Hz. As a result of the truncation, you'd have to retrieve all ~100 records and find the subset within the window.

Need a fix along the lines in ACommon.m:

ToMillisecondUnixTime[date_DateObject] := Module[
	{sec,msec},
	msec = date["Millisecond"];
	If[MissingQ[msec], msec = 0, msec *= 10];
	sec = date["Second"];
	If[MissingQ[sec], sec = 0];
	1000 * UnixTime[date] + msec
]

Additionally, it appears that on my Mac OS system, that DateObject[...]["Millisecond"] reports hundredths of seconds instead of milliseconds. I do not know how widespread that is and how one would detect it (maybe that's why this it's truncated?).

christophergeyer avatar Dec 13 '21 22:12 christophergeyer