fix: use configurable timezone for daily stats keys#1099
Open
Xio-Shark wants to merge 1 commit intohibiken:masterfrom
Open
fix: use configurable timezone for daily stats keys#1099Xio-Shark wants to merge 1 commit intohibiken:masterfrom
Xio-Shark wants to merge 1 commit intohibiken:masterfrom
Conversation
ProcessedKey() and FailedKey() in base.go previously hardcoded .UTC() conversion, causing tasks processed before 8 AM in UTC+8 to be counted towards the previous day's stats. This change: - Removes .UTC() from ProcessedKey/FailedKey (caller decides timezone) - Adds location field to RDB struct (defaults to time.UTC) - Adds SetLocation() method for timezone configuration - Updates all stats-recording methods to use configured location - Adds timezone-specific test cases for Asia/Shanghai
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1099 +/- ##
==========================================
- Coverage 67.13% 63.29% -3.85%
==========================================
Files 29 29
Lines 4300 4989 +689
==========================================
+ Hits 2887 3158 +271
- Misses 1135 1553 +418
Partials 278 278 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
kamikazechaser
approved these changes
Apr 9, 2026
| // By default, RDB uses time.UTC. Setting this to a different location | ||
| // (e.g., time.Local, or a location loaded via time.LoadLocation("Asia/Shanghai")) | ||
| // will cause daily stats to be aggregated according to that timezone's date boundary. | ||
| func (r *RDB) SetLocation(loc *time.Location) { |
Collaborator
There was a problem hiding this comment.
I'm not sure how someone can use this because it is inside internal.
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.
Fixes #671
Root Cause
ProcessedKey() and FailedKey() in internal/base/base.go called
.UTC()before formatting the date string for Redis keys. For users in UTC+8 (Asia/Shanghai), tasks processed before 08:00 local time would fall on the previous UTC day, causing daily stats mismatch.Changes
.UTC()from ProcessedKey() / FailedKey() — the caller now passes time in the desired timezonelocation *time.Locationfield to RDB struct (defaults totime.UTCfor backward compatibility)Asia/ShanghaiBackward Compatibility
time.UTC— no breaking change for existing users