def test_datetime_with_named_time_zone_output(cypher_eval): value = cypher_eval("RETURN datetime('1976-06-13T12:34:56.789012345" "[Europe/London]')") assert isinstance(value, DateTime) dt = DateTime(1976, 6, 13, 12, 34, 56.789012345) assert value == timezone("Europe/London").localize(dt)
def test_last_day_of_month(self): t = DateTime(2000, 1, -1, 0, 0, 0) self.assertEqual(t.year, 2000) self.assertEqual(t.month, 1) self.assertEqual(t.day, 31)
def test_conversion_to_t(self): dt = DateTime(2018, 4, 26, 23, 0, 17.914390409) t = dt.to_clock_time() self.assertEqual(t, ClockTime(63660380417, 914390409))
def test_day_30_of_29_day_month(self): with self.assertRaises(ValueError): _ = DateTime(2000, 2, 30, 0, 0, 0)
def test_day_31_of_30_day_month(self): with self.assertRaises(ValueError): _ = DateTime(2000, 4, 31, 0, 0, 0)
def test_year_lower_bound(self): with self.assertRaises(ValueError): _ = DateTime(MIN_YEAR - 1, 1, 1, 0, 0, 0)
def test_month_upper_bound(self): with self.assertRaises(ValueError): _ = DateTime(2000, 13, 1, 0, 0, 0)
def test_subtract_datetime_2(self): dt1 = DateTime(2018, 4, 1, 23, 0, 17.914390409) dt2 = DateTime(2018, 1, 26, 0, 0, 0.0) t = dt1 - dt2 self.assertEqual( t, Duration(months=3, days=-25, hours=23, seconds=17.914390409))
def test_subtract_native_datetime_2(self): dt1 = DateTime(2018, 4, 1, 23, 0, 17.914390409) dt2 = datetime(2018, 1, 26, 0, 0, 0) t = dt1 - dt2 self.assertEqual(t, timedelta(days=65, hours=23, seconds=17.914390409))
def get_datetime_unix_epoch_utc(): from pytz import utc return DateTime(1970, 1, 1, 0, 0, 0, utc)
def test_iso_format_with_time_zone_case_2(): # python -m pytest tests/unit/time/test_datetime.py -s -v -k test_iso_format_with_time_zone_case_2 expected = DateTime.from_iso_format("2019-10-30T07:54:02.129790999+01:00") assert expected.tzinfo == FixedOffset(60) assert expected.iso_format() == "2019-10-30T07:54:02.129790999+01:00"
def test_date_array_input(cypher_eval): data = [DateTime.now().date(), Date(1976, 6, 13)] value = cypher_eval("CREATE (a {x:$x}) RETURN a.x", x=data) assert value == data
def test_nanosecond_resolution_localdatetime_output(cypher_eval): value = cypher_eval("RETURN " "localdatetime('1976-06-13T12:34:56.789012345')") assert isinstance(value, DateTime) assert value == DateTime(1976, 6, 13, 12, 34, 56.789012345)
def test_whole_second_localdatetime_output(cypher_eval): value = cypher_eval("RETURN localdatetime('1976-06-13T12:34:56')") assert isinstance(value, DateTime) assert value == DateTime(1976, 6, 13, 12, 34, 56)
def test_from_iso_format_hour_and_minute(self): expected = DateTime(2018, 10, 1, 12, 34, 0) actual = DateTime.from_iso_format("2018-10-01T12:34") self.assertEqual(expected, actual)
def test_normalization(self): ndt1 = eastern.normalize( DateTime(2018, 4, 27, 23, 0, 17, tzinfo=eastern)) ndt2 = eastern.normalize( datetime(2018, 4, 27, 23, 0, 17, tzinfo=eastern)) self.assertEqual(ndt1, ndt2)
def test_from_iso_format_hour_minute_second_nanoseconds(self): expected = DateTime(2018, 10, 1, 12, 34, 56.123456789) actual = DateTime.from_iso_format("2018-10-01T12:34:56.123456789") self.assertEqual(expected, actual)
def test_localization(self): ldt1 = eastern.localize(datetime(2018, 4, 27, 23, 0, 17)) ldt2 = eastern.localize(DateTime(2018, 4, 27, 23, 0, 17)) self.assertEqual(ldt1, ldt2)
def test_year_upper_bound(self): with self.assertRaises(ValueError): _ = DateTime(MAX_YEAR + 1, 1, 1, 0, 0, 0)
def test_iso_format(self): dt = DateTime(2018, 10, 1, 12, 34, 56.789123456) self.assertEqual("2018-10-01T12:34:56.789123456", dt.iso_format())
def test_day_zero(self): with self.assertRaises(ValueError): _ = DateTime(2000, 1, 0, 0, 0, 0)
def test_iso_format_with_trailing_zeroes(self): dt = DateTime(2018, 10, 1, 12, 34, 56.789) self.assertEqual("2018-10-01T12:34:56.789000000", dt.iso_format())
def test_day_32_of_31_day_month(self): with self.assertRaises(ValueError): _ = DateTime(2000, 3, 32, 0, 0, 0)
def test_iso_format_with_tz(self): dt = eastern.localize(DateTime(2018, 10, 1, 12, 34, 56.789123456)) self.assertEqual("2018-10-01T12:34:56.789123456-04:00", dt.iso_format())
def test_day_29_of_28_day_month(self): with self.assertRaises(ValueError): _ = DateTime(1999, 2, 29, 0, 0, 0)
def test_iso_format_with_tz_and_trailing_zeroes(self): dt = eastern.localize(DateTime(2018, 10, 1, 12, 34, 56.789)) self.assertEqual("2018-10-01T12:34:56.789000000-04:00", dt.iso_format())
def test_from_overflowing_timestamp(self): with self.assertRaises(ValueError): _ = DateTime.from_timestamp(999999999999999999)
def test_from_iso_format_hour_only(self): expected = DateTime(2018, 10, 1, 12, 0, 0) actual = DateTime.from_iso_format("2018-10-01T12") self.assertEqual(expected, actual)
def test_add_timedelta(self): dt1 = DateTime(2018, 4, 26, 23, 0, 17.914390409) delta = timedelta(days=1) dt2 = dt1 + delta self.assertEqual(dt2, DateTime(2018, 4, 27, 23, 0, 17.914390409))
def test_datetime_array_input(cypher_eval): data = [DateTime(2018, 4, 6, 13, 4, 42.516120), DateTime(1976, 6, 13)] value = cypher_eval("CREATE (a {x:$x}) RETURN a.x", x=data) assert value == data