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
converting -0 to 0 when it appears #2571
converting -0 to 0 when it appears #2571
Conversation
src/differenceInSeconds/index.ts
Outdated
return diff > 0 ? Math.floor(diff) : Math.ceil(diff) | ||
} | ||
return removesNegativeZeroIfPresent(diff > 0 ? Math.floor(diff) : Math.ceil(diff)) | ||
} |
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.
You a new-line problem 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.
solved!
@@ -0,0 +1,3 @@ | |||
export default function removesNegativeZeroIfPnumberent(number:number) : number { | |||
return Object.is(number, -0) ? 0 : number |
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.
The indentation does not follow the project pattern for those files you created.
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.
fixed
src/differenceInHours/index.ts
Outdated
@@ -34,5 +35,5 @@ export default function differenceInHours(dirtyDateLeft: Date | number, dirtyDat | |||
const diff = | |||
differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / | |||
MILLISECONDS_IN_HOUR | |||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff) | |||
return removesNegativeZeroIfPresent(diff > 0 ? Math.floor(diff) : Math.ceil(diff)) |
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.
The same pattern repeats for all those pieces of code using removesNegativeZeroIfPresent
, I mean, diff > 0 ? Math.floor(diff) : Math.ceil(diff)
. What do u think about moving it to the utility function itself?
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.
I agree that's a better way to approach it. I did it in the last commit.
ee202e1
to
26c31b7
Compare
After this PR, should date-fns still give the choice of how to round a value? #2511 |
Good point! |
@LucasHFS @pabrodez @wenderjean
|
src/differenceInHours/index.ts
Outdated
@@ -1,7 +1,7 @@ | |||
import differenceInMilliseconds from '../differenceInMilliseconds/index' | |||
import requiredArgs from '../_lib/requiredArgs/index' | |||
|
|||
const MILLISECONDS_IN_HOUR = 3600000 | |||
import getRoundedValue from '../utils/getRoundedValue' |
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.
import getRoundedValue from '../utils/getRoundedValue' | |
import getRoundedValue from '../utils/getRoundedValue/index' |
src/differenceInWeeks/test.ts
Outdated
const result = differenceInWeeks( | ||
new Date(2014, 6 /* Jul */, 8, 18, 0), | ||
new Date(2014, 5 /* Jun */, 29, 6, 0), | ||
'ceil' |
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.
Shouldn't this argument be either 'trunc' or removed, and the assertion === 1?
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.
@fturmel
yes, you are right! my bad!
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.
✅ fixed
Co-authored-by: Sasha Koss <koss@nocorp.me>
Co-authored-by: Sasha Koss <koss@nocorp.me>
f4fbd2d
to
88bc1e4
Compare
closes date-fns#2555) Added `roundingMethod` option to `differenceInHours`, `differenceInMinutes`, `differenceInQuarters`, `differenceInSeconds` and `differenceInWeeks` with `trunc` as the default method. Co-authored-by: Lucas Silva <lucas.silva@codeminer42.com> Co-authored-by: Tetiana <ttobin@protonmail.ch> Co-authored-by: Sasha Koss <koss@nocorp.me>
Attempt to solve #2555 .
handled the possibility of getting result -0 in all uses of Math.ceil and converted it in 0