-
-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(moment): use timezone from Hexo config instead of maching settings #5720
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
base: master
Are you sure you want to change the base?
Conversation
How to testgit clone -b timezone-dev https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test |
Pull Request Test Coverage Report for Build 20631857379Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates timezone handling to work with the new hexo-front-matter v5.0.0, which now returns dates in UTC format. The changes ensure consistent date handling across the codebase by adjusting for timezone offsets when parsing dates.
Key changes:
- Updated
hexo-front-matterdependency from v4.2.1 to v5.0.0 - Modified
toDate()andadjustDateForTimezone()functions to handle UTC dates correctly - Updated all test fixtures to use
moment.utc()for consistent timezone handling
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Upgraded hexo-front-matter dependency to v5.0.0 |
| lib/plugins/processor/common.ts | Updated toDate() to adjust for timezone offset and simplified adjustDateForTimezone() logic |
| lib/plugins/processor/post.ts | Added defaultTimeZone option to yfm() calls and switched to Date.UTC() for date parsing |
| lib/plugins/processor/asset.ts | Added defaultTimeZone option to yfm() calls |
| lib/models/types/moment.ts | Updated toMoment() to explicitly set timezone to UTC |
| lib/hexo/post.ts | Added defaultTimeZone option to yfmParse() call |
| test/scripts/processors/common.ts | Added DURATION_MINUTE constant and updated test expectations for timezone-adjusted dates |
| test/scripts/models/moment.ts | Updated tests to use moment.utc() for consistent UTC handling |
| test/scripts/filters/post_permalink.ts | Updated test fixtures to use moment.utc() and removed unnecessary date fields |
| test/scripts/console/new.ts | Changed front-matter title format from triple-quoted to double-quoted string |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| data.date = new Date(Date.UTC( | ||
| info.year, | ||
| parseInt(info.month || info.i_month, 10) - 1, | ||
| parseInt(info.day || info.i_day, 10) |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comment on lines 128-130 mentions 'It will be corrected by invoking adjustDateForTimezone later', but this creates a dependency between two separate code blocks (here and line 140). Consider adding a reference to the specific line where the correction happens (e.g., 'It will be corrected on line 140 by invoking adjustDateForTimezone') to make the relationship more explicit.
yoshinorin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this PR is a potentially breaking change, I think it would be better to include it in the 9.x release rather than a minor version. What are your thoughts?
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mimi <stevenjoezhang@gmail.com>
|
If the user hasn't set a timezone in Hexo's I think merging it into 8.x or waiting until 9.0 would both be acceptable approaches. We should remind users to properly configure their default timezone, or, let Hexo write the timezone into the configuration file automatically during the first initialization. |
Most users probably have the same timezone set for both their PC and That said, I don't think typical users would expect this kind of change to be included in a minor version update. The possibility of URLs changing is particularly concerning (I apologize, I overlooked this aspect). Therefore, I personally think it would be preferable to release this in a major version. |
|
I've been thinking about the rollout plan for this feature, and I believe it would be better to ensure backward compatibility and provide advance warnings. Specifically, here's what I suggest: 1. Backward Compatibility ConfigurationIMHO, We should provide a configuration option to maintain backward compatibility. For example, we could allow users to specify _config.yml
// example
timezone: LocalTimeZone# Uses machine's local timezone (legacy behavior)When this value is set, Hexo would continue to use the machine's timezone as it does currently, preserving the existing behavior for users who rely on it. 2. Deprecation Warning in Minor Version (
|
|
@yoshinorin Updated in cad9c2a
|
What does it do?
See hexojs/hexo-front-matter#146
Screenshots
Pull request tasks