Documentation
¶
Index ¶
- Variables
- func Format(d time.Duration) string
- type Duration
- func (duration Duration) MarshalJSON() ([]byte, error)
- func (duration Duration) MarshalText() ([]byte, error)
- func (duration *Duration) String() string
- func (duration *Duration) ToTimeDuration() time.Duration
- func (duration *Duration) UnmarshalJSON(source []byte) error
- func (duration *Duration) UnmarshalText(text []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnexpectedInput is returned when an input in the duration string does not match expectations ErrUnexpectedInput = errors.New("unexpected input") // ErrIncompleteExpr is returned when the expression is incomplete, (e.g. missing unit). ErrIncompleteExpr = errors.New("incomplete expression") )
Functions ¶
func Format ¶ added in v1.1.0
Format formats the given time.Duration into an ISO 8601 duration string (e.g., P1DT6H5M), negative durations are prefixed with a minus sign, for a zero duration "PT0S" is returned. Note that for *Duration's with period values of a month or year that the duration becomes a bit fuzzy since obviously those things vary month to month and year to year.
Types ¶
type Duration ¶
type Duration struct {
Years float64
Months float64
Weeks float64
Days float64
Hours float64
Minutes float64
Seconds float64
Negative bool
}
Duration holds all the smaller units that make up the duration
func FromTimeDuration ¶ added in v1.1.0
FromTimeDuration converts the given time.Duration into duration.Duration. Note that for *Duration's with period values of a month or year that the duration becomes a bit fuzzy since obviously those things vary month to month and year to year.
func Parse ¶
Parse attempts to parse the given duration string into a *Duration, if parsing fails an error is returned instead.
func (Duration) MarshalJSON ¶ added in v1.2.0
MarshalJSON satisfies the Marshaler interface by return a valid JSON string representation of the duration
func (Duration) MarshalText ¶ added in v1.4.0
MarshalText implements encoding.TextMarshaler.
func (*Duration) ToTimeDuration ¶
ToTimeDuration converts the *Duration to the standard library's time.Duration. Note that for *Duration's with period values of a month or year that the duration becomes a bit fuzzy since obviously those things vary month to month and year to year.
func (*Duration) UnmarshalJSON ¶ added in v1.2.0
UnmarshalJSON satisfies the Unmarshaler interface by return a valid JSON string representation of the duration
func (*Duration) UnmarshalText ¶ added in v1.4.0
UnmarshalText implements encoding.TextUnmarshaler.