For fuzzy parsing, 'a' or 'am' (both valid English words) may erroneously trigger the AM/PM flag. Deal with that here.
(self, hour, ampm, fuzzy)
| 1062 | or token in self.info.UTCZONE)) |
| 1063 | |
| 1064 | def _ampm_valid(self, hour, ampm, fuzzy): |
| 1065 | """ |
| 1066 | For fuzzy parsing, 'a' or 'am' (both valid English words) |
| 1067 | may erroneously trigger the AM/PM flag. Deal with that |
| 1068 | here. |
| 1069 | """ |
| 1070 | val_is_ampm = True |
| 1071 | |
| 1072 | # If there's already an AM/PM flag, this one isn't one. |
| 1073 | if fuzzy and ampm is not None: |
| 1074 | val_is_ampm = False |
| 1075 | |
| 1076 | # If AM/PM is found and hour is not, raise a ValueError |
| 1077 | if hour is None: |
| 1078 | if fuzzy: |
| 1079 | val_is_ampm = False |
| 1080 | else: |
| 1081 | raise ValueError('No hour specified with AM or PM flag.') |
| 1082 | elif not 0 <= hour <= 12: |
| 1083 | # If AM/PM is found, it's a 12 hour clock, so raise |
| 1084 | # an error for invalid range |
| 1085 | if fuzzy: |
| 1086 | val_is_ampm = False |
| 1087 | else: |
| 1088 | raise ValueError('Invalid hour specified for 12-hour clock.') |
| 1089 | |
| 1090 | return val_is_ampm |
| 1091 | |
| 1092 | def _adjust_ampm(self, hour, ampm): |
| 1093 | if hour < 12 and ampm == 1: |