duration: maze.io/x/duration Index | Files

package duration

import "maze.io/x/duration"

Package duration contains routines to parse standard units of time.

Index

Package Files

duration.go

Variables

var (
    Nanosecond  = Duration(time.Nanosecond)
    Microsecond = Duration(time.Microsecond)
    Millisecond = Duration(time.Millisecond)
    Second      = Duration(time.Second)
    Minute      = Duration(time.Minute)
    Hour        = Duration(time.Hour)
    Day         = Hour * 24
    Week        = Day * 7
    Fortnight   = Week * 2
    Month       = Day * 30    // Approximation
    Year        = Day * 365   // Approximation
    Decade      = Year * 10   // Approximation
    Century     = Year * 100  // Approximation
    Millennium  = Year * 1000 // Approximation
)

Standard unit of time.

type Duration Uses

type Duration time.Duration

Duration is a standard unit of time.

func ParseDuration Uses

func ParseDuration(s string) (Duration, error)

ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d", "w", "y".

func (Duration) Days Uses

func (d Duration) Days() float64

Days returns the duration as a floating point number of days.

func (Duration) Hours Uses

func (d Duration) Hours() float64

Hours returns the duration as a floating point number of hours.

func (Duration) Minutes Uses

func (d Duration) Minutes() float64

Minutes returns the duration as a floating point number of minutes.

func (Duration) Nanoseconds Uses

func (d Duration) Nanoseconds() int64

Nanoseconds returns the duration as an integer nanosecond count.

func (Duration) Seconds Uses

func (d Duration) Seconds() float64

Seconds returns the duration as a floating point number of seconds.

func (Duration) String Uses

func (d Duration) String() string

String returns a string representing the duration in the form "3d1h3m". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. Duration more than a day or more than a week lose granularity and are truncated to resp. days-hours-minutes and weeks-days-hours. The zero duration formats as 0s.

func (Duration) Weeks Uses

func (d Duration) Weeks() float64

Weeks returns the duration as a floating point number of days.

Package duration imports 2 packages (graph). Updated 2019-08-19. Refresh now. Tools for package owners.