Uh oh!
There was an error while loading. Please reload this page.
fs: (+/-)Infinity and NaN invalid unixtimestamp - #11919
Conversation
There was a problem hiding this comment.
Minor nit: I think 'an Error will be thrown' sounds better
There was a problem hiding this comment.
Agreed. Might be better to list NaN, Infinity, or -Infinity too.
There was a problem hiding this comment.
Thanks, gonna change it
Not sure about this. /cc @jasnell, do we want to put this through a deprecation cycle? @lucamaraschi to me it is not clear why this change should be done — that's not mentioned in this PR. |
There was a problem hiding this comment.
isFinite() covers NaN, so I think the !isNaN(time) can be dropped.
There was a problem hiding this comment.
Can you move this up before the other require()s.
There was a problem hiding this comment.
Agreed. Might be better to list NaN, Infinity, or -Infinity too.
There was a problem hiding this comment.
I think this can be simplified to just typeof time === 'number' && Number.isFinite(time)
There was a problem hiding this comment.
I think Number.isFinite(time) would cover typeof time === 'number' anyway, so this is equivalent to just Number.isFinite(time).
There was a problem hiding this comment.
I think using braces and better indentation for the forEach() callback will make this look better (especially since assert methods do not return meaningful values). Example:
okInputs.forEach((input)=>{assert.doesNotThrow(()=>fs._toUnixTimestamp(input));});There was a problem hiding this comment.
Agreed @mscdex, I was trying to keep it as compact as possible tho.
There was a problem hiding this comment.
IMHO compactness isn't as important in tests.
addaleax
commented
Mar 19, 2017
I think this makes sense, silently converting these values to the current time is not something I’d expect as a user (at least not for ±∞).
Hm, is there any reason not to? |
jasnell
commented
Mar 19, 2017
I'm not convinced this behavior was intentional. It could be viewed as a bug fix and it is in a |
There was a problem hiding this comment.
nit: any reasons the shorter form -Infinity and Infinity are not used?
cjihrig
left a comment
There was a problem hiding this comment.
LGTM once @not-an-aardvark's nit is addressed.
mcollina
left a comment
There was a problem hiding this comment.
LGTM. I don't think it was intentional in the first place.
cjihrig
commented
Mar 20, 2017
@lucamaraschi this needs a rebase. Could you squash the commits while you're at it. |
e5718ba to
3588f6aCompareInfinity and NaN are currently considered valid input when generating a unix time stamp but are defaulted arbitrarly to Date.now()/1000. This PR removes this behaviour and throw an exception like all the other invalid input types.
3588f6a to
1716ef5Comparecjihrig
commented
Mar 21, 2017
Infinity and NaN are currently considered valid input when generating a unix time stamp but are defaulted arbitrarly to Date.now()/1000. This PR removes this behaviour and throw an exception like all the other invalid input types. PR-URL: #11919 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell
commented
Mar 22, 2017
Landed in eed87b1 |
Infinity and NaN are currently considered valid input when generating a
unix time stamp but are defaulted arbitrarly to Date.now()/1000. This
PR removes this behaviour and throw an exception like all the other
invalid input types.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
fs