Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPrettyTimeDuration ¶
GetPrettyTimeDuration returns a human-readable string representing the time duration. If shorten is true, the output will be formatted as "1d2h3m4s" instead of "1 day 2 hours 3 minutes 4 seconds".
func RegisterUnit ¶
RegisterUnit registers a new unit with the given value. WARNING: This function is not thread-safe, it's recommended to use it only during the initialization phase of the program. If the unit is already registered, the value will be updated. If the unit contains whitespaces, they will be removed. If the unit is an empty string, nothing will happen.
Types ¶
type Duration ¶
func ParseDuration ¶
ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". If you want to define custom units, you can use the RegisterUnit function. This code is a modified version of time.ParseDuration from the Go standard library. The original code can be found at https://golang.org/src/time/format.go or https://github.com/golang/go/blob/master/src/time/format.go
func ParseDurationWithDefault ¶
ParseDurationWithDefault parses a duration string and returns the duration. If the string is invalid, it will return the default value. If the string is a number without a unit, it will multiply the number by the default value.