[rfc] time.gmtime() does not accept negative numbers on win32

John Arbash Meinel john at arbash-meinel.com
Wed Apr 18 15:52:01 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Belchenko wrote:
> Aaron, annotate says that you is the author of test_timestamp.py.
> Unfortunately one of the test fails on win32 because gmtime()
> does not accept negative seconds (pre-1970 year).
> This error raised both on 2.4 and 2.5, so I assume it's
> a limitation of win32 C runtime.
> 
> Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import time
>>>>> time.gmtime(0)
> (1970, 1, 1, 0, 0, 0, 3, 1, 0)
>>>>> time.gmtime(-1)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ValueError: (22, 'Invalid argument')
> 

I can confirm that python2.4.4 on win32 fails for "time.gmtime(-1)". It
works under python2.4.3 on FC and under python2.5 on cygwin.


> How the best to change this test:
> 
>         self.assertEqual('1969-12-31 19:00:00 -0500',
>             timestamp.format_patch_date(0, -5 * 3600))
> 
> Any non-zero value is OK for you? Per example such change:
> 
>         self.assertEqual('1970-01-01 05:00:00 -0500',
>             timestamp.format_patch_date(5 * 3600, -5 * 3600))
> 
> 
> [µ]


I'm pretty sure that should be:

        self.assertEqual('1970-01-01 00:00:00 -0500',
            timestamp.format_patch_date(5 * 3600, -5 * 3600))

(5 hours after epoch in TZ -5 hours should be midnight).

*I* would be fine with this, as long as there is a corresponding:
        self.assertEqual('1970-01-01 00:00:00 +0000',
            timestamp.format_patch_date(0, 0))


And probably it would be good to have:

        self.assertEqual('1970-01-01 00:05:00 +0000',
            timestamp.format_patch_date(5 * 3600, 0))

At least, that is my thought.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGJjCRJdeBCYSNAAMRArbKAJ9eCLk2ouMUHbEoAntRo/KuWglZjgCfYTGz
fA9iiutSXEvSSt9iJ6hFeKI=
=7KQx
-----END PGP SIGNATURE-----



More information about the bazaar mailing list