2013-04-23 18:51:17 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2012-12-05 19:53:23 +01:00
|
|
|
import datetime
|
2012-12-11 23:08:17 +01:00
|
|
|
import calendar
|
2012-12-05 19:53:23 +01:00
|
|
|
from django.utils.timezone import utc
|
|
|
|
|
|
|
|
def timestamp_to_datetime(timestamp):
|
2016-06-03 23:32:55 +02:00
|
|
|
# type: (float) -> datetime.datetime
|
2012-12-05 19:53:23 +01:00
|
|
|
return datetime.datetime.utcfromtimestamp(float(timestamp)).replace(tzinfo=utc)
|
2012-12-11 23:08:17 +01:00
|
|
|
|
|
|
|
def datetime_to_timestamp(datetime_object):
|
2016-06-03 23:32:55 +02:00
|
|
|
# type: (datetime.datetime) -> int
|
2012-12-11 23:08:17 +01:00
|
|
|
return calendar.timegm(datetime_object.timetuple())
|