Пример #1
0
    def test_as_time(self):
        time = Time()
        time.hour = 10
        time.minute = 20
        time.sec = 10
        time.microsec = 100
        value = ttypes.Value(tVal=time)
        value_wrapper = ValueWrapper(value)
        assert value_wrapper.is_time()

        time_val = value_wrapper.as_time()
        time_val.set_timezone_offset(28800)
        assert isinstance(time_val, TimeWrapper)
        assert time_val.get_hour() == 10
        assert time_val.get_minute() == 20
        assert time_val.get_sec() == 10
        assert time_val.get_microsec() == 100
        assert 'utc time: 10:20:10.000100, timezone_offset: 28800' == str(
            time_val)
        assert '18:20:10.000100' == time_val.get_local_time_str()
        new_time = copy.deepcopy(time)
        new_time.hour = 18
        assert new_time == time_val.get_local_time()

        new_time_2 = copy.deepcopy(time)
        new_time_2.hour = 12
        assert new_time_2 == time_val.get_local_time_by_timezone_offset(7200)
Пример #2
0
def time_convert_with_timezone(n_time: Time, timezone_offset: int):
    native_date_time = datetime(1, 1, 1, n_time.hour, n_time.minute,
                                n_time.sec, n_time.microsec,
                                pytz.timezone("utc"))
    local_date_time = native_date_time.astimezone(
        timezone(timedelta(seconds=timezone_offset)))
    local_time = Time()
    local_time.hour = local_date_time.hour
    local_time.minute = local_date_time.minute
    local_time.sec = local_date_time.second
    local_time.microsec = local_date_time.microsecond
    return local_time
Пример #3
0
    def test_as_time(self):
        time = Time()
        time.hour = 10
        time.minute = 20
        time.sec = 10
        time.microsec = 100
        value = ttypes.Value(tVal=time)
        value_wrapper = ValueWrapper(value)
        assert value_wrapper.is_time()

        time_val = value_wrapper.as_time()
        assert isinstance(time_val, TimeWrapper)
        assert time_val.get_hour() == 10
        assert time_val.get_minute() == 20
        assert time_val.get_sec() == 10
        assert time_val.get_microsec() == 100
        assert '10:20:10.000100' == str(time_val)
Пример #4
0
def time_convert_with_timezone(n_time: Time, timezone_offset: int):
    """the function to convert utc date_time to local date_time

    :param n_time: the utc time
    :param timezone_offset: the timezone offset
    :return: the time with the timezone
    """
    native_date_time = datetime(1, 1, 1, n_time.hour, n_time.minute,
                                n_time.sec, n_time.microsec,
                                pytz.timezone("utc"))
    local_date_time = native_date_time.astimezone(
        timezone(timedelta(seconds=timezone_offset)))
    local_time = Time()
    local_time.hour = local_date_time.hour
    local_time.minute = local_date_time.minute
    local_time.sec = local_date_time.second
    local_time.microsec = local_date_time.microsecond
    return local_time