Parse the string datetime. This supports the subset of ISO8601 used by xsd:dateTime, but is lenient with what is accepted, handling most reasonable syntax. @param value: A datetime string. @type value: str @return: A datetime object. @rtype: B{dateti
(value)
| 184 | |
| 185 | @staticmethod |
| 186 | def parse(value): |
| 187 | """Parse the string datetime. |
| 188 | |
| 189 | This supports the subset of ISO8601 used by xsd:dateTime, but is |
| 190 | lenient with what is accepted, handling most reasonable syntax. |
| 191 | |
| 192 | @param value: A datetime string. |
| 193 | @type value: str |
| 194 | @return: A datetime object. |
| 195 | @rtype: B{datetime}.I{datetime} |
| 196 | |
| 197 | """ |
| 198 | match_result = RE_DATETIME.match(value) |
| 199 | if match_result is None: |
| 200 | raise ValueError('date data has invalid format "%s"' % (value, )) |
| 201 | |
| 202 | date = date_from_match(match_result) |
| 203 | time = time_from_match(match_result) |
| 204 | tzinfo = tzinfo_from_match(match_result) |
| 205 | |
| 206 | value = datetime.datetime.combine(date, time) |
| 207 | value = value.replace(tzinfo=tzinfo) |
| 208 | |
| 209 | return value |
| 210 | |
| 211 | def __str__(self): |
| 212 | return self.value.isoformat() |
no test coverage detected