コード例 #1
0
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)
コード例 #2
0
 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)
コード例 #3
0
 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))
コード例 #4
0
 def test_day_30_of_29_day_month(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 2, 30, 0, 0, 0)
コード例 #5
0
 def test_day_31_of_30_day_month(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 4, 31, 0, 0, 0)
コード例 #6
0
 def test_year_lower_bound(self):
     with self.assertRaises(ValueError):
         _ = DateTime(MIN_YEAR - 1, 1, 1, 0, 0, 0)
コード例 #7
0
 def test_month_upper_bound(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 13, 1, 0, 0, 0)
コード例 #8
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))
コード例 #9
0
 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))
コード例 #10
0
def get_datetime_unix_epoch_utc():
    from pytz import utc
    return DateTime(1970, 1, 1, 0, 0, 0, utc)
コード例 #11
0
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"
コード例 #12
0
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
コード例 #13
0
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)
コード例 #14
0
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)
コード例 #15
0
 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)
コード例 #16
0
 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)
コード例 #17
0
 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)
コード例 #18
0
 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)
コード例 #19
0
 def test_year_upper_bound(self):
     with self.assertRaises(ValueError):
         _ = DateTime(MAX_YEAR + 1, 1, 1, 0, 0, 0)
コード例 #20
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())
コード例 #21
0
 def test_day_zero(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 1, 0, 0, 0, 0)
コード例 #22
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())
コード例 #23
0
 def test_day_32_of_31_day_month(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 3, 32, 0, 0, 0)
コード例 #24
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())
コード例 #25
0
 def test_day_29_of_28_day_month(self):
     with self.assertRaises(ValueError):
         _ = DateTime(1999, 2, 29, 0, 0, 0)
コード例 #26
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())
コード例 #27
0
 def test_from_overflowing_timestamp(self):
     with self.assertRaises(ValueError):
         _ = DateTime.from_timestamp(999999999999999999)
コード例 #28
0
 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)
コード例 #29
0
 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))
コード例 #30
0
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