Date, Time, & Number Formats#

Date & Time Formats#

quart_babel.format_date(dt: date | datetime | None = None, format: Literal['short', 'medium', 'long', 'full'] | None = None, rebase: bool = True) str#

Return a date formatted according to the given pattern. If no datetime or date object is passed, the current time is assumed. By default, rebasing happens, which causes the object to be converted to the users’s timezone (as returned by to_user_timezone()). This function only formats the date part of a datetime object.

The format parameter can either be 'short', 'medium', 'long' or 'full' (in which case the language’s default for that setting is used, or the default from the Babel.date_formats mapping is used) or a format string as documented by Babel.

This function is also available in the template context as filter named dateformat.

quart_babel.format_datetime(dt: datetime | None = None, format: Literal['short', 'medium', 'long', 'full'] | None = None, rebase: bool = True) str#

Return a date formatted according to the given pattern. If no datetime object is passed, the current time is assumed. By default rebasing happens which causes the object to be converted to the users’s timezone (as returned by to_user_timezone()).

This function formats both date and time. The format parameter can either be 'short', 'medium', 'long' or 'full' (in which case the language’s default for that setting is used, or the default from the Babel.date_formats mapping is used) or a format string as documented by Babel. This function is also available in the template context as filter named datetimeformat.

Parameters:
  • dt – The date to format. If no date is provided, it will use the current date.

  • format – The format to use (Defaults to None).

  • rebase (bool) – Determines to use user timezone or not.

quart_babel.format_time(time: time | datetime | float | None = None, format: Literal['short', 'medium', 'long', 'full'] | None = None, rebase: bool = True) str#

Return a time formatted according to the given pattern. If no datetime object is passed, the current time is assumed. By default, rebasing happens, which causes the object to be converted to the user’s timezone (as returned by to_user_timezone()). This function formats both date and time.

The format parameter can either be 'short', 'medium', 'long' or 'full' (in which case the language’s default for that setting is used, or the default from the Babel.date_formats mapping is used) or a format string as documented by Babel.

This function is also available in the template context as filter named timeformat.

quart_babel.format_timedelta(datetime_or_timedelta: datetime | timedelta | int, granularity: Literal['year', 'month', 'week', 'day', 'hour', 'minute', 'second'] = 'second', add_direction: bool = False, threshold: float = 0.85) str#

Format the elapsed time from the given date to now or the given timedelta.

This function is also available in the template context as filter named timedeltaformat.

Parameters:
  • delta – The time difference to format, or the delta in seconds as an int value.

  • granularity – Determines the smallest unit that should be displayed, the value can be one of “year”, “month”, “week”, “day”, “hour”, “minute” or “second”.

  • threshold – Factor that determines at which point the presentation switches to the nexthigher unit.

  • add_direction – If this flag is set to True the return value will include directional information. For instance a positive timedelta will include the information about it being in the future, a negative will be information about the value being in the past.

Number Formats#

quart_babel.format_currency(number: float | Decimal | str, currency: str, format: str | NumberPattern | None = None, currency_digits: bool = True, format_type: Literal['name', 'standard', 'accounting'] = 'standard') str#

Return the given number formatted for the locale in the request.

Parameters:
  • number – the number to format

  • currency – the currency code

  • format – the format to use

  • currency_digits – use the currency’s number of decimal digits [default: True]

  • format_type – the currency format type to use [default: standard]

Returns:

the formatted number

Return type:

unicode

quart_babel.format_decimal(number: float | Decimal | str, format: str | None = None) str#

Return the given decimal number formatted for the locale in the request.

Parameters:
  • number – the number to format

  • format – the format to use

Returns:

the formatted number

Return type:

unicode

quart_babel.format_number(number: float | Decimal | str) str#

Return the given number formatted for the locale in request

Parameters:

number – the number to format

Returns:

the formatted number

Return type:

unicode

quart_babel.format_percent(number: float | Decimal | str, format: str | NumberPattern | None = None) str#

Return formatted percent value for the locale in the request.

Parameters:
  • number – the number to format

  • format – the format to use

Returns:

the formatted percent number

Return type:

unicode

quart_babel.format_scientific(number: float | Decimal | str, format: str | NumberPattern | None = None) str#

Return value formatted in scientific notation for the locale in request

Parameters:
  • number – the number to format

  • format – the format to use

Returns:

the formatted percent number

Return type:

unicode