Documentation
¶
Index ¶
- Variables
- type Duration
- func (d Duration) Abs() Duration
- func (d Duration) Duration() time.Duration
- func (d Duration) Hours() float64
- func (d Duration) MarshalJSON() ([]byte, error)
- func (d Duration) Microseconds() int64
- func (d Duration) Milliseconds() int64
- func (d Duration) Minutes() float64
- func (d Duration) Nanoseconds() int64
- func (d Duration) Round(m Duration) Duration
- func (d Duration) Seconds() float64
- func (d Duration) String() string
- func (d Duration) Truncate(m Duration) Duration
- func (d *Duration) UnmarshalJSON(b []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidDurationString = fmt.Errorf("invalid duration string") ErrUnsupportedDurationString = fmt.Errorf("unsupported duration string") )
Functions ¶
This section is empty.
Types ¶
type Duration ¶
Duration is a custom duration type which marshals from/to a subset of ISO8601 duration strings.
Specifically, it supports ISO8601 duration strings which can be mapped unambiguously to a Go time.Duration value. This means that strings which contain non-zero values in the month or year fields are forbidden, as these require a point-in-time reference to be unambiguous.
Technically the same is true for days or weeks, as days can be less or more than 24 hours long at daylight savings boundaries. Unfortunately, Django's JSON encoder treats a day as exactly 24 hours long and so we have to support duration strings containing days. Weeks come along for the ride as exactly seven days.
Note that periods of time spanning months or years can be represented and marshaled by this type, but they will be marshaled in terms of weeks, days, etc.
func ParseDuration ¶
func (Duration) Abs ¶
Abs returns the absolute value of d. As a special case, math.MinInt64 is converted to math.MaxInt64.
func (Duration) MarshalJSON ¶
func (Duration) Microseconds ¶
Microseconds returns the duration as an integer microsecond count.
func (Duration) Milliseconds ¶
Milliseconds returns the duration as an integer millisecond count.
func (Duration) Nanoseconds ¶
Nanoseconds returns the duration as an integer nanosecond count.
func (Duration) Round ¶
Round returns the result of rounding d to the nearest multiple of m. The rounding behavior for halfway values is to round away from zero. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, Round returns the maximum (or minimum) duration. If m <= 0, Round returns d unchanged.
func (Duration) Truncate ¶
Truncate returns the result of rounding d toward zero to a multiple of m. If m <= 0, Truncate returns d unchanged.