@@ -45,6 +45,52 @@ def test_from_format_with_square_bracket_in_timezone():
4545 )
4646
4747
48+ @pytest .mark .parametrize (
49+ "zone" ,
50+ [
51+ "America/Argentina/Buenos_Aires" ,
52+ "America/Indiana/Indianapolis" ,
53+ "America/Kentucky/Louisville" ,
54+ "America/North_Dakota/New_Salem" ,
55+ "Europe/Paris" ,
56+ "UTC" ,
57+ ],
58+ )
59+ @pytest .mark .parametrize ("month" , [1 , 7 ])
60+ @pytest .mark .parametrize (
61+ "fmt" ,
62+ [
63+ "YYYY-MM-DD HH:mm:ss.SSSSSS z" ,
64+ "z YYYY-MM-DD HH:mm:ss.SSSSSS" ,
65+ "z/YYYY-MM-DD HH:mm:ss.SSSSSS" ,
66+ ],
67+ )
68+ def test_from_format_with_nested_timezone (zone : str , month : int , fmt : str ) -> None :
69+ expected = pendulum .datetime (2024 , month , 15 , 12 , 34 , 56 , 123456 , tz = zone )
70+
71+ actual = pendulum .from_format (expected .format (fmt ), fmt , tz = "Europe/London" )
72+
73+ assert actual == expected
74+ assert actual .timezone_name == zone
75+ assert actual .utcoffset () == expected .utcoffset ()
76+
77+
78+ @pytest .mark .parametrize (
79+ "zone" ,
80+ [
81+ "America/Argentina/Not_A_City" ,
82+ "America/Argentina/Buenos_Aires/Extra" ,
83+ "America//Argentina/Buenos_Aires" ,
84+ "America/Argentina/Buenos_Aires/" ,
85+ "/America/Argentina/Buenos_Aires" ,
86+ "America/Argentina/Buenos_Aires extra" ,
87+ ],
88+ )
89+ def test_from_format_rejects_invalid_nested_timezone (zone : str ) -> None :
90+ with pytest .raises (ValueError ):
91+ pendulum .from_format (f"2024-01-15 12:34:56 { zone } " , "YYYY-MM-DD HH:mm:ss z" )
92+
93+
4894def test_from_format_with_escaped_elements ():
4995 d = pendulum .from_format ("1975-05-21T22:32:11+00:00" , "YYYY-MM-DD[T]HH:mm:ssZ" )
5096 assert_datetime (d , 1975 , 5 , 21 , 22 , 32 , 11 )
0 commit comments