Giter Site home page Giter Site logo

Comments (3)

timvink avatar timvink commented on May 20, 2024 1

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?

from mkdocs-git-revision-date-localized-plugin.

timvink avatar timvink commented on May 20, 2024

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!

from mkdocs-git-revision-date-localized-plugin.

flc1125 avatar flc1125 commented on May 20, 2024

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

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

from mkdocs-git-revision-date-localized-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.