time

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package time implements time stuff.

Index

Constants

View Source
const (
	// Day duration
	Day = 24 * time.Hour

	// Week duration
	Week = 7 * Day

	// Month duration
	Month = (time.Duration(30.436875*float64(Day)) / time.Second) * time.Second // truncate to second

	// Year duration
	Year = (time.Duration(365.2425*float64(Day)) / time.Second) * time.Second // truncate to second

)

Variables

View Source
var ErrInt64Overflow = errors.New("int64 overflow")

ErrInt64Overflow is returned by ParseISO8601D if the duration can't fit in an int64.

Functions

func Between

func Between(t, a, b time.Time) bool

Between returns true if t is between a and b inclusive.

func Ceil

func Ceil(t time.Time, d time.Duration) time.Time

Ceil returns the result of rounding t up to a multiple of d (since the zero time). If d <= 0, Ceil returns t unchanged.

func IsMultiple

func IsMultiple(t time.Time, d time.Duration) bool

IsMultiple returns true if t is some multiple of d (since the zero time). If d <= 0, IsMultiple returns false.

func MustParseISO8601D

func MustParseISO8601D(duration string) time.Duration

MustParseISO8601D is like ParseISO8601D, but panics if there's an error.

func Next

func Next(t time.Time, d time.Duration) time.Time

Next returns the nearest multiple of d after t (since the zero time). If d <= 0, Next returns t unchanged.

func ParseISO8601D

func ParseISO8601D(duration string) (time.Duration, error)

ParseISO8601D parses an ISO 8601 duration string. Errors are returned if the string can't be parsed or the duration overflows an int64.

The following time assumptions are used: - Days are 24 hours. - Weeks are 7 days. - Months are 30.436875 days. - Years are 365.2425 days.

See: https://en.wikipedia.org/wiki/ISO_8601#Durations

func Prev

func Prev(t time.Time, d time.Duration) time.Time

Prev returns the nearest multiple of d before t (since the zero time). If d <= 0, Prev returns t unchanged.

Types

type RoundedTicker

type RoundedTicker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

RoundedTicker is like a time.Ticker, but rounded up to the nearest multiple of the tick Duration from the zero time.

func NewRoundedTicker

func NewRoundedTicker(d time.Duration) *RoundedTicker

NewRoundedTicker returns a new RoundedTicker.

func (*RoundedTicker) Stop

func (rt *RoundedTicker) Stop()

Stop turns off a ticker. After Stop, no more ticks will be sent. Stop does not close the channel, to prevent a concurrent goroutine reading from the channel from seeing an erroneous "tick".

Jump to

Keyboard shortcuts

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