Skip to content
Snippets Groups Projects
Commit 396d2118 authored by sveseli's avatar sveseli
Browse files

add utc to localtime method

parent eb3d32e7
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,8 @@ from dm.common.exceptions.invalidArgument import InvalidArgument ...@@ -8,6 +8,8 @@ from dm.common.exceptions.invalidArgument import InvalidArgument
class TimeUtility: class TimeUtility:
UTC_MINUS_LOCAL_TIME = None
@classmethod @classmethod
def getCurrentGMTimeStamp(cls): def getCurrentGMTimeStamp(cls):
""" Formats GMT timestamp. """ """ Formats GMT timestamp. """
...@@ -39,8 +41,25 @@ class TimeUtility: ...@@ -39,8 +41,25 @@ class TimeUtility:
raise InvalidArgument('Cannot parse input: %s' % ex) raise InvalidArgument('Cannot parse input: %s' % ex)
return tz.localize(dt, is_dst=None) return tz.localize(dt, is_dst=None)
@classmethod
def utcToLocalTime(cls, utc):
if cls.UTC_MINUS_LOCAL_TIME is None:
cls.UTC_MINUS_LOCAL_TIME = (datetime.datetime.utcnow()-datetime.datetime.now()).total_seconds()
localTime = utc - cls.UTC_MINUS_LOCAL_TIME
return localTime
####################################################################### #######################################################################
# Testing. # Testing.
if __name__ == '__main__': if __name__ == '__main__':
print TimeUtility.toDateTime('2015-01-03', '%Y-%m-%d') print TimeUtility.toDateTime('2015-01-03', '%Y-%m-%d')
dt0 = datetime.datetime.utcnow()
dt1 = datetime.datetime.now()
ts0 = time.mktime(dt0.timetuple())
ts1 = time.mktime(dt1.timetuple())
t0 = time.strftime("%Y/%m/%d %H:%M:%S", dt0.timetuple())
print 'UTC: ', t0, ts0
t1 = time.strftime("%Y/%m/%d %H:%M:%S", dt1.timetuple())
print 'LOCAL: ', t1, ts1
print 'UTC TO LOCAL: ', TimeUtility.utcToLocalTime(ts0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment