bug in time.strftime on linux??? 
Author Message
 bug in time.strftime on linux???

Quote:

> The following line of code works in python 1.5.1 on Win32, and it worked on
> linux until recently: ( August 5, 1998 is a Wednesday )

> Python 1.5.1 (#1, Jun 26 1998, 13:27:37)  [GCC 2.7.2.3] on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import time
> >>> time.strftime('%a', (1998, 8, 5, 0, 0, 0, 0, 0, 0))
> 'Mon'

> It also works properly on Solaris 2.6:
> Python 1.5.1 (#1, Apr 14 1998, 09:12:19) [C] on sunos5
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import time
> >>> time.strftime('%a', (1998, 8, 5, 0, 0, 0, 0, 0, 0))
> 'Wed'

> The Linux box is running RedHat 5.1.  Any ideas?

The code of strftime() says:

#ifdef HAVE_MKTIME
        /* This call is only there to adjust the numbers to be within
           bounds.  When we don't have mktime(), we say the caller is
           responsible for that... */
        (void) mktime(&buf);
#endif

Note that it is not defined whether mktime() may change buffer
contents or not. It does so obviously on Solaris. The weekday
is calculated from the given values otherwise (giving Monday
since you passed 0 as day of week).

I still think that the mktime() call should be removed altogether,
but...

For an alternative have a look at mxDateTime:

        http://www.*-*-*.com/ ~lemburg/mxDateTime.html

--
Marc-Andre Lemburg                               Y2000: 508 days left
---------------------------------------------------------------------
          : Python Pages >>> http://www.*-*-*.com/ ~lemburg/  :
           ---------------------------------------------------------



Fri, 26 Jan 2001 03:00:00 GMT  
 bug in time.strftime on linux???

Quote:

> The following line of code works in Python 1.5.1 on Win32, and it worked on
> linux until recently: ( August 5, 1998 is a Wednesday )

> Python 1.5.1 (#1, Jun 26 1998, 13:27:37)  [GCC 2.7.2.3] on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import time
> >>> time.strftime('%a', (1998, 8, 5, 0, 0, 0, 0, 0, 0))
> 'Mon'

> It also works properly on Solaris 2.6:
> Python 1.5.1 (#1, Apr 14 1998, 09:12:19) [C] on sunos5
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import time
> >>> time.strftime('%a', (1998, 8, 5, 0, 0, 0, 0, 0, 0))
> 'Wed'

Python 1.5.1 (#2, Jul 27 1998, 12:58:10)  [GCC 2.7.2.1] on freebsd2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam

Quote:
>>> import time
>>> time.strftime('%a', (1998, 8, 5, 0, 0, 0, 0, 0, 0))
'Mon'
>>> time.strftime('%a', (1998, 8, 6, 0, 0, 0, 0, 0, 0))
'Mon'
>>> time.strftime('%a', (1998, 9, 6, 0, 0, 0, 0, 0, 0))
'Mon'

It's always Monday on the Information Superhighway? ;-)

tg



Fri, 26 Jan 2001 03:00:00 GMT  
 bug in time.strftime on linux???

Quote:


> > The following line of code works in Python 1.5.1 on Win32, and it worked on
> > linux until recently: ( August 5, 1998 is a Wednesday )

> > Python 1.5.1 (#1, Jun 26 1998, 13:27:37)  [GCC 2.7.2.3] on linux2
[...]
> > It also works properly on Solaris 2.6:
> > Python 1.5.1 (#1, Apr 14 1998, 09:12:19) [C] on sunos5
[...]
> I still think that the mktime() call should be removed altogether,
> but...

"""
     * A call to mktime() inserted in the time module has bad effects
       when formatting non-local times. Patch file: timemodule.1.txt.
       (27-Apr-98)
"""

(http://www.python.org/1.5/patches-1.5.1/timemodule.1.txt).

If I leave this patch out all is fine:

Python 1.5.1 (#1, Aug 10 1998, 15:44:22)  [GCC 2.7.2.1] on freebsd2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam

Quote:
>>> import time
>>> time.strftime('%a', (1998, 8, 5, 0, 0, 0, 0, 0, 0))
'Wed'

tg


Fri, 26 Jan 2001 03:00:00 GMT  
 bug in time.strftime on linux???

Quote:
> The following line of code works in Python 1.5.1 on Win32, and it worked on
> linux until recently: ( August 5, 1998 is a Wednesday )

> Python 1.5.1 (#1, Jun 26 1998, 13:27:37)  [GCC 2.7.2.3] on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import time
> >>> time.strftime('%a', (1998, 8, 5, 0, 0, 0, 0, 0, 0))
> 'Mon'

> It also works properly on Solaris 2.6:
> Python 1.5.1 (#1, Apr 14 1998, 09:12:19) [C] on sunos5
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import time
> >>> time.strftime('%a', (1998, 8, 5, 0, 0, 0, 0, 0, 0))
> 'Wed'

> The Linux box is running RedHat 5.1.  Any ideas?

It's not supposed to work, since you don't give the weekday in the
tuple.  To get it to work, you should call mktime and localtime to
fill out the missing values in the tuple:

Quote:
>>> t = (1998, 8, 5, 0, 0, 0, 0, 0, 0)
>>> time.strftime('%a', time.localtime(time.mktime(t)))
'Wed'

The reason that it works for you on Solaris but not on Linux is that
your Linux version has a patch (see the patch page,
http://www.python.org/1.5/patches-1.5.1/; search for mktime) while
your Solaris version is unpatched.

The patch *removes* a call to mktime() in time.strftime() that
shouldn't be there.  You might argue that it should be there because
it does what you want; unfortunately, other people use strftime() to
format non-local times and in that case it is possible for mktime() to
change the values they pass in!

--Guido van Rossum (home page: http://www.python.org/~guido/)



Fri, 26 Jan 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. time.strftime BUG?

2. unix time and strftime

3. time.strftime()

4. Bug in time.c (was Time.times problems)

5. time and scheduling (was: bug report: [ #447945 ] time.time() is not non-decreasing)

6. bug report: [ #447945 ] time.time() is not non-decreasing

7. bug report: [ #447945 ] time.time() is not non-decreasing

8. linux has bugs - all software has bug i think

9. GAWK: strftime("%z") and portability (which version of strftime is used in compile?)

10. BUGS, BUGS, BUGS, BUGS, C4 BUGS

11. Localized strftime() output

12. strftime * date calculations

 

 
Powered by phpBB® Forum Software