Skip to content

Commit

Permalink
Respect the $TZ environment variable to show local times if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
Roguelazer committed Jun 13, 2012
1 parent 19a529a commit 0f03a06
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion S3/Utils.py
Expand Up @@ -3,6 +3,7 @@
## http://www.logix.cz/michal ## http://www.logix.cz/michal
## License: GPL Version 2 ## License: GPL Version 2


import datetime
import os import os
import sys import sys
import time import time
Expand All @@ -16,6 +17,7 @@


from logging import debug, info, warning, error from logging import debug, info, warning, error



import Config import Config
import Exceptions import Exceptions


Expand Down Expand Up @@ -163,7 +165,14 @@ def formatSize(size, human_readable = False, floating_point = False):
__all__.append("formatSize") __all__.append("formatSize")


def formatDateTime(s3timestamp): def formatDateTime(s3timestamp):
return time.strftime("%Y-%m-%d %H:%M", dateS3toPython(s3timestamp)) try:
import pytz
timezone = pytz.timezone(os.environ.get('TZ', 'UTC'))
utc_dt = datetime.datetime(*dateS3toPython(s3timestamp)[0:6], tzinfo=pytz.timezone('UTC'))
dt_object = utc_dt.astimezone(timezone)
except ImportError:
dt_object = datetime.datetime(*dateS3toPython(s3timestamp)[0:6])
return dt_object.strftime("%Y-%m-%d %H:%M")
__all__.append("formatDateTime") __all__.append("formatDateTime")


def convertTupleListToDict(list): def convertTupleListToDict(list):
Expand Down

0 comments on commit 0f03a06

Please sign in to comment.