tz = pytz.timezone(txt)
if tz is not None:
return tz
- except:
+ except Exception:
pass
# Try dateutil
tz = dateutil.tz.gettz(txt)
if tz is not None:
return tz
- except:
+ except Exception:
pass
# Try constructing an offset in seconds
offset = sign * (hour * 60 * 60) + sign * (minute * 60)
tzoffset = dateutil.tz.tzoffset(txt, offset)
return tzoffset
- except:
+ except Exception:
pass
return None
unit = self._figure_out_date_unit(
ctx.deltaUnit().getText().lower()
)
- except:
+ except Exception:
raise ParseException(f'Invalid Delta +/-: {ctx.getText()}')
else:
self.context['delta_int'] = n
) -> None:
try:
unit = self._figure_out_date_unit(ctx.getText().lower())
- except:
+ except Exception:
raise ParseException(f'Bad delta unit: {ctx.getText()}')
else:
self.context['delta_unit'] = unit
) -> None:
try:
txt = ctx.getText().lower()
- except:
+ except Exception:
raise ParseException(f'Bad next/last: {ctx.getText()}')
if (
'month' in self.context or
ctx.deltaTimeUnit().getText().lower()
)
self.context['time_delta_unit'] = unit
- except:
+ except Exception:
raise ParseException(f'Bad delta unit: {ctx.getText()}')
if 'time_delta_before_after' not in self.context:
raise ParseException(
] = TimeUnit.MINUTES
else:
raise ParseException(f'Bad time fraction {ctx.getText()}')
- except:
+ except Exception:
raise ParseException(f'Bad time fraction {ctx.getText()}')
def exitDeltaBeforeAfter(
) -> None:
try:
txt = ctx.getText().lower()
- except:
+ except Exception:
raise ParseException(f'Bad delta before|after: {ctx.getText()}')
else:
self.context['delta_before_after'] = txt
) -> None:
try:
txt = ctx.getText().lower()
- except:
+ except Exception:
raise ParseException(f'Bad delta before|after: {ctx.getText()}')
else:
self.context['time_delta_before_after'] = txt
self.context['month'] = month
self.context['day'] = 1
self.main_type = DateParser.PARSE_TYPE_BASE_AND_OFFSET_EXPR
- except:
+ except Exception:
raise ParseException(
f'Invalid nthWeekday expression: {ctx.getText()}'
)
def exitNth(self, ctx: dateparse_utilsParser.NthContext) -> None:
try:
i = self._get_int(ctx.getText())
- except:
+ except Exception:
raise ParseException(f'Bad nth expression: {ctx.getText()}')
else:
self.context['nth'] = i
raise ParseException(
f'Bad first|last expression: {ctx.getText()}'
)
- except:
+ except Exception:
raise ParseException(f'Bad first|last expression: {ctx.getText()}')
else:
self.context['nth'] = txt
try:
dow = ctx.getText().lower()[:3]
dow = self.day_name_to_number.get(dow, None)
- except:
+ except Exception:
raise ParseException('Bad day of week')
else:
self.context['dow'] = dow
raise ParseException(
f'Bad dayOfMonth expression: {ctx.getText()}'
)
- except:
+ except Exception:
raise ParseException(f'Bad dayOfMonth expression: {ctx.getText()}')
self.context['day'] = day
raise ParseException(
f'Bad monthName expression: {ctx.getText()}'
)
- except:
+ except Exception:
raise ParseException(f'Bad monthName expression: {ctx.getText()}')
else:
self.context['month'] = month
raise ParseException(
f'Bad monthNumber expression: {ctx.getText()}'
)
- except:
+ except Exception:
raise ParseException(
f'Bad monthNumber expression: {ctx.getText()}'
)
year = self._get_int(ctx.getText())
if year < 1:
raise ParseException(f'Bad year expression: {ctx.getText()}')
- except:
+ except Exception:
raise ParseException(f'Bad year expression: {ctx.getText()}')
else:
self.context['year'] = year
try:
special = ctx.specialDate().getText().lower()
self.context['special'] = special
- except:
+ except Exception:
raise ParseException(
f'Bad specialDate expression: {ctx.specialDate().getText()}'
)
self.context['special_next_last'] = 'next'
elif mod.LAST() is not None:
self.context['special_next_last'] = 'last'
- except:
+ except Exception:
raise ParseException(
f'Bad specialDateNextLast expression: {ctx.getText()}'
)
count = self._get_int(ctx.unsignedInt().getText())
unit = ctx.deltaUnit().getText().lower()
ago_from_now = ctx.AGO_FROM_NOW().getText()
- except:
+ except Exception:
raise ParseException(
f'Bad NFoosFromTodayAgoExpr: {ctx.getText()}'
)
f'Bad This/Next/Last modifier: {mod}'
)
unit = ctx.deltaUnit().getText().lower()
- except:
+ except Exception:
raise ParseException(
f'Bad DeltaRelativeToTodayExpr: {ctx.getText()}'
)
) -> None:
try:
txt = ctx.specialTime().getText().lower()
- except:
+ except Exception:
raise ParseException(
f'Bad special time expression: {ctx.getText()}'
)
try:
tz = ctx.tzExpr().getText()
self.context['tz'] = self._parse_tz(tz)
- except:
+ except Exception:
pass
def exitTwelveHourTimeExpr(
while not hour[-1].isdigit():
hour = hour[:-1]
hour = self._get_int(hour)
- except:
+ except Exception:
raise ParseException(f'Bad hour: {ctx.hour().getText()}')
if hour <= 0 or hour > 12:
raise ParseException(f'Bad hour (out of range): {hour}')
try:
minute = self._get_int(ctx.minute().getText())
- except:
+ except Exception:
minute = 0
if minute < 0 or minute > 59:
raise ParseException(f'Bad minute (out of range): {minute}')
try:
seconds = self._get_int(ctx.second().getText())
- except:
+ except Exception:
seconds = 0
if seconds < 0 or seconds > 59:
raise ParseException(f'Bad second (out of range): {seconds}')
try:
micros = self._get_int(ctx.micros().getText())
- except:
+ except Exception:
micros = 0
if micros < 0 or micros > 1000000:
raise ParseException(f'Bad micros (out of range): {micros}')
try:
ampm = ctx.ampm().getText()
- except:
+ except Exception:
raise ParseException(f'Bad ampm: {ctx.ampm().getText()}')
if hour == 12:
hour = 0
try:
tz = ctx.tzExpr().getText()
self.context['tz'] = self._parse_tz(tz)
- except:
+ except Exception:
pass
def exitTwentyFourHourTimeExpr(
while not hour[-1].isdigit():
hour = hour[:-1]
hour = self._get_int(hour)
- except:
+ except Exception:
raise ParseException(f'Bad hour: {ctx.hour().getText()}')
if hour < 0 or hour > 23:
raise ParseException(f'Bad hour (out of range): {hour}')
try:
minute = self._get_int(ctx.minute().getText())
- except:
+ except Exception:
minute = 0
if minute < 0 or minute > 59:
raise ParseException(f'Bad minute (out of range): {ctx.getText()}')
try:
seconds = self._get_int(ctx.second().getText())
- except:
+ except Exception:
seconds = 0
if seconds < 0 or seconds > 59:
raise ParseException(f'Bad second (out of range): {ctx.getText()}')
try:
micros = self._get_int(ctx.micros().getText())
- except:
+ except Exception:
micros = 0
if micros < 0 or micros >= 1000000:
raise ParseException(f'Bad micros (out of range): {ctx.getText()}')
try:
tz = ctx.tzExpr().getText()
self.context['tz'] = self._parse_tz(tz)
- except:
+ except Exception:
pass