Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Specify to_np to True, if the result should be in numpy class.
"""
if not isinstance(datetimes, (list, tuple, np.ndarray)):
raise TypeError('datetime must be in list form')
if isinstance(datetimes[0], numbers.Number):
items = len(datetimes)
elif isinstance(datetimes[0], (list, tuple, np.ndarray)):
items = len(datetimes[0])
else:
print('Unknown input')
return
if items == 7:
return CDFepoch.compute_epoch(datetimes, to_np)
elif items == 10:
return CDFepoch.compute_epoch16(datetimes, to_np)
elif items == 9:
return CDFepoch.compute_tt2000(datetimes, to_np)
else:
print('Unknown input')
return
print('Bad data')
return None
else:
print('Bad data')
return None
if starttime is None:
stime = list()
stime.append(-1.0E31)
stime.append(-1.0E31)
else:
if isinstance(starttime, complex) or isinstance(starttime, np.complex128):
stime = list()
stime.append(starttime.real)
stime.append(starttime.imag)
elif isinstance(starttime, list) or isinstance(starttime, tuple):
sstime = CDFepoch.compute_epoch16(starttime)
stime = list()
stime.append(sstime.real)
stime.append(sstime.imag)
else:
print('Bad start time')
return None
if endtime is not None:
if isinstance(endtime, complex) or isinstance(endtime, np.complex128):
etime = list()
etime.append(endtime.real)
etime.append(endtime.imag)
elif isinstance(endtime, list) or isinstance(endtime, tuple):
eetime = CDFepoch.compute_epoch16(endtime)
etime = list()
etime.append(eetime.real)
etime.append(eetime.imag)
stime.append(starttime.imag)
elif isinstance(starttime, list) or isinstance(starttime, tuple):
sstime = CDFepoch.compute_epoch16(starttime)
stime = list()
stime.append(sstime.real)
stime.append(sstime.imag)
else:
print('Bad start time')
return None
if endtime is not None:
if isinstance(endtime, complex) or isinstance(endtime, np.complex128):
etime = list()
etime.append(endtime.real)
etime.append(endtime.imag)
elif isinstance(endtime, list) or isinstance(endtime, tuple):
eetime = CDFepoch.compute_epoch16(endtime)
etime = list()
etime.append(eetime.real)
etime.append(eetime.imag)
else:
print('Bad start time')
return None
else:
etime = list()
etime.append(1.0E31)
etime.append(1.0E31)
if stime[0] > etime[0] or (stime[0] == etime[0] and stime[1] > etime[1]):
print('Invalid start/end time')
return None
count = len(new_epochs)
epoch16 = []
for x in range(0, count):
mn = int(date[0][4])
ss = int(date[0][5])
if len(date[0]) == 7:
subs = int(date[0][6])
ms = int(subs / 1000000000)
subms = int(subs % 1000000000)
us = int(subms / 1000000)
subus = int(subms % 1000000)
ns = int(subus / 1000)
ps = int(subus % 1000)
else:
ms = int(date[0][6])
us = int(date[0][7])
ns = int(date[0][8])
ps = int(date[0][9])
return CDFepoch.compute_epoch16([yy, mm, dd, hh, mn, ss, ms, us, ns, ps])
elif len(value) == 29 or len(value) == 31:
# CDF_TIME_TT2000
value = value.lower()
if value == '9999-12-31t23:59:59.999999999' or value == '9999-12-31 23:59:59.999.999.999':
return -9223372036854775808
elif value == '0000-01-01t00:00.000000000' or value == '0000-01-01 00:00.000.000.000':
return -9223372036854775807
else:
date = re.findall('(\d+)\-(\d+)\-(\d+)t(\d+)\:(\d+)\:(\d+)\.(\d+)', value)
if not date:
date = re.findall('(\d+)\-(\d+)\-(\d+) (\d+)\:(\d+)\:(\d+)\.(\d+)\.(\d+)\.(\d+)', value)
yy = int(date[0][0])
mm = int(date[0][1])
dd = int(date[0][2])
hh = int(date[0][3])
mn = int(date[0][4])