1446 tz = time.altzone |
1446 tz = time.altzone |
1447 else: |
1447 else: |
1448 tz = time.timezone |
1448 tz = time.timezone |
1449 return time.mktime(lt), tz |
1449 return time.mktime(lt), tz |
1450 |
1450 |
1451 def datestr(date=None, format='%a %b %d %H:%M:%S %Y', timezone=True): |
1451 def datestr(date=None, format='%a %b %d %H:%M:%S %Y', timezone=True, timezone_format=" %+03d%02d"): |
1452 """represent a (unixtime, offset) tuple as a localized time. |
1452 """represent a (unixtime, offset) tuple as a localized time. |
1453 unixtime is seconds since the epoch, and offset is the time zone's |
1453 unixtime is seconds since the epoch, and offset is the time zone's |
1454 number of seconds away from UTC. if timezone is false, do not |
1454 number of seconds away from UTC. if timezone is false, do not |
1455 append time zone to string.""" |
1455 append time zone to string.""" |
1456 t, tz = date or makedate() |
1456 t, tz = date or makedate() |
1457 s = time.strftime(format, time.gmtime(float(t) - tz)) |
1457 s = time.strftime(format, time.gmtime(float(t) - tz)) |
1458 if timezone: |
1458 if timezone: |
1459 s += " %+03d%02d" % (-tz / 3600, ((-tz % 3600) / 60)) |
1459 s += timezone_format % (-tz / 3600, ((-tz % 3600) / 60)) |
1460 return s |
1460 return s |
1461 |
1461 |
1462 def strdate(string, format, defaults): |
1462 def strdate(string, format, defaults): |
1463 """parse a localized time string and return a (unixtime, offset) tuple. |
1463 """parse a localized time string and return a (unixtime, offset) tuple. |
1464 if the string cannot be parsed, ValueError is raised.""" |
1464 if the string cannot be parsed, ValueError is raised.""" |