Repository navigation
fix(package): [datetime] use local zone for zero hour timestamps - #415
Merged
Merged
Conversation
duke-git
approved these changes
Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GetZeroHourTimestampformats today's local date, parses it as UTC and subtracts 8 hours, so it is only the local midnight when the process runs in a UTC+8 zone.GetNightTimestampadds 86399 seconds to that value. Their docs say "timestamp of zero hour (00:00)" and "23:59", andGetTodayStartTime/GetTodayEndTimeuse the local date.On the base commit, with
time.Localset to UTC-5,GetZeroHourTimestamp()returned 1793682000 while the local midnight is 1793635200.GetZeroHourTimestampnow returnsBeginOfDay(time.Now()).Unix()andGetNightTimestampreturnsEndOfDay(time.Now()).Unix().Compatibility: the values change when the local zone is not UTC+8. Before, they were the Beijing-time midnight of the local date, now they are the local day's start and 23:59:59. In a UTC+8 zone on a normal day the results are the same. A DST-change day is not always 86400 seconds long, so the night value is no longer always the zero-hour value plus 86399.
Test:
TestGetZeroHourAndNightTimestampLocalZonesetstime.Localto fixed zones (UTC-5, UTC, UTC+8, UTC+9) and compares withBeginOfDay/EndOfDay. It is not parallel because it replacestime.Local, and it restores it afterwards. It is not a DST test, since fixed zones have no transitions. On go1.26.6 Linux,go vetandgo test ./datetimepass on amd64, onGOARCH=386and withTZset to Asia/Seoul and America/New_York, and the new test fails on the base commit. The fullgo test ./...still fails innetutil(TestTelnetConnected,ExampleIsTelnetConnected) the same way on the base commit in my environment, which has no external network access. I did not investigate the cause.