|
3 | 3 | from typing import Optional, Sequence, Union |
4 | 4 |
|
5 | 5 | from duffel_api.models import Aircraft, Airline, Airport, LoyaltyProgrammeAccount, Place |
6 | | -from duffel_api.utils import get_and_transform |
| 6 | +from duffel_api.utils import get_and_transform, parse_datetime |
7 | 7 |
|
8 | 8 |
|
9 | 9 | @dataclass |
@@ -200,8 +200,8 @@ def from_json(cls, json: dict): |
200 | 200 | return cls( |
201 | 201 | id=json["id"], |
202 | 202 | aircraft=get_and_transform(json, "aircraft", Aircraft.from_json), |
203 | | - arriving_at=datetime.strptime(json["arriving_at"], "%Y-%m-%dT%H:%M:%S"), |
204 | | - departing_at=datetime.strptime(json["departing_at"], "%Y-%m-%dT%H:%M:%S"), |
| 203 | + arriving_at=parse_datetime(json["arriving_at"]), |
| 204 | + departing_at=parse_datetime(json["departing_at"]), |
205 | 205 | destination=Airport.from_json(json["destination"]), |
206 | 206 | destination_terminal=json.get("destination_terminal"), |
207 | 207 | origin=Airport.from_json(json["origin"]), |
@@ -420,12 +420,12 @@ def from_json(cls, json: dict): |
420 | 420 | payment_required_by=get_and_transform( |
421 | 421 | json, |
422 | 422 | "payment_required_by", |
423 | | - lambda value: datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ"), |
| 423 | + parse_datetime, |
424 | 424 | ), |
425 | 425 | price_guarantee_expires_at=get_and_transform( |
426 | 426 | json, |
427 | 427 | "price_guarantee_expires_at", |
428 | | - lambda value: datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ"), |
| 428 | + parse_datetime, |
429 | 429 | ), |
430 | 430 | ) |
431 | 431 |
|
@@ -529,14 +529,14 @@ def from_json(cls, json: dict): |
529 | 529 | cancelled_at=get_and_transform( |
530 | 530 | json, |
531 | 531 | "cancelled_at", |
532 | | - lambda value: datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%fZ"), |
| 532 | + parse_datetime, |
533 | 533 | ), |
534 | 534 | content=json["content"], |
535 | | - created_at=datetime.strptime(json["created_at"], "%Y-%m-%dT%H:%M:%S.%fZ"), |
| 535 | + created_at=parse_datetime(json["created_at"]), |
536 | 536 | synced_at=get_and_transform( |
537 | 537 | json, |
538 | 538 | "synced_at", |
539 | | - lambda value: datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ"), |
| 539 | + parse_datetime, |
540 | 540 | ), |
541 | 541 | documents=get_and_transform( |
542 | 542 | json, |
|
0 commit comments