def test_nanosecond_precision(self): t = Time(12, 34, 56.789123456) self.assertEqual(t.hour_minute_second, (12, 34, 56.789123456)) self.assertEqual(t.ticks, 45296.789123456) self.assertEqual(t.hour, 12) self.assertEqual(t.minute, 34) self.assertEqual(t.second, 56.789123456)
def test_midnight(self): t = Time(0, 0, 0) self.assertEqual(t.hour_minute_second, (0, 0, 0)) self.assertEqual(t.ticks, 0) self.assertEqual(t.hour, 0) self.assertEqual(t.minute, 0) self.assertEqual(t.second, 0)
def test_simple_time(self): t = Time(12, 34, 56.789) self.assertEqual(t.hour_minute_second, (12, 34, 56.789)) self.assertEqual(t.ticks, 45296.789) self.assertEqual(t.hour, 12) self.assertEqual(t.minute, 34) self.assertEqual(t.second, 56.789)
def _hydrate_time(self, nanoseconds, tz=None): """ Hydrator for `Time` and `LocalTime` values. :param nanoseconds: :param tz: :return: Time """ seconds, nanoseconds = map(int, divmod(nanoseconds, 1000000000)) minutes, seconds = map(int, divmod(seconds, 60)) hours, minutes = map(int, divmod(minutes, 60)) seconds = (1000000000 * seconds + nanoseconds) / 1000000000 t = Time(hours, minutes, seconds) if tz is None: return t tz_offset_minutes, tz_offset_seconds = divmod(tz, 60) zone = FixedOffset(tz_offset_minutes) return zone.localize(t)
def hydrate_datetime(seconds, nanoseconds, tz=None): """ Hydrator for `DateTime` and `LocalDateTime` values. :param seconds: :param nanoseconds: :param tz: :return: datetime """ minutes, seconds = map(int, divmod(seconds, 60)) hours, minutes = map(int, divmod(minutes, 60)) days, hours = map(int, divmod(hours, 24)) seconds = (1000000000 * seconds + nanoseconds) / 1000000000 t = DateTime.combine(UNIX_EPOCH_DATE_ORDINAL + days, Time(hours, minutes, seconds)) if tz is None: return t if isinstance(tz, int): tz_offset_minutes, tz_offset_seconds = divmod(tz, 60) zone = FixedOffset(tz_offset_minutes) else: zone = timezone(tz) return zone.localize(t)
def test_time(graph): skip_if_no_temporal_support(graph) i = Time(12, 34, 56.789) o = graph.evaluate("RETURN $x", x=i) assert o == i
def test_time_property(self): a = Node(t=Time(12, 34, 56)) r = cypher_repr(a) self.assertEqual("({t: time('12:34:56.000000000')})", r)
def test_aware_time(cls): from neotime import Time b, unpacked = pack_and_unpack(cls(0, 0, 0, tzinfo=utc), version=(2, 0)) assert b == b"\xB2T\x00\x00" assert unpacked == Time(0, 0, 0, tzinfo=utc)
def test_naive_time(cls): from neotime import Time b, unpacked = pack_and_unpack(cls(0, 0, 0), version=(2, 0)) assert b == b"\xB1t\x00" assert unpacked == Time(0, 0, 0)
def test_str(self): t = Time(12, 34, 56.789123456) self.assertEqual(str(t), "12:34:56.789123456")
def test_bad_attribute(self): t = Time(12, 34, 56.789) with self.assertRaises(AttributeError): _ = t.x