×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    May 2008
    Posts
    86

    mktime workaround error

    I've tried both this workaround to fix the mktime bug in PyS60 2.0.0, but I always get an error.

    This is my code:

    Code:
    #Workaround mktime Pys60 2.0.0
    def mktime_fixed(time_tuple):
        return calendar.timegm(time_tuple)+time.timezone
    
    value = '20090824'
    uni_time = datetime(int(value[0:4]), int(value[4:6]), int(value[6:8]), 0, 0, 00)					
    value = time.mktime(uni_time)
    And this is the error:

    Code:
    'TypeError'-("sequence index must be integer, not 'slice'",)-
    ...
    File "newcore\\Lib\\calendar.py", line 604, in timegm\n'
    ...
    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    90

    Re: mktime workaround error

    I doubt that you get that error at least from mktime_fixed, because your function mktime_fixed() is not called... replace time.mktime with mktime_fixed and try again...

    And please, report the line in _your_ code where it fails.

  3. #3
    Regular Contributor
    Join Date
    May 2008
    Posts
    86

    Re: mktime workaround error

    Sorry, since I tried different workaround, I copied from the wrong one.

    Code:
    value = mktime_fixed(uni_time)
    And the error is
    Code:
    'TypeError'-("sequence index must be integer, not 'slice'",)-['  File "e:\\python\\myscript.py", line 256, in parsing
    value = mktime_fixed(uni_time)',
    '  File "e:\\python\\myscript.py",line 323,
    in mktime_fixed return calendar.timegm(time_tuple)+time.timezone',
    '  File "newcore\\Lib\\calendar.py", line 604, in timegm',
    '  File "e:\\python\\myscript.py", line 43, in __getitem__
    def __getitem__(self, key): return self.t[key]']

  4. #4
    Regular Contributor
    Join Date
    May 2008
    Posts
    86

    Re: mktime workaround error

    I actually don't know why, but the problem was in the datetime class:

    Code:
    class datetime(object):
        def __init__(self, *argv):
            self.t = time.struct_time(argv+(0,)*(9-len(argv)))    # append to length 9
        def __getattr__(self, name):
            try:
                i = ['year', 'month', 'day', 'hour', 'minute', 'second', 'weekday'].index(name)
                return self.t[i]
            except:
                return getattr(self.t, name)
        
        def __len__(self): return len(self.t)
        def __getitem__(self, key): return self.t[key]
        def __repr__(self): return repr(self.t)
        
        def now(self=None):
            "Return the current date and time as a datetime."
            now = t.localtime()
            return datetime(now[0],now[1],now[2],now[3],now[4],now[5])
        now = staticmethod(now)
        
        def strftime(self, fmt="%Y-%m-%d %H:%M:%S"):
            return time.strftime(fmt, self.t)
    It works well in PyS60 1.4.5, but it doesn't with 2.0.0.
    Using the time tuple without datetime works fine

    Code:
    value = '20090824'
    value = mktime_fixed(int(value[0:4]), int(value[4:6]), int(value[6:8]), 0, 0, 00)

  5. #5
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: mktime workaround error

    I did the following to avoid several function renamings (mktime to mktime_fix, for instance):

    1) I create a file called mktimefix.py with the following contents:
    Code:
    from time import *
    from calendar import timegm
    
    # fix for mktime bug
    # https://garage.maemo.org/tracker/index.php?func=detail&aid=4453&group_id=854&atid=3201
    mktime = lambda time_tuple: calendar.timegm(time_tuple) + timezone
    When I want to use the module time, the following line is used:

    Code:
    import mktimefix as time
    This way, all functions from time module will be available and time.mktime will be overwritten in mktimefix.py by a working function.
    When this bug is fixed I will only change the includes.

    Marcelo

Similar Threads

  1. mktime(localtime()) quits python!
    By ale152 in forum Python
    Replies: 1
    Last Post: 2010-02-22, 23:14
  2. mktime
    By foosion in forum Python
    Replies: 5
    Last Post: 2009-10-02, 22:26
  3. mktime is taking longer time
    By vittalx in forum Open C/C++
    Replies: 7
    Last Post: 2009-09-25, 15:22
  4. MMAPI workaround?
    By vincenzolembo in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2005-11-09, 13:21
  5. The workaround
    By deeper in forum Browsing and Mark-ups
    Replies: 6
    Last Post: 2003-12-30, 12:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •