Skip to content

fix(package): [datetime] use local zone for zero hour timestamps - #415

Merged
duke-git merged 2 commits into
duke-git:rcfrom
lee3Q:fix/datetime-local-zero-hour
Nov 9, 2026
Merged

duke-git merged 2 commits into
duke-git:rcfrom
lee3Q:fix/datetime-local-zero-hour

Conversation

@lee3Q

@lee3Q lee3Q commented Nov 3, 2026

Copy link
Copy Markdown

GetZeroHourTimestamp formats 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. GetNightTimestamp adds 86399 seconds to that value. Their docs say "timestamp of zero hour (00:00)" and "23:59", and GetTodayStartTime / GetTodayEndTime use the local date.

On the base commit, with time.Local set to UTC-5, GetZeroHourTimestamp() returned 1793682000 while the local midnight is 1793635200.

GetZeroHourTimestamp now returns BeginOfDay(time.Now()).Unix() and GetNightTimestamp returns EndOfDay(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: TestGetZeroHourAndNightTimestampLocalZone sets time.Local to fixed zones (UTC-5, UTC, UTC+8, UTC+9) and compares with BeginOfDay / EndOfDay. It is not parallel because it replaces time.Local, and it restores it afterwards. It is not a DST test, since fixed zones have no transitions. On go1.26.6 Linux, go vet and go test ./datetime pass on amd64, on GOARCH=386 and with TZ set to Asia/Seoul and America/New_York, and the new test fails on the base commit. The full go test ./... still fails in netutil (TestTelnetConnected, ExampleIsTelnetConnected) the same way on the base commit in my environment, which has no external network access. I did not investigate the cause.

@duke-git
duke-git merged commit 5839ab3 into duke-git:rc Nov 9, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants