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