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

Comparisons between different timezones #26

Open
ghivert opened this issue May 17, 2024 · 3 comments
Open

Comparisons between different timezones #26

ghivert opened this issue May 17, 2024 · 3 comments

Comments

@ghivert
Copy link

ghivert commented May 17, 2024

Hi !

Following a discussion we had on gleam-lang/hexpm on timestamps, it appears that when comparing two datetime on different timezones, the behaviour is to just compare the millis. But even if on the same timestamp, they don't have the same time because there's an offset.

Is it the desired behaviour?

@massivefermion
Copy link
Owner

massivefermion commented May 17, 2024

Hi
Yes, this is what I had in mind because this way of comparison is what actually means for a time value to be before or after another. Because the same time in two different timezones, is still the same time just represented in two different social contexts.
But of course I can see the utility of the kind of comparison you have in mind. I'll try to add it when I can. I'm just not sure what to call it!
For now, you can get what you want by using the get_time_of_day function on time values with different offsets and comparing the fields. In cases where the difference in offsets may be large enough where the two time values represent different days, you'd want to also use the get_day function and compare the month and date fields on those too.

@ghivert
Copy link
Author

ghivert commented May 17, 2024

Thanks for your answer. 🙂
Isn't there a way to just compare the unix timestamp?
Birl could have something like elm Posix, that could be only the Posix timestamp, and it would solve everything? It could be the boxed timestamp, provide simple functions, and some convert functions from/to Posix to DateTime?

@massivefermion
Copy link
Owner

The compare function does that. The only difference is, the timestamp in a Time value is in microseconds instead of seconds! But that wouldn't be the comparison you described!
There is just the caveat that if both time values have monotonic time, that would be the one used in the comparison. The monotonic time, though, only exists when the Time value is created using one of the now functions.

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

No branches or pull requests

2 participants