-
Notifications
You must be signed in to change notification settings - Fork 15
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
ZonedDateTime seconds since midnight #122
Comments
Currently I came up with the following code:
|
There are timezones where "midnight" does not exist on certain days. What is the expected behavior of the code in that case? What are you really trying to calculate? |
Good point. Can I find a list of them somewhere? |
There is no explicit list that I am aware of. The info is theoretically all encoded in the TZDB files, and it is possible write code to generate such a list of timezones and dates where midnight does not exist. Not hard, but not trivial either. The situation happens primarily due to a timezone switching to DST exactly at midnight, i.e. 00:00 goes to 01:00. Although there exists at least one timezone that I am aware of where they skipped an entire day, going from Dec 29 to Dec 31st if I recall. For timestamped filenames, why use the local time? Isn't UTC more appropriate, so that you never have to worry about DST changes? |
UTC is less convenient for visual search in the file list. I mean, the user might want to read a file corresponding to some event which is probably dated in his timezone. I'll think about it, though. |
That's true. But with local time, you will have duplicate timestamps (when DST ends), and non-existing timestamps (when DST starts). That seems far worse. |
That's why I thought about calculating the number of seconds from midnight with DST 🙂 then there would be no duplicates, but it's possible to have 90000 seconds in a day. Non existent timestamps are lesser problem. |
Non-existent timestamps are a problem because "midnight" may not exist. :-) What does your filename pattern look like? |
|
How many of these CSV files will be generated per day? How about using both UTC and local time, like: For example: |
How do I get ZonedDateTime instance seconds since midnight properly?
I currently use
zdt.localDateTime().localTime().toSeconds()
, but I think it will return incorrect result if the time zone daylight saving changes on this day.Consider Europe/London timezone on Sunday, 31 March, 2024, 3:00 AM. The DST kicked in on that day at 1:00 AM, moving the clock 1 hour forward. So, at 3:00 AM the midnight was 2 hours ago.
The text was updated successfully, but these errors were encountered: