Documentation ¶
Overview ¶
EpochValue is a timestamp with Thread-Safe atomic access.
Epoch translates a time value to a 64-bit value that can be used atomically.
Period provides real-time based fixed-length interval perioding ordered using a uint64 zero-based index.
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, g0 Go)deprecated
- 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 AverageInterval
- type Averager
- type Averager3
- type ClosingTicker
- type Epoch
- type EpochValue
- type Go
- type OnTicker
- type Period
- type PeriodIndex
Constants ¶
const (
FractionScale = uint64(1) << 63
)
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
deprecated
added in
v0.4.22
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()) …
Deprecated: use NewOnTicker2
func OnTimer ¶
OnTimer returns a time.Timer that waits until the next period-multiple since zero time.
- default starting time until the period multiple is now: time.Now(), optionally the absolute time t
- t contains time zone that matters for periods over 1 hour, typically this is time.Local
- the other time zone for Go is time.UTC
- period must be greater than zero or panic
- time.NewTimer does not offer the period calculation
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 AverageInterval ¶ added in v0.4.48
type AverageInterval struct {
// contains filtered or unexported fields
}
AverageInterval is a container for the datapoint aggregate over a single period
func NewAverageInterval ¶ added in v0.4.48
func NewAverageInterval(index PeriodIndex) (ai *AverageInterval)
NewAverageInterval returns an avareging container for one averaging interval
func (*AverageInterval) Add ¶ added in v0.4.48
func (ai *AverageInterval) Add(value float64)
Add adds a datapoint to the averager
func (*AverageInterval) Aggregate ¶ added in v0.4.48
func (ai *AverageInterval) Aggregate(countp *uint64, floatp *float64)
Aggregate provides averaging content for calcukating the average
type Averager ¶ added in v0.4.48
type Averager[T constraints.Integer] struct { // contains filtered or unexported fields }
Averager is a container for averaging providing perioding and history.
- maxCount is the maximum interval over which average is calculated
func NewAverager ¶ added in v0.4.48
func NewAverager[T constraints.Integer]() (averager *Averager[T])
NewAverager returns an object that calculates average over a number of interval periods.
func NewAverager2 ¶ added in v0.4.51
func NewAverager2[T constraints.Integer](period time.Duration, periodCount int) (averager *Averager[T])
NewAverager2 returns an object that calculates average over a number of interval periods.
func (*Averager[T]) Add ¶ added in v0.4.48
Add adds a new value basis for averaging
- value is the sample value
- t is the sample time, default time.Now()
type Averager3 ¶ added in v0.4.48
type Averager3[T constraints.Integer] struct { Averager[T] // contains filtered or unexported fields }
Averager3 is an average container with last, average and max values.
func NewAverager3 ¶ added in v0.4.48
func NewAverager3[T constraints.Integer]() (averager *Averager3[T])
NewAverager3 returns an calculator for last, average and max values.
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
type Epoch ¶ added in v0.4.50
Epoch translates a time value to a 64-bit value that can be used atomically.
func EpochNow ¶ added in v0.4.50
EpochNow translates a time value to a 64-bit value that can be used atomically.
type EpochValue ¶ added in v0.4.50
type EpochValue Epoch
EpochValue is a timestamp with Thread-Safe atomic access.
func (*EpochValue) Get ¶ added in v0.4.50
func (ev *EpochValue) Get() (epoch Epoch)
Get returns the current Epoch value
- zero epoch is returned as zero-time Time.IsZero, time.Time{}
- to get time.Time: epochValue.Get().Time()
- to check if non-zero: epochValue.Get().IsValid()
func (*EpochValue) Set ¶ added in v0.4.50
func (ev *EpochValue) Set(epoch Epoch) (oldEpoch Epoch)
Set updates the Epoch value returning the old value
- 0 is the zero-value
type OnTicker ¶ added in v0.4.58
type OnTicker struct { C <-chan time.Time // The channel on which the ticks are delivered. // contains filtered or unexported fields }
OnTicker is a ticker triggering on period-multiples since zero time
func NewOnTicker ¶ added in v0.4.58
NewOnTicker returns a ticker that ticks on period-multiples since zero time.
- loc is optional time zone, default time.Local, other time zone is time.UTC
- time zone matters for periods over 1 hour
- period must be greater than zero or panic
- OnTicker is a time.Ticker using on-period multiples
func NewOnTicker2 ¶ added in v0.4.58
type Period ¶ added in v0.4.48
type Period struct {
// contains filtered or unexported fields
}
Period provides real-time based fixed-length interval perioding ordered using a uint64 zero-based index.
- Period provides first period index and fractional usage of the first period
func (*Period) Available ¶ added in v0.4.48
func (p *Period) Available(now PeriodIndex, cap int) (periods int)
Available returns the number of possible periods 1… but no greater than cap
- now cannot be less than period0
func (*Period) Index ¶ added in v0.4.48
func (p *Period) Index(t ...time.Time) (index PeriodIndex)
Index returns the index number for the current period or the period at time t
- Index is zero-based
func (*Period) Since ¶ added in v0.4.48
func (p *Period) Since(now, before PeriodIndex) (periods int)
Since returns the number of periods difference that now is greater than before
- periods is >= 0
- now and before must be at least p.period0
- before cannot be greater than now
func (*Period) Sub ¶ added in v0.4.48
func (p *Period) Sub(now PeriodIndex, n int) (periodIndex PeriodIndex)
Sub returns a past period index by n intervals
- periodIndex will not be less than p.period0
- now cannot be less than p.period0
type PeriodIndex ¶ added in v0.4.48
type PeriodIndex uint64