Timezone Name
Time zone name validation and serialization module.
TimeZoneName ¶
Bases: str
TimeZoneName is a custom string subclass for validating and serializing timezone names.
The TimeZoneName class uses the IANA Time Zone Database for validation. It supports both strict and non-strict modes for timezone name validation.
Examples:¶
Some examples of using the TimeZoneName class:
Normal usage:¶
from pydantic_extra_types.timezone_name import TimeZoneName
from pydantic import BaseModel
class Location(BaseModel):
city: str
timezone: TimeZoneName
loc = Location(city="New York", timezone="America/New_York")
print(loc.timezone)
>> America/New_York
Non-strict mode:¶
from pydantic_extra_types.timezone_name import TimeZoneName, timezone_name_settings
@timezone_name_settings(strict=False)
class TZNonStrict(TimeZoneName):
pass
tz = TZNonStrict("america/new_york")
print(tz)
>> america/new_york
get_timezones ¶
Determine the timezone provider and return available timezones.
Source code in .venv/lib/python3.10/site-packages/pydantic_extra_types/timezone_name.py
45 46 47 48 49 50 51 52 53 54 55 56 |
|