def to_native(self): """ Convert to a native Python `datetime.time` value. """ h, m, s = self.hour_minute_second s, ns = nano_divmod(s, 1) ms = int(nano_mul(ns, 1000000)) return time(h, m, s, ms)
def to_native(self): """ Convert to a native Python `datetime.datetime` value. """ y, mo, d = self.year_month_day h, m, s = self.hour_minute_second s, ns = nano_divmod(s, 1) ms = int(nano_mul(ns, 1000000)) return datetime(y, mo, d, h, m, s, ms)
def to_clock_time(self): total_seconds = 0 for year in range(1, self.year): total_seconds += 86400 * Date.days_in_year(year) for month in range(1, self.month): total_seconds += 86400 * Date.days_in_month(self.year, month) total_seconds += 86400 * (self.day - 1) seconds, nanoseconds = nano_divmod(self.__time.ticks, 1) return ClockTime(total_seconds + seconds, 1000000000 * nanoseconds)
def utc_time(self): from time import time seconds, nanoseconds = nano_divmod(int(time() * 1000000), 1000000) return ClockTime(seconds, nanoseconds * 1000)
def from_ticks(cls, ticks, tz=None): if 0 <= ticks < 86400: minute, second = nano_divmod(ticks, 60) hour, minute = divmod(minute, 60) return cls.__new(ticks, hour, minute, second, tz) raise ValueError("Ticks out of range (0..86400)")
def __new__(cls, seconds=0, nanoseconds=0): seconds, nanoseconds = nano_divmod( int(1000000000 * seconds) + int(nanoseconds), 1000000000) return tuple.__new__(cls, (seconds, nanoseconds))
def to_clock_time(self): seconds, nanoseconds = nano_divmod(self.ticks, 1) return ClockTime(seconds, 1000000000 * nanoseconds)