[PATCH] util: add doctest to datestr()

Adrian Buehlmann adrian at cadifra.com
Fri Apr 8 09:29:20 UTC 2016


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1460042647 -7200
# Node ID e4855d9b93ae1c1413b3ab67e9e605b968c89fa9
# Parent  ea86cdcd9b50bf38c6b9dd7bbaa04b9c8cc0aefb
util: add doctest to datestr()

The setlocale call is needed. If I leave it away, the active locale is -
surprisingly - *not* 'C' here.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1576,7 +1576,22 @@
     """represent a (unixtime, offset) tuple as a localized time.
     unixtime is seconds since the epoch, and offset is the time zone's
     number of seconds away from UTC. if timezone is false, do not
-    append time zone to string."""
+    append time zone to string.
+
+    >>> import locale
+    >>> locale.setlocale(locale.LC_ALL, 'C')
+    'C'
+    >>> datestr((0, False))
+    'Thu Jan 01 00:00:00 1970 +0000'
+    >>> datestr((42, False))
+    'Thu Jan 01 00:00:42 1970 +0000'
+    >>> datestr((-42, False))
+    'Thu Jan 01 00:00:00 1970 +0000'
+    >>> datestr((0x7fffffff, False))
+    'Tue Jan 19 03:14:07 2038 +0000'
+    >>> datestr((-0x7fffffff, False))
+    'Thu Jan 01 00:00:00 1970 +0000'
+    """
     t, tz = date or makedate()
     if t < 0:
         t = 0   # time.gmtime(lt) fails on Windows for lt < -43200


More information about the Mercurial-devel mailing list