aboutsummaryrefslogtreecommitdiff
path: root/dateutil/utils.py
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2017-10-25 11:57:57 -0400
committerPaul Ganssle <paul@ganssle.io>2017-10-25 11:57:57 -0400
commit45ebe06b6f35885b8615ae7d43fcb76a7ca35e99 (patch)
treebe9380a5fcba2d0eff7ac9722c91f7c9ca5cea6a /dateutil/utils.py
parentb0167c179235d99a58dd0ec27fc4c7ff213b4f7f (diff)
downloaddateutil-45ebe06b6f35885b8615ae7d43fcb76a7ca35e99.tar.gz
Improve documentation for utils.default_tzinfo
Diffstat (limited to 'dateutil/utils.py')
-rw-r--r--dateutil/utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/dateutil/utils.py b/dateutil/utils.py
index ae700b9..29f8181 100644
--- a/dateutil/utils.py
+++ b/dateutil/utils.py
@@ -24,6 +24,21 @@ def default_tzinfo(dt, tzinfo):
"""
Sets the the ``tzinfo`` parameter on naive datetimes only
+ This is useful for example when you are provided a datetime that may have
+ either an implicit or explicit time zone, such as when parsing a time zone
+ string.
+
+ .. doctest::
+
+ >>> from dateutil.tz import tzoffset
+ >>> from dateutil.parser import parse
+ >>> from dateutil.utils import default_tzinfo
+ >>> dflt_tz = tzoffset("EST", -18000)
+ >>> print(default_tzinfo(parse('2014-01-01 12:30 UTC'), dflt_tz))
+ 2014-01-01 12:30:00+00:00
+ >>> print(default_tzinfo(parse('2014-01-01 12:30'), dflt_tz))
+ 2014-01-01 12:30:00-05:00
+
:param dt:
The datetime on which to replace the time zone