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

John Arbash Meinel john at arbash-meinel.com
Wed Apr 18 16:02:15 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')
> 
> 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))
> 
> 
> [µ]

Oh, the other solution is to use the new "knownFailure" mechanism. Which
is to do:

if sys.platform == 'win32':
  self.assertRaises(ValueError,
                    timestamp.format_patch_date, 0, -5 * 3600)
  self.knownFailure('win32 cannot handle dates before epoch')

self.assertEqual('1969-12-31 19:00:00 -0500',
                 timestamp.format_patch_date(0, -5 * 3600))

It could easily be that this test wants to test how we handle negative
dates. (Just in case someone converts old code that is pre 1970).

We shouldn't avoid the test on platforms where it succeeds. and
"knownFailure" gives us a way to say "yeah, this doesn't work on this
platform".

John
=:->

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

iD8DBQFGJjL3JdeBCYSNAAMRAkZEAKDJF9h+ZXVIGgBsNADJydPQIFTLlQCguM8y
dbDPbpBjr9uLutc4wQC9tsc=
=pEh0
-----END PGP SIGNATURE-----



More information about the bazaar mailing list