Documentation ¶
Overview ¶
Package parltime provides time utility functions
Index ¶
- Constants
- func Date(year int, month int, day int, hour int, min int, sec int, nsec int, ...) (t time.Time, valid bool)
- func Date1k(year int, month int, day int, hour int, min int, sec int, nsec int, ...) (t time.Time, valid bool)
- func Duration(d time.Duration) (printableDuration string)
- func Duro(period time.Duration, atTime time.Time) (d time.Duration)
- func GetTimeString(wallTime *time.Time) (s string)
- func Ms(d time.Duration) string
- func Ns(t time.Time) string
- func NsLocal(t time.Time) string
- func OnTimedThread(send func(at time.Time), period time.Duration, loc *time.Location, ...)
- func OnTimer(period time.Duration, t ...time.Time) (timer *time.Timer)
- func ParseNs(timeString string) (t time.Time, err error)
- func ParseRfc3339nsz(timeString string) (t time.Time, err error)
- func ParseS(timeString string) (t time.Time, err error)
- func ParseTime(dateString string) (tm time.Time, err error)
- func Rfc3339(t time.Time) string
- func Rfc3339msz(t time.Time) (s string)
- func Rfc3339nsz(t time.Time) (s string)
- func Rfc3339sz(t time.Time) (s string)
- func Rfc3339usz(t time.Time) (s string)
- func S(t time.Time) string
- func SGreater(t1 time.Time, t2 time.Time) bool
- type Alert
- type ClosingTicker
Constants ¶
const ( // RFC3339NanoSpace RFC3339 format, ns precision, space separator RFC3339NanoSpace string = "2006-01-02 15:04:05.999999999Z07:00" )
Variables ¶
This section is empty.
Functions ¶
func Date ¶ added in v0.4.12
func Date(year int, month int, day int, hour int, min int, sec int, nsec int, loc *time.Location) (t time.Time, valid bool)
ptime.Date is like time.Date with a flag valid that indicates whether the provided values represents a valid date. year is a 4-digit year, ie. 2022 is 2022. month 1–12, day 1–31, hour 0–23 minute 0-59, sec 0–59
func Date1k ¶ added in v0.4.12
func Date1k(year int, month int, day int, hour int, min int, sec int, nsec int, loc *time.Location) (t time.Time, valid bool)
ptime.Date is like time.Date with a flag valid that indicates whether the provided values represents a valid date. year is a 4-digit year, ie. 2022 is 2022. month 1–12, day 1–31, hour 0–23 minute 0-59, sec 0–59 A year below 1000 is not considered valid
func Duration ¶ added in v0.4.26
Duration formats time.Duration to string with 2 digits precision or better. Duration is more readable than time.Duration.String() that has full ns precision.
func Duro ¶
Duro returns the duration in nanoseconds until the next duration-multiple from zero time.
- The period starts from atTime
- time zone for multiple-calculation is defined by atTime, often time.Local
- time zone matters for 24 h or longer durations
func GetTimeString ¶
GetTimeString rfc 3339: email time format 2020-12-04 20:20:17-08:00
func OnTimedThread ¶ added in v0.4.22
func OnTimedThread(send func(at time.Time), period time.Duration, loc *time.Location, g0 recover.Go)
OnTimedThread invokes a callback on period-multiples since zero-time. thread-safe. OnTimedThread is invoked in a go statement, running in its own thread. The OnTimedThread thread invokes the send callback function periodically.
- the send function callback needs to be thread-safe and is invoked with the trig time provided
- loc is scheduling time zone for durations 24 h or greater eg. time.Local or time.UTC
- the timer thread is cancelled via g0.Context
- OnTimedThread uses g0.Done to provide thread error and to be waited-upon
- period must be greater than zero or panic
- if the send callback panics, that is a g0 fatal error
Usage:
gc := g0.NewGoGroup(context.Background()) defer gc.Wait() defer gc.Cancel() go ptime.OnTimedThread(someFunc, time.Second, time.Local, gc.Add(parl.EcSharedChan, parl.ExCancelOnExit).Go()) …
func OnTimer ¶
OnTimer returns a time.Timer that waits from t to the next period-multiple from zero time.
- period must be greater than zero or panic
- t contains time zone that matters for durations 24 h or longer, typicaly this is time.Local
- default t is time.Now()
func ParseRfc3339nsz ¶ added in v0.4.12
ParseRfc3339nsz parses a UTC time string at nanoseconds precision.
"2022-01-01T08:00:00.000000000Z"
func Rfc3339 ¶
Rfc3339 converts local time to string with second precision and time offset: 2006-01-02 15:04:05-07:00
func Rfc3339msz ¶ added in v0.4.12
Rfc3339msz prints a time using UTC and milliseconds precision.
"2022-01-01T08:00:00.000Z"
func Rfc3339nsz ¶ added in v0.4.12
Rfc3339nsz prints a time using UTC and nanoseconds precision.
"2022-01-01T08:00:00.000000000Z"
func Rfc3339sz ¶ added in v0.4.12
Rfc3339sz prints a time using UTC and seconds precision.
"2022-01-01T08:00:00Z"
func Rfc3339usz ¶ added in v0.4.12
Rfc3339usz prints a time using UTC and microseconds precision.
"2022-01-01T08:00:00.000000Z"
Types ¶
type Alert ¶
Alert impelemnts a renewable alert timer
type ClosingTicker ¶
type ClosingTicker struct { C <-chan time.Time MaxDuration time.Duration // atomic int64 perrors.ParlError // panic in Shutdown or panic in tick thread // contains filtered or unexported fields }
ClosingTicker is like time.Ticker but the channel C closes on shutdown. A closing channel is detectable by listening threads. If the computer is busy swapping, ticks will be lost. MaxDuration indicates the longest time observed between ticks. MaxDuration is normally 1 s
func NewClosingTicker ¶
func NewClosingTicker(d time.Duration) (t *ClosingTicker)
NewClosingTicker returns a Ticker whose channel C closes on shutdown. A closing channel is detectable by a listening thread.
func (*ClosingTicker) GetError ¶
func (t *ClosingTicker) GetError() (maxDuration time.Duration, err error)
func (*ClosingTicker) Shutdown ¶
func (t *ClosingTicker) Shutdown()
Shutdown causes the channel C to close and resources to be released