Skip to content
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

我在使用过程中,有时区问题 #35

Closed
flc1125 opened this issue Jun 27, 2020 · 3 comments
Closed

我在使用过程中,有时区问题 #35

flc1125 opened this issue Jun 27, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@flc1125
Copy link

flc1125 commented Jun 27, 2020

Question

我在使用过程中,有时区问题
I have time zone problems during use(from Google Translate)


我来自中国,Github 的时区是 +0 时区,但是中国应该是 +8。
I’m from China. Github’s time zone is +0, but China should be +8.(from Google Translate)


示例:

@timvink
Copy link
Owner

timvink commented Jun 29, 2020

Hi @flc1125,

Thanks for taking the time to investigate and report. Much appreciated!

All timestamps are currently being reported in UTC (+0) format. That's not sufficiently clear from the documentation (yet). Timezones should be supported by the plugin.

Technical background

We're retrieving the unix timestamp from GIT:

unix_timestamp = self.repo.log(path, n=1, date="short", format="%at")

(Note that %at retrieves the "author date, UNIX timestamp" reference

The UNIX timestamp is timezone independant as it's "the number of seconds (or milliseconds) elapsed since an absolute point in time, midnight of Jan 1 1970 in UTC time".

When formatting time (for type="datetime"), there's no timezone conversion:

revision_date = datetime.utcfromtimestamp(unix_timestamp)

Solution

The solution would be to add timezone support for displaying time. The locale and timezone are only very loosely coupled: you might have English sites in China en vice versa. So this would have to be a separate, additional option of the plugin.

This package usesbabel for localization, which already supports timezones, so an implementation would be fairly straightforward and alone the lines of:

from babel.dates import format_date, format_time, get_timezone
tzinfo = get_timezone("Asia/Shanghai")
format_time(revision_date, format="medium", locale = "zh", tzinfo=tzinfo)

The timeago plugin also accepts an ISO 8601 string where you specify the timezone as well.

I'll spend some time on this somewhere this week and release a new version with timezone support!

@timvink timvink added the enhancement New feature or request label Jun 30, 2020
@timvink
Copy link
Owner

timvink commented Jun 30, 2020

I just released v0.6 adding support for timezones, which should address this issue.

pip install --upgrade mkdocs-git-revision-date-localized-plugin

# mkdocs.yml
plugins:
  - git-revision-date-localized:
      type: datetime
      locale: zh
      time_zone: Asia/Shanghai

Let me know what you think?

@flc1125
Copy link
Author

flc1125 commented Jun 30, 2020

你好,我已经升级成功,已经正常。

非常棒,太高效了,非常非常感谢你。:+1::+1:

@flc1125 flc1125 closed this as completed Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants