Advanced search
Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Python for S60
Summary Tracker News SCM Files

Bugs: Browse | Download .csv

[#4453] time.mktime() crashes interpreter

Please login

State:
Open
Date:
2009-08-29 04:06
Priority:
3
Submitted By:
Russell Stuart (rstuart4133)
Assigned To:
Nobody (None)
Summary:
time.mktime() crashes interpreter

Detailed description
Run using the bluetooth console, on a 6110:

Python 2.5.4 (r254:67916, Aug  3 2009, 04:19:59) [C] on symbian_s60
Type "copyright", "credits" or "license" for more information.
Type "commands" to see the commands available in this simple line editor.
>>> import time
>>> time.mktime((2009, 8, 29, 3, 17, 12, 5, 241, 0))
Disconnected
            cu: Got hangup signal

Same thing works fine on 1.9.6.

Followup

Message
Date: 2010-03-04 04:56
Sender: Russell Stuart

Still a problem in 2.0.0.

A number of work arounds have been given above.  Here is another
one.  Put this in your startup code, and the problem will go
away everywhere:

    def mktime(tuple, _m=(0,31,61,92,122,153,184,214,245,275,306,
337)):
      year, month, day, hour, minute, second = tuple[:6]
      year -= month <= 2 and 1905 or 1904
      days = (year//4)*1461 + (year%4)*365 + _m[(month+9) % 12]
+ day - 24048
      seconds = (((days * 24) + hour) * 60 + minute) * 60
+ second
      if tuple[8] and time.daylight:
	return seconds - time.altzone
      return seconds - time.timezone
    time.mktime = mktime

It handle daylight savings time.  Any of the above solutions
will work with the same "time.mktime = mktime" trick,
of course.
Date: 2010-02-21 12:58
Sender: Marcelo Barros

As I did not want to change all calls to mktime(), I decided
to change only the import, adding a fix file called mktimefix.py:

#---------- mktimefix.py --------------
from time import *
from calendar import timegm
# fix for mktime bug
mktime = lambda time_tuple: calendar.timegm(time_tuple)
+ timezone
#---------- mktimefix.py --------------

Thus, I changed all imports to time as below:

# instead
import time
# use
import mktimefix as time

Date: 2009-11-24 22:15
Sender: Leonid Shevtsov

Actually I found a workaround:

import calendar

def mktime_fixed(time_tuple):
  return calendar.timegm(time_tuple)+time.timezone

Tested on 5800XM. The only difference is that it returns an integer,
not a float.
Date: 2009-11-24 21:57
Sender: Leonid Shevtsov

Bug confirmed on 5800XM.
Date: 2009-10-02 10:55
Sender: paul foosion

Same here.  It's broken in both the interpreter and when run
from a script in 1.9.7.
Date: 2009-09-10 20:26
Sender: Marcelo Barros

Same here.

import time
dt = time.gmtime()
mt = time.mktime(dt) # crash

Attached Files:

Name Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item


Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment