pyRFC3339 2.1.1__tar.gz → 2.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/CHANGES.rst +10 -0
  2. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/LICENSE.txt +1 -1
  3. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/PKG-INFO +19 -6
  4. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/README.rst +16 -3
  5. pyrfc3339-2.1.2/docs/requirements.txt +3 -0
  6. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/doc.rst +0 -1
  7. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyRFC3339.egg-info/PKG-INFO +19 -6
  8. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyRFC3339.egg-info/SOURCES.txt +1 -3
  9. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyRFC3339.egg-info/scm_file_list.json +4 -3
  10. pyrfc3339-2.1.2/pyRFC3339.egg-info/scm_version.json +8 -0
  11. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyproject.toml +21 -12
  12. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyrfc3339/__init__.py +2 -2
  13. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyrfc3339/generator.py +12 -4
  14. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyrfc3339/parser.py +29 -8
  15. pyrfc3339-2.1.1/docs/requirements.txt +0 -3
  16. pyrfc3339-2.1.1/docs/source/utils.rst +0 -6
  17. pyrfc3339-2.1.1/pyRFC3339.egg-info/scm_version.json +0 -8
  18. pyrfc3339-2.1.1/pyrfc3339/utils.py +0 -34
  19. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/.gitignore +0 -0
  20. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/MANIFEST.in +0 -0
  21. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/build/.gitignore +0 -0
  22. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/_static/.gitignore +0 -0
  23. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/_templates/.gitignore +0 -0
  24. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/changes.rst +0 -0
  25. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/conf.py +0 -0
  26. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/generator.rst +0 -0
  27. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/index.rst +0 -0
  28. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/intro.rst +0 -0
  29. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/license.rst +0 -0
  30. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/parser.rst +0 -0
  31. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/docs/source/pyrfc3339.rst +0 -0
  32. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyRFC3339.egg-info/dependency_links.txt +0 -0
  33. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyRFC3339.egg-info/top_level.txt +0 -0
  34. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/pyrfc3339/py.typed +0 -0
  35. {pyrfc3339-2.1.1 → pyrfc3339-2.1.2}/setup.cfg +0 -0
@@ -1,6 +1,16 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 2.1.2 (2026-11-28)
5
+ ------------------
6
+
7
+ - Update ``README`` to clarify that this package does nothing special
8
+ which cannot be done by :mod:`datetime` and :mod:`zoneinfo` and has been
9
+ made irrelevant by improvements to the Python standard library.
10
+ - Simplify logic to eliminate all uses of regular expressions (except in some tests).
11
+ - Simplify logic to eliminate the ``pyrfc3339.utils`` module.
12
+
13
+
4
14
  2.1.1 (2026-10-10)
5
15
  ------------------
6
16
 
@@ -1,4 +1,4 @@
1
- Copyright (c) 2025 Contributors to the pyRFC3339 project
1
+ Copyright (c) 2026 Contributors to the pyRFC3339 project
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyRFC3339
3
- Version: 2.1.1
3
+ Version: 2.1.2
4
4
  Summary: Generate and parse RFC 3339 timestamps
5
5
  Author-email: Kurt Raschke <kurt@kurtraschke.com>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/kurtraschke/pyrfc3339
8
8
  Project-URL: Documentation, https://pyrfc3339.readthedocs.io/
9
- Project-URL: Repository, https://github.com/kurtraschke/pyRFC3339.git
10
- Project-URL: Bug Tracker, https://github.com/kurtraschke/pyRFC3339/issues
9
+ Project-URL: Source, https://github.com/kurtraschke/pyRFC3339.git
10
+ Project-URL: Issues, https://github.com/kurtraschke/pyRFC3339/issues
11
11
  Project-URL: Changelog, https://github.com/kurtraschke/pyRFC3339/blob/main/CHANGES.rst
12
12
  Keywords: rfc-3339,timestamp,iso-8601,datetime
13
13
  Classifier: Development Status :: 5 - Production/Stable
@@ -26,9 +26,6 @@ Description-Content-Type: text/x-rst
26
26
  License-File: LICENSE.txt
27
27
  Dynamic: license-file
28
28
 
29
- Description
30
- ===========
31
-
32
29
  .. image:: https://github.com/kurtraschke/pyRFC3339/actions/workflows/python.yml/badge.svg
33
30
  :target: https://github.com/kurtraschke/pyRFC3339/actions/workflows/python.yml
34
31
  :alt: Build Status
@@ -37,6 +34,9 @@ Description
37
34
  :target: https://pyrfc3339.readthedocs.io/en/latest/?badge=latest
38
35
  :alt: Documentation Status
39
36
 
37
+ Description
38
+ ===========
39
+
40
40
  pyRFC3339 parses and generates :RFC:`3339`-compliant timestamps using `Python <https://www.python.org/>`_ `datetime.datetime <https://docs.python.org/3/library/datetime.html#datetime-objects>`_ objects.
41
41
 
42
42
  >>> from pyrfc3339 import generate, parse
@@ -48,6 +48,15 @@ datetime.datetime(2009, 1, 1, 10, 1, 2, tzinfo=datetime.timezone.utc)
48
48
  >>> parse('2009-01-01T14:01:02-04:00')
49
49
  datetime.datetime(2009, 1, 1, 14, 1, 2, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=72000)))
50
50
 
51
+ Status
52
+ ======
53
+
54
+ The first lines of code for what would become pyRFC3339 were written in 2009, as part of a larger project which would itself never see the light of day. At the time, the most expedient approach to parsing RFC 3339 timestamps seemed to be to use a regular expression derived from the ABNF grammar contained in the RFC. In retrospect, this seems absurd. Seventeen years later, the Python standard library is now well-suited to the task.
55
+
56
+ To be blunt: **you do not need pyRFC3339 on any modern version of Python** [#f1]_. This library is now merely a thin wrapper around the `datetime.datetime.fromisoformat() <https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat>`_ and `datetime.datetime.isoformat() <https://docs.python.org/3/library/datetime.html#datetime.datetime.isoformat>`_. You can call these functions yourself and eliminate a dependency from your dependency tree.
57
+
58
+ It is completely true that once upon a time, handling of `ISO 8601 <https://www.iso.org/iso-8601-date-and-time-format.html>`_ (and, by extension, RFC 3339) timestamps was a notable blindspot in Python's "batteries-included" standard library. But this is no longer the case. There is now built-in support for the `IANA time zone database <https://www.iana.org/time-zones>`_ as well as all of the relevant parts of ISO 8601.
59
+
51
60
  Installation
52
61
  ============
53
62
 
@@ -70,3 +79,7 @@ To build the documentation with Sphinx:
70
79
  The documentation is also available online at:
71
80
 
72
81
  https://pyrfc3339.readthedocs.io/
82
+
83
+ .. rubric:: Footnotes
84
+
85
+ .. [#f1] for clarity, any Python version supported as of November 2026, or any version greater than or equal to 3.11
@@ -1,6 +1,3 @@
1
- Description
2
- ===========
3
-
4
1
  .. image:: https://github.com/kurtraschke/pyRFC3339/actions/workflows/python.yml/badge.svg
5
2
  :target: https://github.com/kurtraschke/pyRFC3339/actions/workflows/python.yml
6
3
  :alt: Build Status
@@ -9,6 +6,9 @@ Description
9
6
  :target: https://pyrfc3339.readthedocs.io/en/latest/?badge=latest
10
7
  :alt: Documentation Status
11
8
 
9
+ Description
10
+ ===========
11
+
12
12
  pyRFC3339 parses and generates :RFC:`3339`-compliant timestamps using `Python <https://www.python.org/>`_ `datetime.datetime <https://docs.python.org/3/library/datetime.html#datetime-objects>`_ objects.
13
13
 
14
14
  >>> from pyrfc3339 import generate, parse
@@ -20,6 +20,15 @@ datetime.datetime(2009, 1, 1, 10, 1, 2, tzinfo=datetime.timezone.utc)
20
20
  >>> parse('2009-01-01T14:01:02-04:00')
21
21
  datetime.datetime(2009, 1, 1, 14, 1, 2, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=72000)))
22
22
 
23
+ Status
24
+ ======
25
+
26
+ The first lines of code for what would become pyRFC3339 were written in 2009, as part of a larger project which would itself never see the light of day. At the time, the most expedient approach to parsing RFC 3339 timestamps seemed to be to use a regular expression derived from the ABNF grammar contained in the RFC. In retrospect, this seems absurd. Seventeen years later, the Python standard library is now well-suited to the task.
27
+
28
+ To be blunt: **you do not need pyRFC3339 on any modern version of Python** [#f1]_. This library is now merely a thin wrapper around the `datetime.datetime.fromisoformat() <https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat>`_ and `datetime.datetime.isoformat() <https://docs.python.org/3/library/datetime.html#datetime.datetime.isoformat>`_. You can call these functions yourself and eliminate a dependency from your dependency tree.
29
+
30
+ It is completely true that once upon a time, handling of `ISO 8601 <https://www.iso.org/iso-8601-date-and-time-format.html>`_ (and, by extension, RFC 3339) timestamps was a notable blindspot in Python's "batteries-included" standard library. But this is no longer the case. There is now built-in support for the `IANA time zone database <https://www.iana.org/time-zones>`_ as well as all of the relevant parts of ISO 8601.
31
+
23
32
  Installation
24
33
  ============
25
34
 
@@ -42,3 +51,7 @@ To build the documentation with Sphinx:
42
51
  The documentation is also available online at:
43
52
 
44
53
  https://pyrfc3339.readthedocs.io/
54
+
55
+ .. rubric:: Footnotes
56
+
57
+ .. [#f1] for clarity, any Python version supported as of November 2026, or any version greater than or equal to 3.11
@@ -0,0 +1,3 @@
1
+ Sphinx==9.2.0
2
+ sphinx-issues==6.0.0
3
+ sphinx-rtd-theme==3.1.0
@@ -8,4 +8,3 @@ Modules
8
8
  pyrfc3339
9
9
  generator
10
10
  parser
11
- utils
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyRFC3339
3
- Version: 2.1.1
3
+ Version: 2.1.2
4
4
  Summary: Generate and parse RFC 3339 timestamps
5
5
  Author-email: Kurt Raschke <kurt@kurtraschke.com>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/kurtraschke/pyrfc3339
8
8
  Project-URL: Documentation, https://pyrfc3339.readthedocs.io/
9
- Project-URL: Repository, https://github.com/kurtraschke/pyRFC3339.git
10
- Project-URL: Bug Tracker, https://github.com/kurtraschke/pyRFC3339/issues
9
+ Project-URL: Source, https://github.com/kurtraschke/pyRFC3339.git
10
+ Project-URL: Issues, https://github.com/kurtraschke/pyRFC3339/issues
11
11
  Project-URL: Changelog, https://github.com/kurtraschke/pyRFC3339/blob/main/CHANGES.rst
12
12
  Keywords: rfc-3339,timestamp,iso-8601,datetime
13
13
  Classifier: Development Status :: 5 - Production/Stable
@@ -26,9 +26,6 @@ Description-Content-Type: text/x-rst
26
26
  License-File: LICENSE.txt
27
27
  Dynamic: license-file
28
28
 
29
- Description
30
- ===========
31
-
32
29
  .. image:: https://github.com/kurtraschke/pyRFC3339/actions/workflows/python.yml/badge.svg
33
30
  :target: https://github.com/kurtraschke/pyRFC3339/actions/workflows/python.yml
34
31
  :alt: Build Status
@@ -37,6 +34,9 @@ Description
37
34
  :target: https://pyrfc3339.readthedocs.io/en/latest/?badge=latest
38
35
  :alt: Documentation Status
39
36
 
37
+ Description
38
+ ===========
39
+
40
40
  pyRFC3339 parses and generates :RFC:`3339`-compliant timestamps using `Python <https://www.python.org/>`_ `datetime.datetime <https://docs.python.org/3/library/datetime.html#datetime-objects>`_ objects.
41
41
 
42
42
  >>> from pyrfc3339 import generate, parse
@@ -48,6 +48,15 @@ datetime.datetime(2009, 1, 1, 10, 1, 2, tzinfo=datetime.timezone.utc)
48
48
  >>> parse('2009-01-01T14:01:02-04:00')
49
49
  datetime.datetime(2009, 1, 1, 14, 1, 2, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=72000)))
50
50
 
51
+ Status
52
+ ======
53
+
54
+ The first lines of code for what would become pyRFC3339 were written in 2009, as part of a larger project which would itself never see the light of day. At the time, the most expedient approach to parsing RFC 3339 timestamps seemed to be to use a regular expression derived from the ABNF grammar contained in the RFC. In retrospect, this seems absurd. Seventeen years later, the Python standard library is now well-suited to the task.
55
+
56
+ To be blunt: **you do not need pyRFC3339 on any modern version of Python** [#f1]_. This library is now merely a thin wrapper around the `datetime.datetime.fromisoformat() <https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat>`_ and `datetime.datetime.isoformat() <https://docs.python.org/3/library/datetime.html#datetime.datetime.isoformat>`_. You can call these functions yourself and eliminate a dependency from your dependency tree.
57
+
58
+ It is completely true that once upon a time, handling of `ISO 8601 <https://www.iso.org/iso-8601-date-and-time-format.html>`_ (and, by extension, RFC 3339) timestamps was a notable blindspot in Python's "batteries-included" standard library. But this is no longer the case. There is now built-in support for the `IANA time zone database <https://www.iana.org/time-zones>`_ as well as all of the relevant parts of ISO 8601.
59
+
51
60
  Installation
52
61
  ============
53
62
 
@@ -70,3 +79,7 @@ To build the documentation with Sphinx:
70
79
  The documentation is also available online at:
71
80
 
72
81
  https://pyrfc3339.readthedocs.io/
82
+
83
+ .. rubric:: Footnotes
84
+
85
+ .. [#f1] for clarity, any Python version supported as of November 2026, or any version greater than or equal to 3.11
@@ -15,7 +15,6 @@ docs/source/intro.rst
15
15
  docs/source/license.rst
16
16
  docs/source/parser.rst
17
17
  docs/source/pyrfc3339.rst
18
- docs/source/utils.rst
19
18
  docs/source/_static/.gitignore
20
19
  docs/source/_templates/.gitignore
21
20
  pyRFC3339.egg-info/PKG-INFO
@@ -27,5 +26,4 @@ pyRFC3339.egg-info/top_level.txt
27
26
  pyrfc3339/__init__.py
28
27
  pyrfc3339/generator.py
29
28
  pyrfc3339/parser.py
30
- pyrfc3339/py.typed
31
- pyrfc3339/utils.py
29
+ pyrfc3339/py.typed
@@ -6,10 +6,13 @@
6
6
  ".gitignore",
7
7
  ".idea/codeStyles/Project.xml",
8
8
  ".idea/codeStyles/codeStyleConfig.xml",
9
+ ".idea/go.imports.xml",
9
10
  ".idea/inspectionProfiles/Project_Default.xml",
10
11
  ".idea/jsonSchemas.xml",
11
12
  ".idea/misc.xml",
12
13
  ".idea/modules.xml",
14
+ ".idea/play2_compiler_settings.xml",
15
+ ".idea/pyLspTools.xml",
13
16
  ".idea/pyRFC3339.iml",
14
17
  ".idea/vcs.xml",
15
18
  ".readthedocs.yml",
@@ -30,14 +33,12 @@
30
33
  "docs/source/license.rst",
31
34
  "docs/source/parser.rst",
32
35
  "docs/source/pyrfc3339.rst",
33
- "docs/source/utils.rst",
34
36
  "pyproject.toml",
35
37
  "pyrfc3339/__init__.py",
36
38
  "pyrfc3339/generator.py",
37
39
  "pyrfc3339/parser.py",
38
40
  "pyrfc3339/py.typed",
39
41
  "pyrfc3339/tests/__init__.py",
40
- "pyrfc3339/tests/test_all.py",
41
- "pyrfc3339/utils.py"
42
+ "pyrfc3339/tests/test_all.py"
42
43
  ]
43
44
  }
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "2.1.2",
3
+ "distance": 0,
4
+ "node": "ge7cf5668da54dc8bb1b4b015649fee2bca0dec1f",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-11-28"
8
+ }
@@ -31,8 +31,8 @@ classifiers = [
31
31
  [project.urls]
32
32
  Homepage = "https://github.com/kurtraschke/pyrfc3339"
33
33
  Documentation = "https://pyrfc3339.readthedocs.io/"
34
- Repository = "https://github.com/kurtraschke/pyRFC3339.git"
35
- "Bug Tracker" = "https://github.com/kurtraschke/pyRFC3339/issues"
34
+ Source = "https://github.com/kurtraschke/pyRFC3339.git"
35
+ Issues = "https://github.com/kurtraschke/pyRFC3339/issues"
36
36
  Changelog = "https://github.com/kurtraschke/pyRFC3339/blob/main/CHANGES.rst"
37
37
 
38
38
  [tool.setuptools]
@@ -40,19 +40,16 @@ packages = ["pyrfc3339"]
40
40
 
41
41
  [tool.setuptools_scm]
42
42
 
43
- [tool.mypy]
44
- strict = true
45
-
46
43
  [tool.coverage.run]
47
44
  omit = ["pyrfc3339/tests/*"]
48
45
 
49
46
  [tool.tox]
50
47
  requires = ["tox>=4"]
51
- env_list = ["ruff-lint", "type", "ruff-format", "3.11", "3.12", "3.13", "3.14", "3.15"]
48
+ env_list = ["coverage-clean", "ruff-lint", "ty", "ruff-format", "3.11", "3.12", "3.13", "3.14", "3.15", "coverage-report"]
52
49
  skip_missing_interpreters = true
53
50
 
54
51
  [tool.tox.gh.python]
55
- "3.15" = ["ruff-lint", "type", "ruff-format", "3.15"]
52
+ "3.15" = ["ruff-lint", "ty", "ruff-format", "3.15"]
56
53
  "3.14" = ["3.14"]
57
54
  "3.13" = ["3.13"]
58
55
  "3.12" = ["3.12"]
@@ -66,22 +63,34 @@ commands = [["pytest",
66
63
  "--doctest-modules",
67
64
  "--doctest-continue-on-failure",
68
65
  "--cov=pyrfc3339",
66
+ "--cov-append",
67
+ "--cov-report=",
69
68
  "."]]
70
69
 
71
- [tool.tox.env.type]
70
+ [tool.tox.env.coverage-clean]
71
+ skip_install = true
72
+ deps = ["coverage"]
73
+ commands = [["coverage", "erase"]]
74
+
75
+ [tool.tox.env.coverage-report]
76
+ skip_install = true
77
+ deps = ["coverage"]
78
+ commands = [["coverage", "report", "--show-missing"], ["coverage", "html"]]
79
+
80
+ [tool.tox.env.ty]
72
81
  skip_install = true
73
- deps = ["mypy"]
74
- commands = [["mypy", "pyrfc3339"]]
82
+ deps = ["ty"]
83
+ commands = [["ty", "check"]]
75
84
 
76
85
  [tool.tox.env.ruff-lint]
77
86
  skip_install = true
78
87
  deps = ["ruff"]
79
- commands = [["ruff", "check", "."]]
88
+ commands = [["ruff", "check"]]
80
89
 
81
90
  [tool.tox.env.ruff-format]
82
91
  skip_install = true
83
92
  deps = ["ruff"]
84
- commands = [["ruff", "format", "--check", "--diff", "."]]
93
+ commands = [["ruff", "format", "--check", "--diff"]]
85
94
 
86
95
  [tool.tox.env.docs]
87
96
  deps = ["-r docs/requirements.txt"]
@@ -3,8 +3,8 @@ pyRFC3339 parses and generates :RFC:`3339`-compliant timestamps using Python
3
3
  :class:`datetime.datetime` objects.
4
4
 
5
5
  >>> from pyrfc3339 import generate, parse
6
- >>> from datetime import datetime, timezone
7
- >>> generate(datetime.now(timezone.utc)) #doctest:+ELLIPSIS
6
+ >>> from datetime import datetime, UTC
7
+ >>> generate(datetime.now(UTC)) #doctest:+ELLIPSIS
8
8
  '...T...Z'
9
9
  >>> parse('2009-01-01T10:01:02Z')
10
10
  datetime.datetime(2009, 1, 1, 10, 1, 2, tzinfo=datetime.timezone.utc)
@@ -1,4 +1,3 @@
1
- import re
2
1
  from datetime import UTC, datetime
3
2
 
4
3
 
@@ -20,12 +19,21 @@ def generate(
20
19
  it will use the timezone from the :class:`~datetime.datetime`'s :attr:`~datetime.datetime.tzinfo` attribute.
21
20
 
22
21
  >>> eastern = ZoneInfo('US/Eastern')
23
- >>> dt = datetime(2009, 1, 1, 12, 59, 59, tzinfo=eastern)
22
+ >>> dt = datetime(2009, 1, 1, 12, 59, 59, 0, eastern)
24
23
  >>> generate(dt)
25
24
  '2009-01-01T17:59:59Z'
26
25
  >>> generate(dt, utc=False)
27
26
  '2009-01-01T12:59:59-05:00'
28
27
 
28
+ Timestamps which are explicitly in UTC will have their timezone offset set to 'Z', while those which are not UTC
29
+ but happen to be '+00:00' will remain unchanged.
30
+
31
+ >>> generate(datetime(2009, 1, 1, 12, 59, 59, 0, UTC))
32
+ '2009-01-01T12:59:59Z'
33
+ >>> london = ZoneInfo('Europe/London')
34
+ >>> generate(datetime(2009, 1, 1, 12, 59, 59, 0, london), utc=False)
35
+ '2009-01-01T12:59:59+00:00'
36
+
29
37
  Unless :python:`accept_naive=True` is specified, the :class:`~datetime.datetime` must not be naive.
30
38
 
31
39
  >>> generate(datetime(2009, 1, 1, 12, 59, 59, 0))
@@ -75,7 +83,7 @@ def generate(
75
83
 
76
84
  timestamp = dt.isoformat(timespec="microseconds" if microseconds else "seconds")
77
85
 
78
- if dt.tzinfo == UTC:
79
- timestamp = re.sub(r"\+00:00$", "Z", timestamp)
86
+ if dt.tzinfo == UTC and timestamp.endswith("+00:00"):
87
+ timestamp = timestamp[:-6] + "Z"
80
88
 
81
89
  return timestamp
@@ -1,8 +1,5 @@
1
- import re
2
1
  from datetime import UTC, datetime
3
2
 
4
- from .utils import datetime_utcoffset
5
-
6
3
 
7
4
  def parse(timestamp: str, utc: bool = False, produce_naive: bool = False) -> datetime:
8
5
  """
@@ -27,6 +24,29 @@ def parse(timestamp: str, utc: bool = False, produce_naive: bool = False) -> dat
27
24
  >>> parse('2009-01-01T06:01:02-04:00', utc=True)
28
25
  datetime.datetime(2009, 1, 1, 10, 1, 2, tzinfo=datetime.timezone.utc)
29
26
 
27
+ If :meth:`parse()` is called with :python:`produce_naive=True`, then the returned
28
+ :class:`~datetime.datetime` will be naive (and its :attr:`~datetime.datetime.tzinfo` attribute set to
29
+ :python:`None`). This is not permitted for input timestamps which have a non-zero timezone offset, unless those
30
+ are normalized to UTC with the use of :python:`utc=True`.
31
+ The use of naive datetimes, is, as a matter of course, not recommended.
32
+
33
+ >>> parse('2009-01-01T06:01:02Z', produce_naive=True)
34
+ datetime.datetime(2009, 1, 1, 6, 1, 2)
35
+
36
+ >>> parse('2009-01-01T06:01:02+00:00', produce_naive=True)
37
+ datetime.datetime(2009, 1, 1, 6, 1, 2)
38
+
39
+ >>> parse('2009-01-01T06:01:02-00:00', produce_naive=True)
40
+ datetime.datetime(2009, 1, 1, 6, 1, 2)
41
+
42
+ >>> parse('2009-01-01T06:01:02-04:00', produce_naive=True)
43
+ Traceback (most recent call last):
44
+ ...
45
+ ValueError: cannot produce a naive datetime from a local timestamp
46
+
47
+ >>> parse('2009-01-01T06:01:02-04:00', utc=True, produce_naive=True)
48
+ datetime.datetime(2009, 1, 1, 10, 1, 2)
49
+
30
50
  As parsing is delegated to :meth:`datetime.datetime.fromisoformat()`, certain
31
51
  timestamps which do not strictly adhere to :RFC:`3339` are nonetheless accepted.
32
52
 
@@ -44,15 +64,16 @@ def parse(timestamp: str, utc: bool = False, produce_naive: bool = False) -> dat
44
64
  :param bool utc: :const:`True` to normalize the timestamp to UTC; :const:`False` otherwise. Defaults to :const:`False`.
45
65
  :param bool produce_naive: :const:`True` if the produced :class:`~datetime.datetime` instance should
46
66
  not have a timezone attached (that is, be 'naive'); :const:`False` otherwise.
47
- Defaults to :const:`False`.
67
+ Defaults to :const:`False`. Not permitted for input timestamps which have
68
+ a non-zero timezone offset.
48
69
  :return: the parsed timestamp
49
70
  :rtype: datetime.datetime
50
71
 
51
72
  """
52
73
 
53
- # Python does not recognize "Z" as an alias for "+00:00", so we perform the
54
- # substitution here.
55
- timestamp = re.sub("Z$", "+00:00", timestamp, flags=re.IGNORECASE)
74
+ # Python only recognizes the 'Z' suffix, not 'z'. (python/cpython#80010)
75
+ if timestamp.endswith("z"):
76
+ timestamp = timestamp[:-1] + "Z"
56
77
 
57
78
  dt_out = datetime.fromisoformat(timestamp)
58
79
 
@@ -60,7 +81,7 @@ def parse(timestamp: str, utc: bool = False, produce_naive: bool = False) -> dat
60
81
  dt_out = dt_out.astimezone(UTC)
61
82
 
62
83
  if produce_naive:
63
- if datetime_utcoffset(dt_out) == 0:
84
+ if dt_out.tzinfo == UTC:
64
85
  dt_out = dt_out.replace(tzinfo=None)
65
86
  else:
66
87
  raise ValueError("cannot produce a naive datetime from a local timestamp")
@@ -1,3 +0,0 @@
1
- Sphinx==9.1.0
2
- sphinx-issues==6.0.0
3
- sphinx-rtd-theme==3.1.0
@@ -1,6 +0,0 @@
1
- :mod:`pyrfc3339.utils` -- Utilities for working with timestamps
2
- ===============================================================
3
-
4
- .. automodule:: pyrfc3339.utils
5
- :members:
6
-
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "2.1.1",
3
- "distance": 0,
4
- "node": "gcc6ffe260f63c4e37c2789813894516c089e5cb6",
5
- "dirty": false,
6
- "branch": "HEAD",
7
- "node_date": "2026-10-11"
8
- }
@@ -1,34 +0,0 @@
1
- from datetime import datetime
2
-
3
-
4
- def datetime_utcoffset(dt: datetime) -> float:
5
- """
6
- Return the UTC offset for an aware :class:`datetime.datetime` in seconds.
7
-
8
- >>> from datetime import datetime
9
- >>> from zoneinfo import ZoneInfo
10
- >>> z = ZoneInfo('US/Eastern')
11
- >>> dt = datetime(2024, 11, 5, 19, 7, 6, tzinfo=z)
12
- >>> datetime_utcoffset(dt)
13
- -18000.0
14
-
15
- >>> dt = datetime(2024, 11, 5, 19, 7, 6)
16
- >>> datetime_utcoffset(dt)
17
- Traceback (most recent call last):
18
- ...
19
- AssertionError
20
-
21
- :param datetime.datetime dt: a :class:`~datetime.datetime` instance; must be aware (that is, have a timezone attached)
22
- :return: the UTC offset of the supplied :class:`~datetime.datetime` in seconds
23
- :rtype: float
24
-
25
- """
26
-
27
- assert dt.tzinfo is not None
28
-
29
- tz = dt.tzinfo
30
- offset = tz.utcoffset(dt)
31
-
32
- assert offset is not None
33
-
34
- return offset.total_seconds()
File without changes
File without changes
File without changes
File without changes
File without changes