Esempio n. 1
0
 def test_datetime_array(self):
     self.assert_supports_temporal_types()
     with self.driver.session() as session:
         data = [
             DateTime(2018, 4, 6, 13, 4, 42.516120),
             DateTime(1976, 6, 13)
         ]
         value = session.write_transaction(run_and_rollback,
                                           "CREATE (a {x:$x}) RETURN a.x",
                                           x=data)
         self.assertEqual(value, data)
Esempio n. 2
0
 def test_whole_second_localdatetime(self):
     self.assert_supports_temporal_types()
     with self.driver.session() as session:
         result = session.run("RETURN localdatetime('1976-06-13T12:34:56')")
         value = result.single().value()
         self.assertIsInstance(value, DateTime)
         self.assertEqual(value, DateTime(1976, 6, 13, 12, 34, 56))
Esempio n. 3
0
 def test_datetime_with_named_time_zone(self):
     self.assert_supports_temporal_types()
     with self.driver.session() as session:
         result = session.run("RETURN datetime('1976-06-13T12:34:56.789012345[Europe/London]')")
         value = result.single().value()
         self.assertIsInstance(value, DateTime)
         self.assertEqual(value, timezone("Europe/London").localize(DateTime(1976, 6, 13, 12, 34, 56.789012345)))
Esempio n. 4
0
 def test_datetime_with_numeric_time_offset(self):
     self.assert_supports_temporal_types()
     with self.driver.session() as session:
         result = session.run("RETURN datetime('1976-06-13T12:34:56.789012345+01:30')")
         value = result.single().value()
         self.assertIsInstance(value, DateTime)
         self.assertEqual(value, DateTime(1976, 6, 13, 12, 34, 56.789012345, tzinfo=FixedOffset(90)))
Esempio n. 5
0
 def test_nanosecond_resolution_datetime(self):
     self.assert_supports_temporal_types()
     with self.driver.session() as session:
         result = session.run("RETURN datetime('1976-06-13T12:34:56.789012345')")
         value = result.single().value()
         self.assertIsInstance(value, DateTime)
         self.assertEqual(value, DateTime(1976, 6, 13, 12, 34, 56.789012345, tzinfo=utc))
Esempio n. 6
0
 def test_whole_second_datetime(self):
     self.assert_supports_temporal_types()
     with self.driver.session() as session:
         result = session.run("CYPHER runtime=interpreted WITH $x AS x "
                              "RETURN x.year, x.month, x.day, "
                              "       x.hour, x.minute, x.second",
                              x=DateTime(1976, 6, 13, 12, 34, 56))
         year, month, day, hour, minute, second = result.single()
         self.assertEqual(year, 1976)
         self.assertEqual(month, 6)
         self.assertEqual(day, 13)
         self.assertEqual(hour, 12)
         self.assertEqual(minute, 34)
         self.assertEqual(second, 56)
Esempio n. 7
0
 def test_datetime_with_numeric_time_offset(self):
     self.assert_supports_temporal_types()
     with self.driver.session() as session:
         result = session.run("CYPHER runtime=interpreted WITH $x AS x "
                              "RETURN x.year, x.month, x.day, "
                              "       x.hour, x.minute, x.second, x.nanosecond, x.offset",
                              x=DateTime(1976, 6, 13, 12, 34, 56.789012345, tzinfo=FixedOffset(90)))
         year, month, day, hour, minute, second, nanosecond, offset = result.single()
         self.assertEqual(year, 1976)
         self.assertEqual(month, 6)
         self.assertEqual(day, 13)
         self.assertEqual(hour, 12)
         self.assertEqual(minute, 34)
         self.assertEqual(second, 56)
         self.assertEqual(nanosecond, 789012345)
         self.assertEqual(offset, "+01:30")
Esempio n. 8
0
 def test_datetime_with_named_time_zone(self):
     self.assert_supports_temporal_types()
     with self.driver.session() as session:
         input_value = timezone("US/Pacific").localize(DateTime(1976, 6, 13, 12, 34, 56.789012345))
         result = session.run("CYPHER runtime=interpreted WITH $x AS x "
                              "RETURN x.year, x.month, x.day, "
                              "       x.hour, x.minute, x.second, x.nanosecond, x.timezone",
                              x=input_value)
         year, month, day, hour, minute, second, nanosecond, tz = result.single()
         self.assertEqual(year, input_value.year)
         self.assertEqual(month, input_value.month)
         self.assertEqual(day, input_value.day)
         self.assertEqual(hour, input_value.hour)
         self.assertEqual(minute, input_value.minute)
         self.assertEqual(second, int(input_value.second))
         self.assertEqual(nanosecond, int (1000000000 * input_value.second) % 1000000000)
         self.assertEqual(tz, input_value.tzinfo.zone)