views:

43

answers:

1

I'm working on making a small ban system, and the snippet below will tell the client how much time of their ban is remaining.

The problem: When you call Bans.timeleft_str(), rather then showing something less then a day, it will show the timestamp + 18 hours.

Snippet: http://pastebin.com/Zumn0tLv

This problem occurs if I change self.length = WEEK, etc. Rather then 7d 00h 00m, it will be 7d 18h 00m.

I originally tested this on my ubuntu vbox, and then tried it on my windows python shell, and still got the same result.

You may need to change self.timestamp to a time in the past.

Thanks in advance.

+1  A: 

time.time, as the docs I just pointed to say, works in UTC (once known as "Greenwich" time, now "universal time coordinate"). mktime, again as said in its docs, takes as argument

9-tuple [...] which expresses the time in local time, not UTC.

strptime may work either way (but you're not supplying a timezone, so it's going to use local time).

So, overall, you're getting deep into timezone confusion;-).

I recommend (as always) that you standardize on UTC (the local timezone of your server can well not be the same as that of its users, after all), e.g. with a %Z directive in the format you pass to strptime and a corresponding timezone of 'UTC' (which is guaranteed to be recognized on all platforms) in the corresponding part of the string you're parsing.

Alex Martelli