Timezone#

quart_babel.get_timezone() BaseTzInfo#

Gets the current active timezone from context.

quart_babel.switch_timezone(timezone: str | BaseTzInfo) Generator[None, None, None]#

Temporary switch current timezone for a code block. The previous timezone will be restored after exiting the manager.

Parameters:

timezone – The timezone to switch to.

quart_babel.refresh_timezone(timezone: BaseTzInfo | str | None = None) None#

Refreshes the cached timezone information. This can be used to switch a timezone between a request and if you want the changes to take place immediately, not just with the next request.

Parameters:

timezone – The timezone to set. If none is used it will use the default timezone.

quart_babel.to_user_timezone(dtime: datetime) datetime#

Convert a datetime object to the user’s timezone. This automatically happens on all date formatting unless rebasing is disabled. If you need to convert a datetime.datetime object at any time to the user’s timezone (as returned by get_timezone() this function can be used).

Parameters:

dtime – The datetime object to use the user’s timezone.

quart_babel.to_utc(dtime: datetime) datetime#

Convert a datetime object to UTC and drop tzinfo. This is the opposite operation to to_user_timezone().

Parameters:

dttime (datetime) – The datetime object to convert.