+ if txt == 'noon' or txt == 'midday':
+ self.context['hour'] = 12
+ self.context['minute'] = 0
+ self.context['seconds'] = 0
+ self.context['micros'] = 0
+ elif txt == 'midnight':
+ self.context['hour'] = 0
+ self.context['minute'] = 0
+ self.context['seconds'] = 0
+ self.context['micros'] = 0
+ else:
+ raise ParseException(f'Bad special time expression: {txt}')
+
+ try:
+ tz = ctx.tzExpr().getText()
+ self.context['tz'] = self._parse_tz(tz)
+ except Exception:
+ pass
+
+ def exitTwelveHourTimeExpr(
+ self, ctx: dateparse_utilsParser.TwelveHourTimeExprContext
+ ) -> None:
+ try:
+ hour = ctx.hour().getText()
+ while not hour[-1].isdigit():
+ hour = hour[:-1]
+ hour = self._get_int(hour)
+ 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 Exception:
+ minute = 0
+ if minute < 0 or minute > 59:
+ raise ParseException(f'Bad minute (out of range): {minute}')
+ self.context['minute'] = minute
+
+ try:
+ seconds = self._get_int(ctx.second().getText())
+ except Exception:
+ seconds = 0
+ if seconds < 0 or seconds > 59:
+ raise ParseException(f'Bad second (out of range): {seconds}')
+ self.context['seconds'] = seconds
+
+ try:
+ micros = self._get_int(ctx.micros().getText())
+ except Exception:
+ micros = 0
+ if micros < 0 or micros > 1000000:
+ raise ParseException(f'Bad micros (out of range): {micros}')
+ self.context['micros'] = micros
+
+ try:
+ ampm = ctx.ampm().getText()
+ except Exception:
+ raise ParseException(f'Bad ampm: {ctx.ampm().getText()}')
+ if hour == 12:
+ hour = 0
+ if ampm[0] == 'p':
+ hour += 12
+ self.context['hour'] = hour
+
+ try:
+ tz = ctx.tzExpr().getText()
+ self.context['tz'] = self._parse_tz(tz)
+ except Exception:
+ pass
+
+ def exitTwentyFourHourTimeExpr(
+ self, ctx: dateparse_utilsParser.TwentyFourHourTimeExprContext
+ ) -> None:
+ try:
+ hour = ctx.hour().getText()
+ while not hour[-1].isdigit():
+ hour = hour[:-1]
+ hour = self._get_int(hour)
+ 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}')
+ self.context['hour'] = hour
+
+ try:
+ minute = self._get_int(ctx.minute().getText())
+ except Exception:
+ minute = 0
+ if minute < 0 or minute > 59:
+ raise ParseException(f'Bad minute (out of range): {ctx.getText()}')
+ self.context['minute'] = minute
+
+ try:
+ seconds = self._get_int(ctx.second().getText())
+ except Exception:
+ seconds = 0
+ if seconds < 0 or seconds > 59:
+ raise ParseException(f'Bad second (out of range): {ctx.getText()}')
+ self.context['seconds'] = seconds