EXPAND ALL
  • Home

px.format_duration

Convert a duration in nanoseconds to a duration string.

Convert an integer in nanoseconds (-3,000,000,000) to a duration string ("-5m") while preserving the sign. This function converts to whole milliseconds, seconds, minutes, hours or days. This means it will round down to the nearest whole number time unit.

Arguments

NameTypeDescription
durationint64The duration in nanoseconds.

Returns

string: The string representing the human readable duration (i.e. -5m, -10h).

Examples

# duration = "-5m"
duration = px.format_duration(-5 * 60 * 1000 * 1000 * 1000)
# duration = "5m" duration is rounded down to nearest whole minute.
duration = px.parse_duration(-5 * 60 * 1000 * 1000 * 1000 + 5)
# duration = "-5h"
duration = px.format_duration(-5 * 60 * 60 * 1000 * 1000 * 1000)

This site uses cookies to provide you with a better user experience. By using Pixie, you consent to our use of cookies.