aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dateutil/utils.py15
-rw-r--r--docs/index.rst1
-rw-r--r--docs/utils.rst6
3 files changed, 22 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
diff --git a/docs/index.rst b/docs/index.rst
index b2503a1..55dfd7e 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -19,6 +19,7 @@ Contents:
relativedelta
rrule
tz
+ utils
zoneinfo
examples
diff --git a/docs/utils.rst b/docs/utils.rst
new file mode 100644
index 0000000..5f36591
--- /dev/null
+++ b/docs/utils.rst
@@ -0,0 +1,6 @@
+=====
+utils
+=====
+.. automodule:: dateutil.utils
+ :members:
+ :undoc-members: