Skip to content

Commit

Permalink
✅ Implement tzinfo.fromutc method for TzInfo in pydantic-core
Browse files Browse the repository at this point in the history
  • Loading branch information
lig committed Aug 7, 2023
1 parent adc657a commit 6206fc0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_datetime.py
Expand Up @@ -595,3 +595,17 @@ def test_invalid_annotated_type(annotation):

class Model(BaseModel):
foo: Annotated[str, annotation()]


def test_tzinfo_could_be_reused():
class Model(BaseModel):
value: datetime

m = Model(value='2015-10-21T15:28:00.000000+01:00')
assert m.model_dump_json() == '{"value":"2015-10-21T15:28:00+01:00"}'

target = datetime(1955, 11, 12, 14, 38, tzinfo=m.value.tzinfo)
assert target == datetime(1955, 11, 12, 14, 38, tzinfo=timezone(timedelta(hours=1)))

now = datetime.now(tz=m.value.tzinfo)
assert isinstance(now, datetime)

0 comments on commit 6206fc0

Please sign in to comment.