fix: catch out of range dates in conversion to string
@@ -201,9 +201,9 @@ def datestring_from_numeric(numdate):
str
date string YYYY-MM-DD
"""
- if numdate>1900: # python datetime doesn't work for dates before 1900. This can be relaxed to numdate>1 once we drop python 2.7
+ try:
return datetime.datetime.strftime(datetime_from_numeric(numdate), "%Y-%m-%d")
- else:
+ except:
year = int(np.floor(numdate))
dt = datetime_from_numeric(1900+(numdate%1))
return "%04d-%02d-%02d"%(year, dt.month, dt.day)
