Duration

package
v0.0.0-...-b0e9511 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(s string) Result.Interface

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

func FromSeconds(sec int64) Interface

FromSeconds is the Duration constructor from a whole number of seconds.

d := Duration.FromSeconds(90) // 1m30s

func Null

func Null() Interface

Null returns the Null-Object variant of Duration.

It satisfies Interface so callers never have to test for a bare nil: it spans zero seconds, its arithmetic returns itself, and IsNull() returns true.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL