jinks_widgets.utils¶
Utilities module.
Functions
|
Format a timedelta into a customized string with selected units. |
|
Truncate text by width. |
- jinks_widgets.utils.truncate_text_by_width(text, font, max_width, ending='...', split_space=False)¶
Truncate text by width.
- jinks_widgets.utils.format_timedelta(td, units=None, separator=', ', last_separator=' and ', auto_remove=False)¶
Format a timedelta into a customized string with selected units.
- Parameters:
td (
timedelta) – The timedelta object to formatunits (
List[str] |None) – List of units to include. Valid units: ‘years’, ‘months’, ‘days’, ‘hours’, ‘minutes’, ‘seconds’. If None, uses all non-zero units.separator (
str) – Separator between units (default: “, “)last_separator (
str) – Separator before the last unit (default: “ and “)auto_remove (
bool) – If True, removes units with value 0 when all larger units are also 0 (default: False)
- Return type:
str- Returns:
Formatted string representation of the timedelta
Examples
>>> td = timedelta(days=465, hours=3, minutes=25, seconds=12) >>> format_timedelta(td, ["years", "days", "seconds"]) '1 year, 100 days and 11712 seconds'
>>> format_timedelta(td, ["months", "hours"]) '15 months and 3 hours'