Skip to content

Commit f434584

Browse files
authored
Merge pull request #41 from robotools/utc_fix
fix utc
2 parents fc2b823 + df4dff7 commit f434584

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Lib/ufo2fdk/fontInfoData.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
from fontTools.misc.py23 import *
1515
from fontTools.misc.py23 import PY2, PY3
1616

17+
import os
1718
import time
19+
import calendar
1820
import unicodedata
1921
from fontTools.misc.textTools import binary2num
2022
from fontTools.misc.arrayTools import unionRect
@@ -60,21 +62,19 @@ def styleMapFamilyNameFallback(info):
6062
# head
6163

6264
def dateStringForNow():
63-
year, month, day, hour, minute, second, weekDay, yearDay, isDST = time.localtime()
64-
year = str(year)
65-
month = str(month).zfill(2)
66-
day = str(day).zfill(2)
67-
hour = str(hour).zfill(2)
68-
minute = str(minute).zfill(2)
69-
second = str(second).zfill(2)
70-
return "%s/%s/%s %s:%s:%s" % (year, month, day, hour, minute, second)
65+
return time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime())
7166

7267

7368
def openTypeHeadCreatedFallback(info):
7469
"""
75-
Fallback to now.
70+
Fallback to the environment variable SOURCE_DATE_EPOCH if set, otherwise
71+
now.
7672
"""
77-
return dateStringForNow()
73+
if "SOURCE_DATE_EPOCH" in os.environ:
74+
t = datetime.utcfromtimestamp(int(os.environ["SOURCE_DATE_EPOCH"]))
75+
return t.strftime("%Y/%m/%d %H:%M:%S")
76+
else:
77+
return dateStringForNow()
7878

7979

8080
# hhea
@@ -622,9 +622,9 @@ def intListToNum(intList, start, length):
622622

623623
def dateStringToTimeValue(date):
624624
try:
625-
t = calendar.timegm(date, "%Y/%m/%d %H:%M:%S")
626-
return long(time.mktime(t))
627-
except OverflowError:
625+
t = time.strptime(date, "%Y/%m/%d %H:%M:%S")
626+
return long(calendar.timegm(t))
627+
except ValueError:
628628
return long(0)
629629

630630

0 commit comments

Comments
 (0)