#7073 closed defect (fixed)
Times and dates are not imported properly
Reported by: | Freek Wielstra | Owned by: | Anton Stroganov |
---|---|---|---|
Priority: | normal | Component: | MantisImportScript |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.12 |
Description
In the latest version of the mantis2trac.py script (the one linked to from the Trac site, i.e. the latest trunk version (I assume)), times and dates are not retrieved and inserted properly.
The existing version uses time.strftime('%S'), however this will, according to the 2.6.5 documentation of Pyhton, only return the seconds (i.e. a two-digit number at best). I'm thinking that at one time this method returned the amount of seconds since the epoch.
I've spent some time trying to figure out how to fix this, so first I converted the date to a UNIX timestamp (where I assumed this was the format used - note that I was wrong) using
time.mktime(sometime.timetuple())
Note that time. in this case refers to the Python time library, and that all time variables need to be renamed (both in the array keys as the method parameters) to avoid naming collisions.
This however didn't solve the problem - it creates a 32 bits int stamp, and (it seems) Python uses 64 bits. I couldn't find any good conversion scripts, and I'm nowhere near knowledgeable with Python, so I used the following code snippet at all points where time is used (I could find it in tickets, ticket changes, comments, and attachments):
changetime = time.mktime(changetime.timetuple()) changetime = int(changetime) changetime = str(changetime) changetime = changetime + '000000' changetime = long(changetime)
Or, if you like the one-lined version which I didn't try:
changetime = long(str(int(time.mktime(changetime.timetuple())) + '000000')
I'm just posting that here in case there's other people like me that spend a day and a half trying to get this to work.
Thank you for the report, I think the latest version with changes from John Líchovnik should take care of it (it uses
time.mktime(time2.timetuple())+1e-6*time2.microsecond
to convert timestamps.