Parse a date/int/float/string and return a datetime.date. Raise ValueError if the input is well formatted but not a valid date. Raise ValueError if the input isn't well formatted.
(value: Union[date, StrBytesIntFloat])
| 103 | |
| 104 | |
| 105 | def parse_date(value: Union[date, StrBytesIntFloat]) -> date: |
| 106 | """ |
| 107 | Parse a date/int/float/string and return a datetime.date. |
| 108 | |
| 109 | Raise ValueError if the input is well formatted but not a valid date. |
| 110 | Raise ValueError if the input isn't well formatted. |
| 111 | """ |
| 112 | if isinstance(value, date): |
| 113 | if isinstance(value, datetime): |
| 114 | return value.date() |
| 115 | else: |
| 116 | return value |
| 117 | |
| 118 | number = get_numeric(value, 'date') |
| 119 | if number is not None: |
| 120 | return from_unix_seconds(number).date() |
| 121 | |
| 122 | if isinstance(value, bytes): |
| 123 | value = value.decode() |
| 124 | |
| 125 | match = date_re.match(value) # type: ignore |
| 126 | if match is None: |
| 127 | raise errors.DateError() |
| 128 | |
| 129 | kw = {k: int(v) for k, v in match.groupdict().items()} |
| 130 | |
| 131 | try: |
| 132 | return date(**kw) |
| 133 | except ValueError: |
| 134 | raise errors.DateError() |
| 135 | |
| 136 | |
| 137 | def parse_time(value: Union[time, StrBytesIntFloat]) -> time: |
nothing calls this directly
no test coverage detected