mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[fix] Better way to calculate locale timezone
This commit is contained in:
parent
57602c5a1c
commit
8b8296e87b
1 changed files with 11 additions and 5 deletions
|
@ -103,13 +103,19 @@ def pretty_date(_date):
|
|||
Argument:
|
||||
- date -- The date or datetime to display
|
||||
"""
|
||||
# Deduce system timezone
|
||||
nowutc = datetime.now(tz=pytz.utc)
|
||||
nowtz = datetime.now()
|
||||
nowtz = nowtz.replace(tzinfo=pytz.utc)
|
||||
offsetHour = nowutc - nowtz
|
||||
offsetHour = int(round(offsetHour.total_seconds() / 3600))
|
||||
localtz = 'Etc/GMT%+d' % offsetHour
|
||||
|
||||
# Transform naive date into UTC date
|
||||
if _date.tzinfo is None:
|
||||
_date = _date.replace(tzinfo=pytz.utc)
|
||||
if time.daylight:
|
||||
offsetHour = time.altzone / 3600
|
||||
else:
|
||||
offsetHour = time.timezone / 3600
|
||||
localtz = 'Etc/GMT%+d' % offsetHour
|
||||
|
||||
# Convert UTC date into system locale date
|
||||
_date = _date.astimezone(pytz.timezone(localtz))
|
||||
if isinstance(_date, datetime):
|
||||
return _date.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
|
Loading…
Add table
Reference in a new issue