Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse builds a Duration from a Go duration string (see time.ParseDuration).
On success the Result carries the Duration as its payload; when the input is malformed the Result carries an Error instead — the operation never panics and never returns nil.
r := Duration.Parse("1h30m")
if r.HasError() {
// r.Error().Message()
}
Types ¶
type Interface ¶
type Interface interface {
ToSeconds() int64
ToGoString() string
Add(Interface) Interface
Sub(Interface) Interface
Equal(Interface) bool
IsNull() bool
}
Duration is a composite over a span of time, wrapping Go's stdlib time.Duration.
It follows Composition-Oriented Programming: it is interface-first, its fallible constructor (Parse) returns a Result.Interface so that a malformed input is a value rather than a panic, and it ships a Null-Object variant so callers never have to test for a bare nil.
func FromSeconds ¶
FromSeconds is the Duration constructor from a whole number of seconds.
d := Duration.FromSeconds(90) // 1m30s