duration

package
v0.0.0-...-cf6bbf6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2019 License: Apache-2.0 Imports: 7 Imported by: 6

Documentation

Overview

Package duration provides utilities for dealing with times and durations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FloatToTime

func FloatToTime(secondsSinceEpoch float64) time.Time

FloatToTime converts seconds after Jan 1, 1970 GMT to a time in the system's local time zone.

func FromFloat

func FromFloat(seconds float64) time.Duration

FromFloat converts a value in seconds to a duration

func TimeToFloat

func TimeToFloat(t time.Time) (secondsSinceEpoch float64)

TimeToFloat returns t as seconds after Jan 1, 1970 GMT

func ToFloat

func ToFloat(d time.Duration) (seconds float64)

ToFloat returns d as seconds

Types

type Duration

type Duration struct {
	Seconds     int64
	Nanoseconds int32
}

Duration represents a duration of time For negative durations, both Seconds and Nanoseconds are negative. Internal use only for now.

func New

func New(d time.Duration) Duration

func ParseWithUnit

func ParseWithUnit(str string, unit units.Unit) (dur Duration, err error)

ParseWithUnit takes a string that is a quantity of unit and converts it to a Duration.

func SinceEpoch

func SinceEpoch(now time.Time) Duration

SinceEpoch returns the amount of time since unix epoch

func SinceEpochFloat

func SinceEpochFloat(secondsSinceEpoch float64) Duration

SinceEpochFloat returns the amount of time since unix epoch

func (Duration) AsFloat

func (d Duration) AsFloat() float64

AsFloat returns this duration in seconds.

func (Duration) AsGoDuration

func (d Duration) AsGoDuration() time.Duration

AsGoDuration converts this duration to a go duration

func (Duration) AsGoTime

func (d Duration) AsGoTime() time.Time

AsGoTime Converts this duration to a go time in the system's local time zone.

func (Duration) IsNegative

func (d Duration) IsNegative() bool

IsNegative returns true if this duration is negative.

func (Duration) PrettyFormat

func (d Duration) PrettyFormat() string

PrettyFormat pretty formats this duration. PrettyFormat panics if this duration is negative.

func (Duration) String

func (d Duration) String() string

String shows in seconds

func (Duration) StringUsingUnits

func (d Duration) StringUsingUnits(unit units.Unit) string

StringUsingUnits shows in specified time unit. If unit not a time, shows in seconds.

Jump to

Keyboard shortcuts

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