Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_date(self,typeofdate):
daybefore = datetime.datetime.now(LocalTZ())
if 'recurrence' in self.keys():
rset = dateutil.rrule.rruleset()
for el in self['recurrence']:
if el.find('DTSTART') == -1:
if 'date' in self[typeofdate].keys():
dtstart = self[typeofdate]['date']+'T00:00:00'+ get_utc_offset(daybefore)
print(self[typeofdate]['date'])
elif 'dateTime' in self[typeofdate].keys():
dtstart = self[typeofdate]['dateTime']
print(self[typeofdate]['dateTime'])
print(1,dtstart)
dtstart = rfc3339.parse_datetime(dtstart)
print(2,dtstart)
if el.find('UNTIL') != -1:
elements = el.split(';')
ans = ''
for element in elements:
if element.startswith('UNTIL='):
s,e=element.split("=")
if len(e) == 8:
e += 'T000000'+ get_utc_offset(daybefore).replace(':','')
elif len(e) == 17:
e += get_utc_offset(daybefore)
element = s+'='+e
ans += element+';'
if ans.endswith(';'):
ans = ans[:-1]
el = ans
def format_datetime(date_string):
dt = rfc3339.parse_datetime(date_string)
return dt.strftime("%A, %B %d, %Y")
except Exception as e:
print(e)
try:
ans = rset.after(daybefore,inc=True)
except Exception as e:
print(e)
ans = None
if ans is not None:
return ans
if typeofdate in self.keys():
if 'date' in self[typeofdate].keys():
dtstart = self[typeofdate]['date']+'T00:00:00'+ get_utc_offset(daybefore)
return rfc3339.parse_datetime(dtstart)
elif 'dateTime' in self[typeofdate].keys():
dtstart = self[typeofdate]['dateTime']
return rfc3339.parse_datetime(dtstart)
return None
try:
rrule = dateutil.rrule.rrulestr(el)
rset.rrule(rrule)
except Exception as e:
print(e)
try:
ans = rset.after(daybefore,inc=True)
except Exception as e:
print(e)
ans = None
if ans is not None:
return ans
if typeofdate in self.keys():
if 'date' in self[typeofdate].keys():
dtstart = self[typeofdate]['date']+'T00:00:00'+ get_utc_offset(daybefore)
return rfc3339.parse_datetime(dtstart)
elif 'dateTime' in self[typeofdate].keys():
dtstart = self[typeofdate]['dateTime']
return rfc3339.parse_datetime(dtstart)
return None
def datetime_validator(value, schema_name=None):
msg = make_validation_error_msg(
value,
"JSON datetime value. Hint: use datetime.datetime.isoformat(), instead of datetime.datetime",
schema_name,
)
try:
pvalue = rfc3339.parse_datetime(value)
# pvalue = datetime.datetime.fromisoformat(value)
except Exception as e:
raise ValidationError(str(e), msg)
if not isinstance(pvalue, datetime.datetime):
raise ValidationError(msg)