Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dateutil
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
Python
Modules
dateutil
Commits
42bed07ada58
Commit
42bed07ada58
authored
7 years ago
by
Paul Ganssle
Browse files
Options
Downloads
Plain Diff
Merge pull request #671 from weatherpattern/examples-improvement-tzfile
Added examples to tzfile docstring
parents
5a576731bb58
37e4ff00bb7b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/671.doc.rst
+1
-0
1 addition, 0 deletions
changelog.d/671.doc.rst
dateutil/tz/tz.py
+52
-0
52 additions, 0 deletions
dateutil/tz/tz.py
with
53 additions
and
0 deletions
changelog.d/671.doc.rst
0 → 100644
+
1
−
0
View file @
42bed07a
Add doctest examples to tzfile documentation. Done by @weatherpattern and @pganssle (gh pr #671)
This diff is collapsed.
Click to expand it.
dateutil/tz/tz.py
+
52
−
0
View file @
42bed07a
...
...
@@ -190,6 +190,8 @@
class
tzlocal
(
_tzinfo
):
"""
A :class:`tzinfo` subclass built around the ``time`` timezone functions.
"""
def
__init__
(
self
):
super
(
tzlocal
,
self
).
__init__
()
...
...
@@ -392,6 +394,56 @@
Time zone files can be compiled from the `IANA Time Zone database files
<https://www.iana.org/time-zones>`_ with the `zic time zone compiler
<https://www.freebsd.org/cgi/man.cgi?query=zic&sektion=8>`_
.. note::
Only construct a ``tzfile`` directly if you have a specific timezone
file on disk that you want to read into a Python ``tzinfo`` object.
If you want to get a ``tzfile`` representing a specific IANA zone,
(e.g. ``
'
America/New_York
'
``), you should call
:func:`dateutil.tz.gettz` with the zone identifier.
**Examples:**
Using the US Eastern time zone as an example, we can see that a ``tzfile``
provides time zone information for the standard Daylight Saving offsets:
.. testsetup:: tzfile
from dateutil.tz import gettz
from datetime import datetime
.. doctest:: tzfile
>>>
NYC
=
gettz
(
'
America/New_York
'
)
>>>
NYC
tzfile
(
'
/usr/share/zoneinfo/America/New_York
'
)
>>>
print
(
datetime
(
2016
,
1
,
3
,
tzinfo
=
NYC
))
# EST
2016
-
01
-
03
00
:
00
:
00
-
05
:
00
>>>
print
(
datetime
(
2016
,
7
,
7
,
tzinfo
=
NYC
))
# EDT
2016
-
07
-
07
00
:
00
:
00
-
04
:
00
The ``tzfile`` structure contains a fully history of the time zone,
so historical dates will also have the right offsets. For example, before
the adoption of the UTC standards, New York used local solar mean time:
.. doctest:: tzfile
>>>
print
(
datetime
(
1901
,
4
,
12
,
tzinfo
=
NYC
))
# LMT
1901
-
04
-
12
00
:
00
:
00
-
04
:
56
And during World War II, New York was on
"
Eastern War Time
"
, which was a
state of permanent daylight saving time:
.. doctest:: tzfile
>>>
print
(
datetime
(
1944
,
2
,
7
,
tzinfo
=
NYC
))
# EWT
1944
-
02
-
07
00
:
00
:
00
-
04
:
00
"""
def
__init__
(
self
,
fileobj
,
filename
=
None
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment