Commit 242e8edd authored by nmartensen's avatar nmartensen
Browse files

optimize getting the epoch

--HG--
branch : 3.0
parent 92f444de400a
Pipeline #17902 failed with stage
in 4 minutes and 25 seconds
......@@ -64,12 +64,6 @@ def from_ISO8601(formatted_string):
return dt
def _get_epoch(offset):
if offset == CALENDAR_MAC_1904:
return MAC_EPOCH
return WINDOWS_EPOCH
def to_excel(dt, offset=CALENDAR_WINDOWS_1900):
if isinstance(dt, datetime.time):
return time_to_days(dt)
......@@ -77,7 +71,8 @@ def to_excel(dt, offset=CALENDAR_WINDOWS_1900):
return timedelta_to_days(dt)
if isnan(dt.year): # Pandas supports Not a Date
return
jul = (datetime.datetime(dt.year, dt.month, dt.day) - _get_epoch(offset)).days
epoch = offset == CALENDAR_WINDOWS_1900 and WINDOWS_EPOCH or MAC_EPOCH
jul = (datetime.datetime(dt.year, dt.month, dt.day) - epoch).days
if jul <= 60 and offset == CALENDAR_WINDOWS_1900:
jul -= 1
if hasattr(dt, 'time'):
......@@ -94,7 +89,8 @@ def from_excel(value, offset=CALENDAR_WINDOWS_1900):
return days_to_time(diff)
if 1 < value < 60 and offset == CALENDAR_WINDOWS_1900:
day += 1
return _get_epoch(offset) + datetime.timedelta(days=day) + diff
epoch = offset == CALENDAR_WINDOWS_1900 and WINDOWS_EPOCH or MAC_EPOCH
return epoch + datetime.timedelta(days=day) + diff
class GMT(tzinfo):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment