Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def to_excel(dt, offset=CALENDAR_WINDOWS_1900):
jul = sum(gcal2jd(dt.year, dt.month, dt.day)) - offset
if jul <= 60 and offset == CALENDAR_WINDOWS_1900:
jul -= 1
if hasattr(dt, 'time'):
jul += time_to_days(dt)
return jul
if units:
units = units.lower().strip()
if long_name:
units = long_name.lower().strip()
units = units or long_name
if not units or units != 'time in julian days':
return ds
ds = ds.copy()
# Decode JD time
# noinspection PyTypeChecker
tuples = [jd2gcal(x, 0) for x in ds.time.values]
# Replace JD time with datetime
ds['time'] = [datetime(x[0], x[1], x[2]) for x in tuples]
# Adjust attributes
ds.time.attrs['long_name'] = 'time'
ds.time.attrs['calendar'] = 'standard'
return ds