-
Notifications
You must be signed in to change notification settings - Fork 30k
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
fs: consider NaN/Infinity in toUnixTimestamp #2387
Conversation
Why not replace both checks with |
Oh, I absolutely this function, let me use and test it, thanks for the tip |
Fixed, thank you Brian |
I meant replace both conditions, like simply: if (!isFinite(time)) { since |
Fixed, thank you |
@@ -126,7 +126,9 @@ runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() { | |||
runTest(new Date(), new Date(), function() { | |||
runTest(123456.789, 123456.789, function() { | |||
runTest(stats.mtime, stats.mtime, function() { | |||
// done | |||
runTest(NaN, Infinity, function() { | |||
// TODO |
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.
What exactly to do here?
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.
Sorry, it should be "done"
Corrected, thanks @thefourtheye |
@@ -1046,6 +1046,9 @@ fs.chownSync = function(path, uid, gid) { | |||
// converts Date or number to a fractional UNIX timestamp | |||
function toUnixTimestamp(time) { | |||
if (typeof time === 'number') { | |||
if (!isFinite(time)) { |
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.
Should use Number.isFinite()
instead of isFinite()
:
In comparison to the global isFinite() function, this method doesn't forcibly convert the parameter to a number. This means only values of the type number, that are also finite, return true.
Doesn't matter here, but good for consistency.
After reading some docs about the difference at MDN and ECMA spec, I changed it to use the |
Any feedback from core team? |
LGTM |
Hmmm.
|
I have no idea about the negative, because the linux manual didn't mention this, so I have the following proposals:
I will document this either after getting the answer of the above from @thefourtheye or other Node.js team member. Thank you :) |
any words? @thefourtheye |
How is this pr going? @thefourtheye did ignore my questions and proposals again, I don't know what happened :( |
@yorkie Might be outside the scope of this PR, but is there utility in accepting strings? The check would basically be: if (typeof time === 'string' && +time == time) {
return +time;
} I'm cool w/ the change if CI is happy. |
Hey @trevnorris I Added your suggestion at this PR, but I still care about strict mode and source code confusion in using the operator Mainly, the unit test is pass on my side :) |
Added few document as well, but I have not yet got any response about minus value, so I will just keep the current logic. |
@yorkie I am really sorry about the delay. I finally got some time to test this. The value of |
|
||
- if the value is a numberable string like "123456789", the value would get converted to | ||
corresponding number. | ||
- if the value is `NaN` or `Infinity`, the value would get converted to `Date.now()`. |
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.
If
It's fine @thefourtheye
Do you have some document about this or someone from nodejs team tell me what should I do, or I think set to Unix Epoch is not still the best solution. |
@yorkie Thanks. Only reason I suggest using |
@yorkie I searched for documentations but I couldn't find any. I found that by running const fs = require('fs');
console.error(fs.statSync('Test.py'));
fs.utimesSync('Test.py', -1, -1);
console.error(fs.statSync('Test.py')); |
Thanks for your work @thefourtheye, I will follow your running result at first :) |
Updated, now the minus number and other |
@yorkie Ah, lets get some confirmation about the negative values. @bnoordhuis any idea? |
Of course, and I will document something after that :) |
Ping @bnoordhuis |
@orangemocha so the thing that I should or can do is reword the title and push again? |
runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() { | ||
runTest(new Date(), new Date(), function() { | ||
runTest(123456.789, 123456.789, function() { | ||
runTest(stats.mtime, stats.mtime, function() { | ||
// done | ||
runTest(NaN, Infinity, function() { | ||
runTest('123456', -1, function () { |
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.
Linter would break at this line? @Fishrock123
@yorke : yes! |
Yes, sir. I will fix the line 131 as well :) |
@yorkie : or, if you added those tests in the first place, you could also do an interactive rebase and change your commits to simply not add them. |
Ok, I did squash all commits then could someone run the CI again, thanks for your helps :) |
The test seems to be suspended by ARM at https://ci.nodejs.org/job/node-test-commit-arm/634/console, anything that I can help to fix? |
@yorkie Just took a really long time to finish. Everything looks green now. |
PR-URL: #2387 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Landed on 1f842c2 with column change in doc. |
To clarify, this is indeed a breaking change? |
Thanks @trevnorris
Shouldn't, I guess few modules use |
@Fishrock123 I'd say this is a bug-fix. This simply makes previously undefined behavior defined. |
PR-URL: #2387 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Notable changes: * buffer: - Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) nodejs#2866. - `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) nodejs#2777. * fs: - `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) nodejs#2387. - `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) nodejs#2167. * http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) nodejs#2824. * npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) nodejs#2822. * src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) nodejs#2324. * v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) nodejs#2870. - This fixes a previously known bug where some computed object shorthand properties did not work correctly (nodejs#2507). Refs: nodejs#2844 PR-URL: nodejs#2889
Notable changes: * buffer: - Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) #2866. - `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) #2777. * fs: - `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) #2387. - `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) #2167. * http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) #2824. * npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) #2822. * src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) #2324. * v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) #2870. - This fixes a previously known bug where some computed object shorthand properties did not work correctly (#2507). Refs: #2844 PR-URL: #2889
We might should follow the rule of linux:
ref: http://linux.die.net/man/2/utime