duration

package module
Version: v0.0.0-...-faac084 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2016 License: MIT Imports: 2 Imported by: 2

README

duration

Build Status GoDoc Codebeat badge

Parse standard units of time, based on go's stdlib time implementation.

Documentation

Overview

Package duration contains routines to parse standard units of time.

Index

Constants

This section is empty.

Variables

View Source
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.

Functions

This section is empty.

Types

type Duration

type Duration time.Duration

Duration is a standard unit of time.

func ParseDuration

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

func (d Duration) Days() float64

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

func (Duration) Hours

func (d Duration) Hours() float64

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

func (Duration) Minutes

func (d Duration) Minutes() float64

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

func (Duration) Nanoseconds

func (d Duration) Nanoseconds() int64

Nanoseconds returns the duration as an integer nanosecond count.

func (Duration) Seconds

func (d Duration) Seconds() float64

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

func (Duration) String

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

func (d Duration) Weeks() float64

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

Source Files

Jump to

Keyboard shortcuts

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