Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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))