Skip to main content
Pydantic Docs
current

Search documentation

Type to search this documentation.

On this pageOverview

Timezone Name

Time zone name validation and serialization module.

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.

Some examples of using the TimeZoneName class:

Python
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
Python

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
Python
def get_timezones() -> set[str]

Determine the timezone provider and return available timezones.

set[str]

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu