1212def test_init_empty ():
1313 t1 = Timestamp ()
1414 assert isinstance (t1 , Timestamp )
15- assert t1 .to_string () == t1 ._obj .instant (). format_common_iso ()
15+ assert t1 .to_datetime () == t1 ._obj .py_datetime ()
1616
1717 t2 = Timestamp (None )
1818 assert isinstance (t2 , Timestamp )
19- assert t2 .to_string () == t2 ._obj .instant (). format_common_iso ()
19+ assert t2 .to_datetime () == t2 ._obj .py_datetime ()
2020
2121
2222def test_init_timestamp ():
2323 t1 = Timestamp ()
2424 t2 = Timestamp (t1 )
2525 assert t1 .to_string () == t2 .to_string ()
2626 assert isinstance (t2 , Timestamp )
27- assert t2 .to_string () == t2 ._obj .instant (). format_common_iso ()
27+ assert t2 .to_datetime () == t2 ._obj .py_datetime ()
2828
2929
3030def test_parse_string ():
@@ -65,15 +65,15 @@ def test_parse_string():
6565)
6666def test_to_datetime (input_str , expected_datetime ):
6767 assert isinstance (Timestamp (input_str ).to_datetime (), datetime )
68- assert str ( Timestamp (input_str ).to_datetime ()) == str ( expected_datetime )
68+ assert Timestamp (input_str ).to_datetime () == expected_datetime
6969
7070
7171@pytest .mark .parametrize (
7272 "input_str,expected_str,expected_str_no_z" ,
7373 [
7474 pytest .param (
7575 "2022-01-01T10:01:01.123000Z" ,
76- "2022-01-01T10:01:01.123Z " ,
76+ "2022-01-01T10:01:01.123000Z " ,
7777 "2022-01-01T10:01:01.123000+00:00" ,
7878 id = "milliseconds" ,
7979 ),
@@ -94,13 +94,13 @@ def test_to_string_default(input_str, expected_str, expected_str_no_z):
9494def test_add ():
9595 t1 = Timestamp ("2022-01-01T10:01:01.123Z" )
9696 t2 = t1 .add (hours = 1 )
97- assert t2 .to_string () == "2022-01-01T11:01:01.123Z "
97+ assert t2 .to_string () == "2022-01-01T11:01:01.123000Z "
9898
9999
100100def test_subtract ():
101101 t1 = Timestamp ("2022-01-01T10:05:01.123Z" )
102102 t2 = t1 .subtract (hours = 1 )
103- assert t2 .to_string () == "2022-01-01T09:05:01.123Z "
103+ assert t2 .to_string () == "2022-01-01T09:05:01.123000Z "
104104
105105
106106def test_compare ():
@@ -119,6 +119,15 @@ def test_compare():
119119 assert t11 == t12
120120
121121
122+ def test_serialize ():
123+ time_no_z = "2022-01-01T11:00:00.000000+00:00"
124+ time = "2022-01-01T11:00:00.000000Z"
125+ timestamp = Timestamp (time )
126+
127+ assert timestamp .to_string (with_z = False ) == time_no_z
128+ assert timestamp .to_string () == time
129+
130+
122131@pytest .mark .parametrize ("invalid_str" , ["blurple" , "1122334455667788" , "2023-45-99" ])
123132def test_invalid_raises_correct_error (invalid_str ):
124133 with pytest .raises (TimestampFormatError ):
0 commit comments