root/lib/dates.py @ 844
1 |
# Date/time manipulation
|
---|---|
2 |
|
3 |
import datetime |
4 |
import time |
5 |
|
6 |
epoch_year = datetime.datetime.utcfromtimestamp(0).year |
7 |
|
8 |
def timestamp(datetime_): return time.mktime(datetime_.timetuple()) |
9 |
|
10 |
def strftime(format, datetime_): |
11 |
'''datetime.strftime() can't handle years before 1900'''
|
12 |
return (datetime_.replace(year=epoch_year, day=1).strftime( |
13 |
format.replace('%Y', '%%Y').replace('%d', '%%d')) |
14 |
.replace('%Y', str(datetime_.year)).replace('%d', str(datetime_.day))) |