Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Timezone offset from UTC is wrong when not in DST #362

Closed
@pquentin

Description

@pquentin

It turns out that theEurope/Paris timezone just gotout of DST and is now in UTC+1 back from UTC+2. It means that dates should currently be recorded with +0100.date does it correctly:

$ TZ='Europe/Paris' date +"%Y-%m-%dT%H:%M:%S%z"2015-11-04T08:45:34+0100

However, GitPython usestime.altzone to guess dates in commits, which yields +0200 instead of +0100:

$ TZ='Europe/Paris' python -c 'import time; print(-time.altzone/3600)'2.0

While the date is still correct, the timezone is now wrong. Indeed, usingtime.altzone is only correct when:

  1. time.daylight is non zero, eg. the current timezone has a DST defined at some point in the year (always true for Europe/Paris, but always false for Indian/Reunion)
  2. and DST is currently active, which you can check withtime.localtime().tm_isdst > 0.

To fix this issue, you shoulduse this code to get the UTC offset in seconds.

is_dst = time.daylight and time.localtime().tm_isdst > 0utc_offset = time.altzone if is_dst else time.timezone

You still need to multiply by -1 and divide by 3600, but you will get the correct offset this way.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp