Documentation
¶
Overview ¶
Package time implements time stuff.
Index ¶
- Constants
- Variables
- func Between(t, a, b time.Time) bool
- func Ceil(t time.Time, d time.Duration) time.Time
- func IsMultiple(t time.Time, d time.Duration) bool
- func MustParseISO8601D(duration string) time.Duration
- func Next(t time.Time, d time.Duration) time.Time
- func ParseISO8601D(duration string) (time.Duration, error)
- func Prev(t time.Time, d time.Duration) time.Time
- type RoundedTicker
Constants ¶
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 ¶
var ErrInt64Overflow = errors.New("int64 overflow")
ErrInt64Overflow is returned by ParseISO8601D if the duration can't fit in an int64.
Functions ¶
func Ceil ¶
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 ¶
IsMultiple returns true if t is some multiple of d (since the zero time). If d <= 0, IsMultiple returns false.
func MustParseISO8601D ¶
MustParseISO8601D is like ParseISO8601D, but panics if there's an error.
func Next ¶
Next returns the nearest multiple of d after t (since the zero time). If d <= 0, Next returns t unchanged.
func ParseISO8601D ¶
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.
Types ¶
type RoundedTicker ¶
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".