Skip to content

feat(validate_config): add warning about timezone#5731

Open
stevenjoezhang wants to merge 1 commit intomasterfrom
tz
Open

feat(validate_config): add warning about timezone#5731
stevenjoezhang wants to merge 1 commit intomasterfrom
tz

Conversation

@stevenjoezhang
Copy link
Member

What does it do?

See #5720

Screenshots

Pull request tasks

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

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

How to test

git clone -b tz https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test

@coveralls
Copy link

Pull Request Test Coverage Report for Build 20736158720

Details

  • 6 of 20 (30.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 99.351%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/hexo/validate_config.ts 6 20 30.0%
Totals Coverage Status
Change from base Build 20673264715: -0.1%
Covered Lines: 9944
Relevant Lines: 10009

💛 - Coveralls

Comment on lines +39 to +40
const machineTimezone = moment.tz.guess();
if (configTimezone.name !== machineTimezone) {
Copy link
Member

@SukkaW SukkaW Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to guess and warn about a mismatch here? E.g., running Hexo on CI may have a different timezone, intentionally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that the warning will always be displayed in CI environments. However, I think it should be displayed.

If the user's permalink setting includes time-based parts, it will also change the URLs of their posts.

As @stevenjoezhang mentioned in the above comment at #5720 (comment), my concern is that URLs may change.

Currently, URLs are always generated using the LocalTimeZone (machine's timezone) for date/time formatting. If we change it to use the Timezone from _config.yml for generating URLs in the next major version, and users are unaware that their machine's timezone and the timezone in _config.yml are inconsistent, the generated URLs could unintentionally change.

However, I do think it might be acceptable to address this by including a migration guide in the release notes instead of showing the warning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about only giving this warning if this is not in CI? (In CI, there is nothing users can do anyway; they need to validate this on his/her local machine).

Also, since this only affects permalink patterns with time, we may emit this warning only when one of the permalink patterns uses time.

cc @stevenjoezhang

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoshinorin @SukkaW I believe that displaying a warning message is necessary both locally and in CI environments, because there is a possibility that links may change. Showing a clear warning is more reasonable than remaining completely silent. For example, if a user does not configure the time zone correctly and this causes the article links generated by CI to change, the issue can still be discovered by checking the CI logs.

I think we still have two tasks to complete:

  1. Check whether the permalink patterns contain time-related parameters, and use that as a condition for displaying the warning message.
  2. Write a migration notice in the release notes to inform users how to properly configure the time zone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SukkaW @stevenjoezhang
I agree with only showing the warning when the permalink is affected.

As for CI environments, I don't think there's a reliable way to detect them. Even if there were, it would add unnecessary implementation complexity, so I think always showing the warning is fine. Instead of suppressing the warning in CI environments, it could help to make the warning message clearer, for example by including a link to the relevant documentation or this discussion.

Copy link
Member

@yoshinorin yoshinorin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, LGTM

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.

4 participants