Skip to content
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

Unexpected behaviour from at least isEqual() when using UNIX epoch date (1970-01-01) #417

Closed
wodow opened this issue Oct 9, 2024 · 8 comments
Labels

Comments

@wodow
Copy link

wodow commented Oct 9, 2024

> spacetime('1970-01-01').isEqual('1970-01-01')
null
> spacetime('1970-01-02').isEqual('1970-01-02')
true
> spacetime('1970-01-02').isEqual('1970-01-01')
null
> spacetime('1970-01-01').isEqual('1970-01-02')
false

Should only return null when passed an invalid date?

@wodow
Copy link
Author

wodow commented Oct 9, 2024

Possible this affects other functions too, but have not yet checked.

@spencermountain
Copy link
Owner

spencermountain commented Oct 9, 2024

hey Chris, thanks for the issue. I don't see any nulls, when I do this:

console.log(spacetime('1970-01-01').isEqual('1970-01-01'))
console.log(spacetime('1970-01-02').isEqual('1970-01-02'))
console.log(spacetime('1970-01-02').isEqual('1970-01-01'))
console.log(spacetime('1970-01-01').isEqual('1970-01-02'))

same thing in the repl - how did you produce this null response? You're right, that it should be a boolean always.
cheers

@wodow
Copy link
Author

wodow commented Oct 9, 2024

Are you testing on a more recent (dev?) version?

Here's a copy of Firefox's console output for your examples run on https://spacetime.how/

console.log(spacetime('1970-01-01').isEqual('1970-01-01'))
console.log(spacetime('1970-01-02').isEqual('1970-01-02'))
console.log(spacetime('1970-01-02').isEqual('1970-01-01'))
console.log(spacetime('1970-01-01').isEqual('1970-01-02'))
null debugger eval code:1:9
true debugger eval code:2:9
null debugger eval code:3:9
false debugger eval code:4:9
undefined
spacetime.version
"7.6.1"

@spencermountain
Copy link
Owner

weird - i'm seeing true/false in chrome/node/firefox
2024-10-09 T 13 35 02@2x

@wodow
Copy link
Author

wodow commented Oct 10, 2024

I get the nulls in Chrome/Chromium for me:

Screenshot 2024-10-10 at 10 51 42

@wodow
Copy link
Author

wodow commented Oct 10, 2024

I've worked out why: we are both avoiding the obvious and also super pertinent elephant in the room, the timezone!

It only behaves this way with a GMT/UTC/London timezone, where the epoch is equal to zero.

getEpoch should allow for tmp.epoch being zero, but it only checks for truthiness:

spacetime/src/fns.js

Lines 59 to 71 in 0464eca

export function getEpoch(tmp) {
//support epoch
if (typeof tmp === 'number') {
return tmp
}
//suport date objects
if (isDate(tmp)) {
return tmp.getTime()
}
if (tmp.epoch) {
return tmp.epoch
}
return null

@spencermountain
Copy link
Owner

haha, thank you. busted by pertinent elephant again.
Good catch. Happy to do a hotfix today, if I can.
cheers

spencermountain added a commit that referenced this issue Oct 10, 2024
@spencermountain spencermountain mentioned this issue Oct 10, 2024
Merged
@spencermountain
Copy link
Owner

released as 7.6.2
thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants