-
-
Notifications
You must be signed in to change notification settings - Fork 9
Fix timezone issue #146
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?
Fix timezone issue #146
Conversation
|
To test it with Hexo, checkout this branch: https://github.com/hexojs/hexo/tree/timezone-dev (I'll open a Pull Request once this merged) |
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 pull request addresses timezone handling issues in hexo-front-matter by implementing a comprehensive timezone solution. The changes replace the existing date parsing logic with a more robust system that respects explicit timezone information and provides fallback mechanisms.
- Replaces js-yaml with the yaml library and adds luxon for better timezone handling
- Implements custom timestamp parsing that respects timezone information from multiple sources
- Updates test cases to validate timezone behavior across different scenarios
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| package.json | Updates dependencies from js-yaml to yaml and adds luxon for timezone handling |
| lib/timestamp.ts | Implements custom timestamp factory with timezone-aware parsing logic |
| lib/front_matter.ts | Integrates custom timestamp parsing and updates YAML processing |
| test/index.ts | Replaces old date test with comprehensive timezone test cases |
Comments suppressed due to low confidence (1)
lib/front_matter.ts:144
- Add TypeScript type annotations for the parameters. The
optionsparameter should be typed consistently with theStringifyOptionsinterface or a subset of yaml library options.
}
|
|
||
| stringify: ({ value }) => { | ||
| // eslint-disable-next-line no-extra-parens | ||
| return (value as Date)?.toISOString().replace(/(T00:00:00)?\.000Z$/, '') ?? ''; |
Copilot
AI
Jul 25, 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.
The regex pattern escapes the dot unnecessarily. Use \. instead of \\. for better readability: /(T00:00:00)?\.000Z$/
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mimi <stevenjoezhang@gmail.com>
check list
Description
Issue resolved: #28
See also hexojs/hexo#4548
This pull request introduces significant changes to timezone handling, aiming to address long-standing timezone issues in Hexo. (Of course, after hexo-front-matter is updated, Hexo’s code will also need corresponding adjustments — for example, passing the timezone parameter when calling hexo-front-matter, and prompting users to properly configure the timezone in
_config.yml)The core logic can be found in the comments of
lib/timestamp.ts. Specifically:1. If a timezone is set in the timestamp, use that timezone.
2. Otherwise, use the timezone defined in the Hexo configuration. hexo-front-matter no longer read the timezone from the machine, as this can cause issues in CI environments or when collaborators are in different timezones.
3. If no timezone is provided, treat the timestamp as UTC by default and take no further action.
Note that this behavior differs from the YAML specification — YAML treats unspecified timestamps as UTC, whereas we apply Hexo’s configured timezone.
To support the new functionality, I used the
yamlandluxonlibraries, which are different from Hexo’s current dependencies (js-yamlandmoment-timezone). However, all unit tests have passed, so I believe this should not cause any issues.Additional information