Skip to content

String Formatting Functions

Functions for formatting numerical values into human-readable strings.

Time Formatting

format_time_string builtin

format_time_string(seconds: float, short: bool = False) -> str

Format a time duration in seconds to a human-readable string.

Converts a duration in seconds to either a long format (e.g., "6 minutes and 2.00 seconds") or a short format (e.g., "6m 2s").

Parameters:

Name Type Description Default
seconds float

Time duration in seconds

required
short bool

If True, use short format; otherwise use long format (default: False)

False

Returns:

Name Type Description
str str

Human-readable string representation of the time duration

Example
import brahe as bh

# Long format (default)
print(bh.format_time_string(90.0))
# Output: "1 minutes and 30.00 seconds"

print(bh.format_time_string(3665.0))
# Output: "1 hours, 1 minutes, and 5.00 seconds"

# Short format
print(bh.format_time_string(90.0, short=True))
# Output: "1m 30s"

print(bh.format_time_string(3665.0, short=True))
# Output: "1h 1m 5s"