Documentation ¶
Overview ¶
Package duration provides utilities for interacting with durations.
In contrast to the functions provided by the time package, duration also supports the units Day, Week, Month and Year, but does not provide support for units smaller than a millisecond.
Index ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format formats the passed duration rounded to milliseconds. Individual Values are separated.
For example: '1h 10s'.
func Parse ¶
Parse parses the passed duration. A duration string is a sequence of decimal numbers and units. Both numbers and units may be followed by spaces or tabs.
Valid units are "ms", "s" or "sec", "min", "h" or "hr", "d", "w", "m" or "mon", and "y" or "yr".
If the passed string does not represent a valid duration, Parse will return a *ParseError.
Types ¶
type ParseError ¶
type ParseError struct { // Code is the error code describing further what error occurred. Code ParseErrorCode // Val is the faulty part of the raw duration. // This will be empty, unless the doc of the error code specifically // states it, Val string // RawDuration is the raw duration, as attempted to parse RawDuration string }
ParseError is the error returned by Parse, if the passed duration is faulty.
func (ParseError) Error ¶
func (p ParseError) Error() string
type ParseErrorCode ¶
type ParseErrorCode string
const ( // ErrSyntax indicates a syntax error. ErrSyntax ParseErrorCode = "invalid duration" // ErrSize indicates that the parsed duration exceeds the maximum size of // a duration. ErrSize ParseErrorCode = "the duration is too large" // ErrMissingUnit indicates that a number is missing its unit. ErrMissingUnit ParseErrorCode = "missing unit in duration" // ErrInvalidUnit indicates an unknown unit. // Val will contain the invalid unit. ErrInvalidUnit ParseErrorCode = "invalid unit '%s' in duration" )