[PATCH 1 of 8] utils: test coverage of makedate
Raphaël Gomès
raphael.gomes at octobus.net
Tue Jul 30 13:51:01 UTC 2024
Patches 4 and 7 don't pass formatting, so I've amended them.
Otherwise the series looks good, I'll merge it soon.
Thanks!
On 7/26/24 9:42 PM, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1688061747 -7200
> # Thu Jun 29 20:02:27 2023 +0200
> # Node ID ac1c2c42edb73b7f7ee2de0950de74616d4bf3fb
> # Parent 278af66e6595ff3baff92416839f7dbc427e24fd
> utils: test coverage of makedate
>
> Explore the scenario from ae04af1ce78d to avoid future regressions.
>
> This was intended to give some coverage of the change in faccec1edc2c.
>
> diff --git a/mercurial/utils/dateutil.py b/mercurial/utils/dateutil.py
> --- a/mercurial/utils/dateutil.py
> +++ b/mercurial/utils/dateutil.py
> @@ -83,7 +83,37 @@ extendeddateformats = defaultdateformats
>
> def makedate(timestamp: Optional[float] = None) -> hgdate:
> """Return a unix timestamp (or the current time) as a (unixtime,
> - offset) tuple based off the local timezone."""
> + offset) tuple based off the local timezone.
> +
> + >>> import os, time
> + >>> os.environ['TZ'] = 'Asia/Novokuznetsk'
> + >>> time.tzset()
> +
> + >>> def dtu(*a):
> + ... return datetime.datetime(*a, tzinfo=datetime.timezone.utc)
> +
> + # Old winter timezone, +7
> + >>> makedate(dtu(2010, 1, 1, 5, 0, 0).timestamp())
> + (1262322000.0, -25200)
> +
> + # Same timezone in summer, +7, so no DST
> + >>> makedate(dtu(2010, 7, 1, 5, 0, 0).timestamp())
> + (1277960400.0, -25200)
> +
> + # Changing to new winter timezone, from +7 to +6 (ae04af1ce78d testcase)
> + >>> makedate(dtu(2010, 10, 30, 20, 0, 0).timestamp() - 1)
> + (1288468799.0, -25200)
> + >>> makedate(dtu(2010, 10, 30, 20, 0, 0).timestamp())
> + (1288468800.0, -21600)
> + >>> makedate(dtu(2011, 1, 1, 5, 0, 0).timestamp())
> + (1293858000.0, -21600)
> +
> + # Introducing DST, changing +6 to +7
> + >>> makedate(dtu(2011, 3, 26, 20, 0, 0).timestamp() - 1)
> + (1301169599.0, -21600)
> + >>> makedate(dtu(2011, 3, 26, 20, 0, 0).timestamp())
> + (1301169600.0, -25200)
> + """
> if timestamp is None:
> timestamp = time.time()
> if timestamp < 0:
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at lists.mercurial-scm.org
> https://lists.mercurial-scm.org/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list