summaryrefslogtreecommitdiffstats
path: root/tests/datetime/test_strings.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-05 10:38:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-05 10:38:34 +0000
commite3bdad36cc3a1a00c1e6772ca1c1898085ab73e0 (patch)
tree34512072a667ae716fd262e7b37e733e60fe4d89 /tests/datetime/test_strings.py
parentAdding upstream version 2.1.2. (diff)
downloadpendulum-83a7f839c9a467bc9d84890cf9e61ed3520cd627.tar.xz
pendulum-83a7f839c9a467bc9d84890cf9e61ed3520cd627.zip
Adding upstream version 3.0.0~a1.upstream/3.0.0_a1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/datetime/test_strings.py')
-rw-r--r--tests/datetime/test_strings.py141
1 files changed, 141 insertions, 0 deletions
diff --git a/tests/datetime/test_strings.py b/tests/datetime/test_strings.py
new file mode 100644
index 0000000..0de340d
--- /dev/null
+++ b/tests/datetime/test_strings.py
@@ -0,0 +1,141 @@
+from __future__ import annotations
+
+import pytest
+
+import pendulum
+
+
+def test_to_string():
+ d = pendulum.datetime(1975, 12, 25, 0, 0, 0, 0, tz="local")
+ assert str(d) == d.to_iso8601_string()
+ d = pendulum.datetime(1975, 12, 25, 0, 0, 0, 123456, tz="local")
+ assert str(d) == d.to_iso8601_string()
+
+
+def test_to_date_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16)
+
+ assert d.to_date_string() == "1975-12-25"
+
+
+def test_to_formatted_date_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16)
+
+ assert d.to_formatted_date_string() == "Dec 25, 1975"
+
+
+def test_to_timestring():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16)
+
+ assert d.to_time_string() == "14:15:16"
+
+
+def test_to_atom_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_atom_string() == "1975-12-25T14:15:16-05:00"
+
+
+def test_to_cookie_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_cookie_string() == "Thursday, 25-Dec-1975 14:15:16 EST"
+
+
+def test_to_iso8601_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_iso8601_string() == "1975-12-25T14:15:16-05:00"
+
+
+def test_to_iso8601_string_utc():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16)
+ assert d.to_iso8601_string() == "1975-12-25T14:15:16Z"
+
+
+def test_to_iso8601_extended_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, 123456, tz="local")
+ assert d.to_iso8601_string() == "1975-12-25T14:15:16.123456-05:00"
+
+
+def test_to_rfc822_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_rfc822_string() == "Thu, 25 Dec 75 14:15:16 -0500"
+
+
+def test_to_rfc850_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_rfc850_string() == "Thursday, 25-Dec-75 14:15:16 EST"
+
+
+def test_to_rfc1036_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_rfc1036_string() == "Thu, 25 Dec 75 14:15:16 -0500"
+
+
+def test_to_rfc1123_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_rfc1123_string() == "Thu, 25 Dec 1975 14:15:16 -0500"
+
+
+def test_to_rfc2822_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_rfc2822_string() == "Thu, 25 Dec 1975 14:15:16 -0500"
+
+
+def test_to_rfc3339_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_rfc3339_string() == "1975-12-25T14:15:16-05:00"
+
+
+def test_to_rfc3339_extended_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, 123456, tz="local")
+ assert d.to_rfc3339_string() == "1975-12-25T14:15:16.123456-05:00"
+
+
+def test_to_rss_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_rss_string() == "Thu, 25 Dec 1975 14:15:16 -0500"
+
+
+def test_to_w3c_string():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.to_w3c_string() == "1975-12-25T14:15:16-05:00"
+
+
+def test_to_string_invalid():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+
+ with pytest.raises(ValueError):
+ d._to_string("invalid")
+
+
+def test_repr():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ expected = f"DateTime(1975, 12, 25, 14, 15, 16, tzinfo={repr(d.tzinfo)})"
+ assert repr(d) == expected
+
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, 123456, tz="local")
+ expected = f"DateTime(1975, 12, 25, 14, 15, 16, 123456, tzinfo={repr(d.tzinfo)})"
+ assert repr(d) == expected
+
+
+def test_format_with_locale():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ expected = "jeudi 25e jour de décembre 1975 02:15:16 PM -05:00"
+ assert d.format("dddd Do [jour de] MMMM YYYY hh:mm:ss A Z", locale="fr") == expected
+
+
+def test_strftime():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.strftime("%d") == "25"
+
+
+def test_for_json():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
+ assert d.for_json() == "1975-12-25T14:15:16-05:00"
+
+
+def test_format():
+ d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="Europe/Paris")
+ assert f"{d}" == "1975-12-25T14:15:16+01:00"
+ assert f"{d:YYYY}" == "1975"
+ assert f"{d:%Y}" == "1975"
+ assert f"{d:%H:%M %d.%m.%Y}" == "14:15 25.12.1975"