diff options
Diffstat (limited to 'tests/test_time.py')
-rw-r--r-- | tests/test_time.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/test_time.py b/tests/test_time.py index bd0e63f..62d4361 100644 --- a/tests/test_time.py +++ b/tests/test_time.py @@ -1,6 +1,7 @@ import unittest +import sys -from sqlglot.time import format_time +from sqlglot.time import format_time, subsecond_precision class TestTime(unittest.TestCase): @@ -12,3 +13,22 @@ class TestTime(unittest.TestCase): self.assertEqual(format_time("aa", mapping), "c") self.assertEqual(format_time("aaada", mapping), "cbdb") self.assertEqual(format_time("da", mapping), "db") + + def test_subsecond_precision(self): + self.assertEqual(6, subsecond_precision("2023-01-01 12:13:14.123456+00:00")) + self.assertEqual(3, subsecond_precision("2023-01-01 12:13:14.123+00:00")) + self.assertEqual(0, subsecond_precision("2023-01-01 12:13:14+00:00")) + self.assertEqual(0, subsecond_precision("2023-01-01 12:13:14")) + self.assertEqual(0, subsecond_precision("garbage")) + + @unittest.skipUnless( + sys.version_info >= (3, 11), + "Python 3.11 relaxed datetime.fromisoformat() parsing with regards to microseconds", + ) + def test_subsecond_precision_python311(self): + # ref: https://docs.python.org/3/whatsnew/3.11.html#datetime + self.assertEqual(6, subsecond_precision("2023-01-01 12:13:14.123456789+00:00")) + self.assertEqual(6, subsecond_precision("2023-01-01 12:13:14.12345+00:00")) + self.assertEqual(6, subsecond_precision("2023-01-01 12:13:14.1234+00:00")) + self.assertEqual(3, subsecond_precision("2023-01-01 12:13:14.12+00:00")) + self.assertEqual(3, subsecond_precision("2023-01-01 12:13:14.1+00:00")) |