-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows timestamp in converter panel #114
base: master
Are you sure you want to change the base?
Conversation
Thanks for this contribution! I'm somewhat concerned about the name choice: "Windows timestamp". Windows-related products are known to use several different models of tracking time, and the one that you've provided is the one generally known as FILETIME, i.e. 64-bit integer measuring time since 1601-01-01 in 100ns ticks. Let us use more precise naming to avoid the confusion? |
Is |
I'd rather pick And the two extra characters don't really matter, when we consider that we reduce a lot of confusion in our users. |
var u64le = Converter.numConv(data, 8, false, false); | ||
this.filetime = u64le ? dateFormat(new Date(Converter.fileToUnixTime(parseInt(u64le)) * 1000), "yyyy-mm-dd HH:MM:ss") : ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sealmove Unfonutately, as all numbers in JavaScript are double
s with just 53 bits of mantissa, a 64-bit integer will lose precision during the conversion to it (using the parseInt
method). It means that not all integers larger than 253 - 1 (available in the Number.MAX_SAFE_INTEGER
constant) can't be represented accurately in the native JavaScript number type: e.g. Number.MAX_SAFE_INTEGER + 1 == Number.MAX_SAFE_INTEGER + 2
, see MDN.
But it doesn't have to happen here, because the Converter.numConv
method works internally with a bigInt
, though it returns a string
(don't know why). Anyway, I would suggest to convert the string to the bigInt
type, and do the arithmetics you need to do in the fileToUnixTime
method using its methods instead of the native arithmetic operators.
And I just checked that Date
object has more than sufficient range for not losing precision here, it's even far larger than FILETIME
has (maximum year in FILETIME
is ~30828, maximum year of Date
is 275760), so there shouldn't be a problem, if you choose a safe method of initializing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there shouldn't be a problem, if you choose a safe method of initializing it.
@sealmove Actually, you can safely ignore that "safe method". I've just tested on RunKit the maximum year 30828 of FILETIME
, and the number that represents that Date
(number of milliseconds that have elapsed since midnight on January 1, 1970, UTC) is still ~10 times less than the Number.MAX_SAFE_INTEGER
, so it will be fine to just stuff that Unix timestamp * 1000
number into the new Date()
constructor, after you do the arithmetic with bigInt
.
No description provided.