Date, Time, & Number Formats#
Date & Time Formats#
- quart_babel.format_date(dt: datetime | date | 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
datetimeordateobject 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 byto_user_timezone()). This function only formats the date part of adatetimeobject.The format parameter can either be
'short','medium','long'or'full'(in which cause the language’s default for that setting is used, or the default from theBabel.date_formatsmapping is used) or a format string as documented by Babel. This function is also available in the template context as filter named dateformat.- Parameters:
dt – The date to format. If no date is provided, it will use the current date.
format – The format to use.
rebase – Determines to use user timezone or not.
- 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
datetimeobject 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 byto_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 theBabel.date_formatsmapping 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
datetimeobject 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 byto_user_timezone()). This function formats both date and time.The format parameter can either be
'short','medium','long'or'full'(in which cause the language’s default for that setting is used, or the default from theBabel.date_formatsmapping is used) or a format string as documented by Babel. This function is also available in the template context as filter named timeformat.- Parameters:
time – The time to format. If no time is provided, it will use the current time.
format – The format to use.
rebase – Determines to use user timezone or not.
- quart_babel.format_timedelta(delta: datetime | timedelta | int, granularity: Literal['year', 'month', 'week', 'day', 'hour', 'minute', 'second'] = 'second', threshold: float = 0.85, add_direction: bool = False) 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.
- quart_babel.format_interval(start: datetime | date | time, end: datetime | date | time, skeleton: str | None = None, fuzzy: bool = True, rebase: bool = True) str#
Format an interval between two instants according to the locale’s rules.
- Parameters:
start – First instance.
end – Second instance.
skeleton – The “skeleton format” to use for formatting.
fuzzy – If the skeleton is not found, allow choosing a skeleton that is close enough to it.
rebase – Determines to use user timezone or not. Defaults to
True.
Number Formats#
- quart_babel.format_currency(number: float | Decimal | str, currency: str, format: str | None = None, currency_digits: bool = True, format_type: Literal['name', 'standard', 'accounting'] = 'standard', decimal_quantization: bool = True, group_separator: bool = True) str#
Returns formatted currency value.
- Parameters:
number – the number to format.
currency – the currency code.
format – the format string to use.
currency_digits – use the currency’s natural number of decimal digits.
format_type – the currency format type to use.
decimal_quantization – Truncate and round high-precision numbers. The format pattern.
group_separator – Boolean to switch group separator on/off in a locale’s number format.
- quart_babel.format_decimal(number: float | Decimal | str, format: str | None = None, decimal_quantization: bool = True, group_separator: bool = True) str#
Returns the given decimal number formatted for a specific locale.
- Parameters:
number – The number to format.
format – The format to use.
decimal_quantization – Truncate and round high-precision numbers to the format pattern.
group_separator – Boolean to switch group separator on/off in a locale’s number format.
- quart_babel.format_number(number: float | Decimal | str) str#
Return the given number formatted for the locale.
This function will return
quart_babel.format_decimal()function, since thebabel.numbers.format_number()function is depreciated.- Parameters:
number – The number to format.
- quart_babel.format_percent(number: float | Decimal | str, format: str | None = None, decimal_quantization: bool = True, group_separator: bool = True) str#
Returns a formatted percent value for a specific locale.
- Parameters:
number – The percent number to format
format – The format to use.
decimal_quantization – Truncate and round high-precision numbers to the format pattern.
group_separator – Boolean to switch group separator on/off in a locale’s number format.
- quart_babel.format_scientific(number: float | Decimal | str, format: str | None = None, decimal_quantization: bool = True) str#
Returns a value formatted in scientific notation for a specific locale.
- Parameters:
number – The number to format.
format – The format to use.
decimal_quantization – Truncate and round high-precision numbers to the format pattern.