Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Fix timezone issue #146

wants to merge 4 commits into from

Conversation

stevenjoezhang
Copy link
Member

check list

  • Add test cases for the changes.
  • Passed the CI test.

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 yaml and luxon libraries, which are different from Hexo’s current dependencies (js-yaml and moment-timezone). However, all unit tests have passed, so I believe this should not cause any issues.

Additional information

@stevenjoezhang stevenjoezhang changed the title Yaml Fix timezone issue Apr 20, 2025
@coveralls
Copy link

coveralls commented Apr 20, 2025

Coverage Status

coverage: 98.917% (-1.1%) from 100.0%
when pulling 987e15b on yaml
into d72860c on master.

@stevenjoezhang stevenjoezhang marked this pull request as draft April 20, 2025 17:07
@stevenjoezhang stevenjoezhang marked this pull request as ready for review April 21, 2025 06:21
@stevenjoezhang
Copy link
Member Author

To test it with Hexo, checkout this branch: https://github.com/hexojs/hexo/tree/timezone-dev (I'm open a Pull Request once this merged)

@stevenjoezhang stevenjoezhang requested a review from a team April 23, 2025 06:02
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.

Date parse issue
2 participants