def tz_fix_utc_epoch(utc_epoch, timezone): """Take a UTC epoch seconds value, and convert it into a date time string in the provided timezone""" return timezone.normalize( pytz.utc.localize( from_epoch(utc_epoch) ) ).strftime(DATETIME_FORMAT)
def make_naive(value, timezone): """ Makes an aware datetime.datetime naive in a given time zone. """ value = value.astimezone(timezone) if hasattr(timezone, 'normalize'): # available for pytz time zones value = timezone.normalize(value) return value.replace(tzinfo=None)
def localtime(value, timezone=None): """ Converts an aware datetime.datetime to local time. Local time is defined by the current time zone, unless another time zone is specified. """ if timezone is None: timezone = get_current_timezone() value = value.astimezone(timezone) if hasattr(timezone, 'normalize'): # available for pytz time zones value = timezone.normalize(value) return value
def get_date_time(timestamp): utc_timezone = pytz.timezone('UTC') utc_datatime = utc_timezone.localize( datetime.utcfromtimestamp(float(timestamp))) timezone = pytz.timezone(settings.TIME_ZONE) return timezone.normalize(utc_datatime.astimezone(timezone))