From df4dff79850443f181ae4a87381bbfee6d325e10 Mon Sep 17 00:00:00 2001 From: Frederik Berlaen Date: Mon, 18 Mar 2019 23:12:27 +0100 Subject: [PATCH] fix utc --- Lib/ufo2fdk/fontInfoData.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Lib/ufo2fdk/fontInfoData.py b/Lib/ufo2fdk/fontInfoData.py index 4ca1a25..6d53ba2 100644 --- a/Lib/ufo2fdk/fontInfoData.py +++ b/Lib/ufo2fdk/fontInfoData.py @@ -14,7 +14,9 @@ from fontTools.misc.py23 import * from fontTools.misc.py23 import PY2, PY3 +import os import time +import calendar import unicodedata from fontTools.misc.textTools import binary2num from fontTools.misc.arrayTools import unionRect @@ -60,21 +62,19 @@ def styleMapFamilyNameFallback(info): # head def dateStringForNow(): - year, month, day, hour, minute, second, weekDay, yearDay, isDST = time.localtime() - year = str(year) - month = str(month).zfill(2) - day = str(day).zfill(2) - hour = str(hour).zfill(2) - minute = str(minute).zfill(2) - second = str(second).zfill(2) - return "%s/%s/%s %s:%s:%s" % (year, month, day, hour, minute, second) + return time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime()) def openTypeHeadCreatedFallback(info): """ - Fallback to now. + Fallback to the environment variable SOURCE_DATE_EPOCH if set, otherwise + now. """ - return dateStringForNow() + if "SOURCE_DATE_EPOCH" in os.environ: + t = datetime.utcfromtimestamp(int(os.environ["SOURCE_DATE_EPOCH"])) + return t.strftime("%Y/%m/%d %H:%M:%S") + else: + return dateStringForNow() # hhea @@ -622,9 +622,9 @@ def intListToNum(intList, start, length): def dateStringToTimeValue(date): try: - t = calendar.timegm(date, "%Y/%m/%d %H:%M:%S") - return long(time.mktime(t)) - except OverflowError: + t = time.strptime(date, "%Y/%m/%d %H:%M:%S") + return long(calendar.timegm(t)) + except ValueError: return long(0)