timeutil

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 16 Imported by: 92

Documentation

Overview

timeutil provides a set of time utilities including comparisons, conversion to "DT8" int32 and "DT14" int64 formats and other capabilities.

Index

Constants

View Source
const (
	SecondsPerYear = (365 * 24 * 60 * 60) + (6 * 60 * 60)
	SecondsPerWeek = 7 * 24 * 60 * 60
	SecondsPerDay  = 24 * 60 * 60

	NanosPerSecond      = int64(1000000000)
	NanosPerMicrosecond = NanosPerSecond / 1000000
	NanosPerMillisecond = NanosPerSecond / 1000
	NanosPerMinute      = NanosPerSecond * 60
	NanosPerHour        = NanosPerMinute * 24
	NanosPerSecondSub1  = NanosPerSecond - 1

	MonthsEN = `["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]`
)
View Source
const (
	DT14               = "20060102150405"
	DT8                = "20060102"
	DT6                = "200601"
	MonthDay           = "1/2"
	RFC3339FullDate    = "2006-01-02"
	RFC3339Milli       = "2006-01-02T15:04:05.999Z07:00"
	RFC3339Dash        = "2006-01-02T15-04-05Z07-00"
	ISO8601            = "2006-01-02T15:04:05Z0700"
	ISO8601TZHour      = "2006-01-02T15:04:05Z07"
	ISO8601NoTZ        = "2006-01-02T15:04:05"
	ISO8601MilliNoTZ   = "2006-01-02T15:04:05.999"
	ISO8601Milli       = "2006-01-02T15:04:05.999Z0700"
	ISO8601CompactZ    = "20060102T150405Z0700"
	ISO8601CompactNoTZ = "20060102T150405"
	ISO8601YM          = "2006-01"
	Ruby               = "2006-01-02 15:04:05 -0700" // Ruby Time.now.to_s
	SQLTimestamp       = "2006-01-02 15:04:05"       // MySQL, BigQuery, etc.
	SQLTimestampPgTz   = "2006-01-02 15:04:05.999999-07"
	InsightlyAPIQuery  = "_1/_2/2006 _3:04:05 PM"
	DateMDY            = "1/_2/2006"
	DateMDYSlash       = "01/02/2006"
	DateDMYHM2         = "02:01:06 15:04" // GMT time in format dd:mm:yy hh:mm
	DateYMD            = RFC3339FullDate
)

More predefined layouts for use in Time.Format and time.Parse.

View Source
const (
	RFC3339Min         = "0000-01-01T00:00:00Z"
	RFC3339Max         = "9999-12-31T23:59:59Z"
	RFC3339Zero        = "0001-01-01T00:00:00Z" // Golang zero value
	RFC3339ZeroUnix    = "1970-01-01T00:00:00Z"
	RFC3339YMDZeroUnix = int64(-62135596800)
)
View Source
const (
	NanosecondString  = "naonsecond"
	MicrosecondString = "microsecond"
	MillisecondString = "millisecond"
	SecondString      = "second"
	MinuteString      = "minute"
	HourString        = "hour"
	DayString         = "day"
	WeekString        = "week"
	MonthString       = "month"
	QuarterString     = "quarter"
	YearString        = "year"
	DecadeString      = "decade"
	ScoreString       = "score"
	CenturyString     = "century"
	MillenniaString   = "millennia"
)

Variables

View Source
var (
	ErrEmptyTimeSlice   = errors.New("empty time slice")
	ErrOutOfBounds      = errors.New("out of bounds")
	ErrOutOfBoundsLower = errors.New("out of bounds lower")
	ErrOutOfBoundsUpper = errors.New("out of bounds upper")
)
View Source
var FormatMap = map[string]string{
	"RFC3339":    time.RFC3339,
	"RFC3339YMD": RFC3339FullDate,
	"ISO8601YM":  ISO8601YM,
}

Functions

func AnyStringToQuarterTime

func AnyStringToQuarterTime(yyyyqSrcStr string) time.Time

AnyStringToQuarterTime returns the current time if in the current quarter or the end of any previous quarter.

func DT14ForInts added in v0.46.0

func DT14ForInts(yyyy, mm, dd, hr, mn, dy int) int64

DT14ForInts returns a Dt8 value for a UTC year, month, day, hour, minute and second.

func DT14ForString added in v0.46.0

func DT14ForString(layout, value string) (int64, error)

DT14ForString returns a DT14 value given a layout and value to parse to time.Parse.

func DT6ForDT14 added in v0.46.0

func DT6ForDT14(dt14 int64) int32

DT6ForDT14 returns the Dt6 value for Dt14.

func DT6MinMaxSlice added in v0.46.0

func DT6MinMaxSlice(minDt6 int32, maxDt6 int32) []int32

func DT6Next added in v0.46.0

func DT6Next(dt6 int32) int32

func DT6Parse added in v0.46.0

func DT6Parse(dt6 int32) (int16, int8)

func DT6Prev added in v0.46.0

func DT6Prev(dt6 int32) int32

func DT8ForInts added in v0.46.0

func DT8ForInts(yyyy, mm, dd int) int32

DT8ForInts returns a Dt8 value for year, month, and day.

func DT8ForString added in v0.46.0

func DT8ForString(layout, value string) (int32, error)

DT8ForString returns a Dt8 value given a layout and value to parse to time.Parse.

func DaysAgoDow

func DaysAgoDow(baseDow, wantDow time.Weekday, wantInclusive bool) int

func DaysAgoDowStrings

func DaysAgoDowStrings(baseDowS string, wantDowS string, wantInclusive bool) (int, error)

func DaysToDow

func DaysToDow(baseDow, wantDow time.Weekday, wantInclusive bool) int

func DaysToDowStrings

func DaysToDowStrings(baseDowS string, wantDowS string, wantInclusive bool) (int, error)

func Dd6ToTime

func Dd6ToTime(dd6 string, reverse bool) (time.Time, error)

func Distinct

func Distinct(times []time.Time) []time.Time

Distinct returns a time slice with distinct, or unique, times.

func DurationDays

func DurationDays(d time.Duration) float64

func DurationDaysInt64

func DurationDaysInt64(dur time.Duration) int64

func DurationForNowSubDT8 added in v0.46.0

func DurationForNowSubDT8(dt8 int32) (time.Duration, error)

DurationForNowSubDt8 returns a duartion struct between a Dt8 value and the current time.

func DurationFromProtobuf

func DurationFromProtobuf(pdur *durationpb.Duration) time.Duration

DurationFromProtobuf converts a protobuf duration to a `time.Duration`. More on protobuf: https://godoc.org/github.com/golang/protobuf/ptypes/duration#Duration

func DurationIsZero

func DurationIsZero(dur time.Duration) bool

func DurationStringMinutesSeconds

func DurationStringMinutesSeconds(durationSeconds int64) (string, error)

func DurationYears

func DurationYears(d time.Duration) float64

func DurationZero

func DurationZero() time.Duration

func Earliest

func Earliest(times []time.Time, skipZeroes bool) (time.Time, error)

func EqualQuarter

func EqualQuarter(dt1, dt2 time.Time) bool

func FirstDayOfISOWeek

func FirstDayOfISOWeek(year int, week int, timezone *time.Location) time.Time

FirstDayOfISOWeek returns a time.Time object for the first day of a given ISO week. https://xferion.com/golang-reverse-isoweek-get-the-date-of-the-first-day-of-iso-week/

func FirstNonZeroTime

func FirstNonZeroTime(times ...time.Time) (time.Time, error)

func FirstNonZeroTimeParsed

func FirstNonZeroTimeParsed(format string, times []string) (time.Time, error)

func FormatDurationInfoMinSec

func FormatDurationInfoMinSec(di DurationInfo) string

FormatDurationInfoMinSec returns the duration as a simple string like 01:01.

func FormatQuarter

func FormatQuarter(t time.Time) string

FormatQuarter takes quarter time and formats it using "Q# YYYY".

func FormatQuarterYYQ

func FormatQuarterYYQ(t time.Time) string

FormatQuarterYYQ takes quarter time and formats it using "'YY Q#".

func FormatQuarterYYYYQ

func FormatQuarterYYYYQ(t time.Time) string

FormatQuarter takes quarter time and formats it using "YYYY Q#".

func FormatTimeMulti

func FormatTimeMulti(dateFormat string, v any) string

FormatTimeMulti formats a `time.Time` object or an epoch number. It is adapted from `github.com/wcharczuk/go-chart`.

func FormatTimeToString

func FormatTimeToString(format string) func(time.Time) string

func FromTo

func FromTo(value, fromLayout, toLayout string) (string, error)

Reformat a time string from one format to another Deprecated...

func FromTo2

func FromTo2(fromLayout, toLayout, value string) (string, error)

Reformat a time string from one format to another

func FromToFirstValue

func FromToFirstValue(fromLayout, toLayout string, values []string) (string, error)

func FromToFirstValueOrEmpty

func FromToFirstValueOrEmpty(fromLayout, toLayout string, values []string) string

func GetFormat

func GetFormat(formatName string) (string, error)

func GreaterTime

func GreaterTime(t1, t2 time.Time) time.Time

GreaterTime returns the greater of two times.

func InQuarter

func InQuarter(dt time.Time, yyyyq int32) (bool, error)

func InQuarterRange

func InQuarterRange(dt time.Time, yyyyq1, yyyyq2 int32) (bool, error)

InQuarterRange checks to see if the date is within 2 quarters.

func InQuarterTime

func InQuarterTime(dt, qtr time.Time) bool

func InRange

func InRange(rangeStart, rangeEnd, needle time.Time, incStart, incEnd bool) bool

InRange checks to see if a time is within a provided time range with options whether the start and end ranges are inclusive or exclusive. Exclusive ranges are the default.

func IntToBaseXString

func IntToBaseXString(baseX, val int) string

func IsGreaterThan

func IsGreaterThan(timeLeft time.Time, timeRight time.Time, orEqual bool) bool

IsGreaterThan compares two times and returns true if the left time is greater than the right time.

func IsLessThan

func IsLessThan(timeLeft time.Time, timeRight time.Time, orEqual bool) bool

IsLessThan compares two times and returns true if the left time is less than the right time.

func IsQuarterInt32

func IsQuarterInt32(q int32) bool

func Latest

func Latest(times []time.Time, skipZeroes bool) (time.Time, error)

func LesserTime

func LesserTime(t1, t2 time.Time) time.Time

LesserTime returns the lesser of two times.

func MaxDuration

func MaxDuration(durs []time.Duration) time.Duration

func MaxInt32

func MaxInt32(ints []int32) int32

func MaxTime

func MaxTime(t, max time.Time) time.Time

MaxTime returns maxTime if time in question is greater than max time.

func MinInt32

func MinInt32(ints []int32) int32

func MinMax

func MinMax(min, max time.Time) (time.Time, time.Time)

MinMax takes two times and returns the earlier time first.

func MinMaxInt32

func MinMaxInt32(ints []int32) (int32, int32)

func MinTime

func MinTime(t, min time.Time) time.Time

MinTime returns minTime if time in question is less than min time.

func MonthEndDay added in v0.46.0

func MonthEndDay(year int, month time.Month) int

func MonthNames

func MonthNames() []string

func MonthToQuarter

func MonthToQuarter(month uint8) uint8

MonthToQuarter converts a month to a calendar quarter.

func MustFirstNonZeroTime

func MustFirstNonZeroTime(times ...time.Time) time.Time

func MustInQuarter

func MustInQuarter(dt time.Time, yyyyq int32) bool

func MustInQuarterRange

func MustInQuarterRange(dt time.Time, yyyyq1, yyyyq2 int32) bool

MustInQuarterRange returns whether a date is within 2 quarters. It panics if the quarter integer is not valid.

func MustParse

func MustParse(layout, value string) time.Time

func MustParseDuration

func MustParseDuration(s string) time.Duration

func NewDuration added in v0.45.0

func NewDuration(day, hour, min, sec float64, nsec int64) time.Duration

func NewDurationStrings

func NewDurationStrings(h, m, s string) (time.Duration, error)

func NowDeltaDuration

func NowDeltaDuration(d time.Duration) time.Time

func NowDeltaParseDuration

func NowDeltaParseDuration(s string) (time.Time, error)

func NumQuartersInt32

func NumQuartersInt32(start, end int32) (int, error)

func OffsetFormat

func OffsetFormat(offset int, useColon, useZ bool) string

OffsetFormat converts an integer offset value to a string value to use in string time formats. Note: RFC-3339 times use colons and the UTC "Z" offset.

func ParseDayOfWeek

func ParseDayOfWeek(d string) (time.Weekday, error)

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration adds days (d), weeks (w), years (y).

func ParseFirst

func ParseFirst(layouts []string, value string) (time.Time, error)

ParseFirst attempts to parse a string with a set of layouts.

func ParseFirstValue

func ParseFirstValue(layout string, values []string) (time.Time, error)

func ParseFirstValueOrZero

func ParseFirstValueOrZero(layout string, values []string) time.Time

func ParseHalf

func ParseHalf(yyyyh int32) (int32, uint8, error)

func ParseOrZero

func ParseOrZero(layout, value string) time.Time

ParseOrZero returns a parsed time.Time or the RFC-3339 zero time.

func ParseQuarterInt32

func ParseQuarterInt32(yyyyq int32) (int32, uint8, error)

func ParseQuarterInt32StartEndTimes

func ParseQuarterInt32StartEndTimes(yyyyq int32) (time.Time, time.Time, error)

func ParseQuarterStringStartTime

func ParseQuarterStringStartTime(yyyyqStr string) (time.Time, error)

func ParseSlice

func ParseSlice(layout string, strings []string) ([]time.Time, error)

func ParseTimeSQLTimestampUsingOffset

func ParseTimeSQLTimestampUsingOffset(timeStr string, offset int) (time.Time, error)

ParseTimeSQLTimestampUsingOffset converts a SQL timestamp without timezone adding in a manual integer timezone.

func ParseTimeUsingOffset

func ParseTimeUsingOffset(format, raw, sep string, offset int, useColon, useZ bool) (time.Time, error)

func ParseWeekday

func ParseWeekday(s string) (time.Weekday, error)

func QuarterAdd added in v0.40.1

func QuarterAdd(t time.Time, count int) time.Time

func QuarterInt32Add added in v0.40.1

func QuarterInt32Add(yyyyq int32, numQuarters int) (int32, error)

func QuarterInt32End

func QuarterInt32End(yyyyq int32) (time.Time, error)

func QuarterInt32EndTime

func QuarterInt32EndTime(yyyyq int32) (time.Time, error)

func QuarterInt32ForTime

func QuarterInt32ForTime(dt time.Time) int32

func QuarterInt32Now

func QuarterInt32Now() int32

func QuarterInt32StartTime

func QuarterInt32StartTime(yyyyq int32) (time.Time, error)

func QuarterInt32Timeline

func QuarterInt32Timeline(ints []int32) ([]int32, error)

func QuarterInt32ToYear

func QuarterInt32ToYear(yyyyq int32) int32

func QuarterProjection

func QuarterProjection(dt time.Time, current float64) float64

QuarterProjection takes a time and numeric value, estimating the value at the end of the quarter using a straight-line projection.

func QuarterSlice

func QuarterSlice(min, max time.Time) []time.Time

func QuarterStartString

func QuarterStartString(t time.Time) string

func QuarterStringEndTime

func QuarterStringEndTime(yyyyqStr string) (time.Time, error)

func QuarterStringStartTime

func QuarterStringStartTime(yyyyqStr string) (time.Time, error)

func QuarterToMonth

func QuarterToMonth(quarter uint8) uint8

QuarterToMonth converts a calendar quarter to a month.

func QuartersInt32RelToAbs

func QuartersInt32RelToAbs(start, end int32) (int32, int32)

QuartersInt32RelToAbs is useful relative date queries.

func SliceMinMax

func SliceMinMax(times []time.Time) (time.Time, time.Time)

SliceMinMax returns the min and max times of a time slice.

func Sort

func Sort(times []time.Time) []time.Time

func SubDuration

func SubDuration(dur1, dur2 time.Duration) time.Duration

SubDuration subtracts one duration from another and returns the result as a `time.Duration`.

func SumDurations

func SumDurations(durations ...time.Duration) time.Duration

func TimeDT4AddNYears added in v0.46.0

func TimeDT4AddNYears(t time.Time, numYears int) time.Time

func TimeDT6AddNMonths added in v0.46.0

func TimeDT6AddNMonths(t time.Time, numMonths int) time.Time

func TimeDT6SubNMonths added in v0.46.0

func TimeDT6SubNMonths(t time.Time, numMonths int) time.Time

func TimeDeltaDow

func TimeDeltaDow(base time.Time, wantDow time.Weekday, deltaUnits int, wantInclusive bool, wantStartOfDay bool) (time.Time, error)

func TimeDeltaDowInt

func TimeDeltaDowInt(base time.Time, wantDow time.Weekday, deltaUnits int, wantInclusive bool, wantStartOfDay bool) (time.Time, error)

func TimeDeltaDowString

func TimeDeltaDowString(base time.Time, wantDowS string, deltaUnits int, wantInclusive bool, wantStartOfDay bool) (time.Time, error)

func TimeForDT14 added in v0.46.0

func TimeForDT14(dt14 int64) (time.Time, error)

TimeForDT14 returns a time.Time value given a Dt14 value.

func TimeForDT6 added in v0.46.0

func TimeForDT6(dt6 int32) (time.Time, error)

TimeForDT6 returns a time.Time value given a Dt6 value.

func TimeForDT8 added in v0.46.0

func TimeForDT8(dt8 int32) (time.Time, error)

TimeForDT8 returns a time.Time value given a Dt8 value.

func TimeMinRFC3339

func TimeMinRFC3339() time.Time

func TimeSeriesMinMax

func TimeSeriesMinMax(interval Interval, min, max time.Time) []time.Time

TimeSeriesMinMax builds a time series based on supplied interval.

func TimeSeriesSlice

func TimeSeriesSlice(interval Interval, times []time.Time) []time.Time

TimeSeriesSlice builds a time series based on supplied interval.

func TimeSliceMinMax

func TimeSliceMinMax(times []time.Time) (time.Time, time.Time, error)

func TimeToDd6

func TimeToDd6(dt time.Time, reverse bool) (string, error)

func TimeWithin

func TimeWithin(this, beg, end time.Time, eqBeg, eqEnd bool) bool

func TimeZeroRFC3339

func TimeZeroRFC3339() time.Time

func TimeZeroUnix

func TimeZeroUnix() time.Time

func Timespec added in v0.46.0

func Timespec(t syscall.Timespec) time.Time

func Timeval added in v0.46.0

func Timeval(t syscall.Timeval) time.Time

func UnixToDay

func UnixToDay(epoch int64) time.Time

UnixToDay converts an epoch in seconds to a time.Time for the day.

func WeekdayNormalized added in v0.46.0

func WeekdayNormalized(d time.Weekday) time.Weekday

WeekdayNormalized ensures a `time.Weekday` value is within `[0,6]`. It supports converting postiive and negative integers.

Types

type DurationInfo

type DurationInfo struct {
	Hours        int64
	Minutes      int64
	Seconds      int64
	Milliseconds int64
	Microseconds int64
	Nanoseconds  int64
}

DurationInfo is a struct that holds integer values for each time unit including hours, minutes, seconds milliseconds, microseconds, and nanoseconds.

func NewDurationInfo

func NewDurationInfo(dur time.Duration) DurationInfo

NewDurationInfo returns a DurationInfo struct for a duration in nanos.

func ParseDurationInfoStrings

func ParseDurationInfoStrings(hr, mn, sc, ms, us, ns string) (DurationInfo, error)

ParseDurationInfoStrings returns a DurationInfo object for various time units.

func (*DurationInfo) Duration

func (di *DurationInfo) Duration() time.Duration

Duration returns a `time.Duration` struct representing the duration.

func (*DurationInfo) TotalNanoseconds

func (di *DurationInfo) TotalNanoseconds() int64

TotalNanoseconds returns the total number of nanoseconds represented by the duration.

type DurationPct

type DurationPct struct {
	DurationStartTime time.Time
	DurationEndTime   time.Time
	DurationActive    time.Duration
	DurationRange     time.Duration
	DurationPct       float64
}

func (*DurationPct) Inflate

func (dp *DurationPct) Inflate() error

func (*DurationPct) InflateDurationActive

func (dp *DurationPct) InflateDurationActive() error

type Event

type Event struct {
	DurationPct    DurationPct
	ImpactPct      ImpactPct
	EventImpactPct float64
	EventUptimePct float64
}

func (*Event) Inflate

func (e *Event) Inflate() error

type ISO8601NoTzMilliTime

type ISO8601NoTzMilliTime struct{ time.Time }

func (ISO8601NoTzMilliTime) MarshalJSON

func (t ISO8601NoTzMilliTime) MarshalJSON() ([]byte, error)

func (*ISO8601NoTzMilliTime) UnmarshalJSON

func (t *ISO8601NoTzMilliTime) UnmarshalJSON(buf []byte) error

type ImpactPct

type ImpactPct struct {
	ImpactNum int
	TotalNum  int
	ImpactPct float64
}

func (*ImpactPct) Inflate

func (ip *ImpactPct) Inflate() error

type Interval

type Interval int
const (
	Nanosecond Interval = iota
	Microsecond
	Millisecond
	Second
	Minute
	Hour
	Day
	Week
	Month
	Quarter
	Year
	Decade
	Score
	Century
	Millennia
)

func ParseInterval

func ParseInterval(src string) (Interval, error)

func (Interval) String

func (i Interval) String() string

type QuarterTimeline

type QuarterTimeline struct {
	// contains filtered or unexported fields
}

func (*QuarterTimeline) Add

func (qt *QuarterTimeline) Add(yyyyq int32)

func (*QuarterTimeline) AddInit

func (qt *QuarterTimeline) AddInit(yyyyq int32)

func (*QuarterTimeline) Inflate

func (qt *QuarterTimeline) Inflate() error

func (*QuarterTimeline) Timeline

func (qt *QuarterTimeline) Timeline() ([]int32, error)

func (*QuarterTimeline) TimelineIndex

func (qt *QuarterTimeline) TimelineIndex(yyyyq int32) (int, error)

type RFC3339YMDTime

type RFC3339YMDTime struct{ time.Time }

func (RFC3339YMDTime) MarshalJSON

func (t RFC3339YMDTime) MarshalJSON() ([]byte, error)

func (*RFC3339YMDTime) UnmarshalJSON

func (t *RFC3339YMDTime) UnmarshalJSON(buf []byte) error

type TimeMeta

type TimeMeta struct {
	This           time.Time
	WeekStartDay   string
	YearStart      time.Time
	YearEnd        time.Time
	QuarterStart   time.Time
	QuarterEnd     time.Time
	MonthStart     time.Time
	MonthEnd       time.Time
	WeekStart      time.Time
	WeekEnd        time.Time
	DayStart       time.Time
	DayEnd         time.Time
	IsYearStart    bool
	IsQuarterStart bool
	IsMonthStart   bool
}

TimeMeta is a struct for holding various times related to a current time, including year start, quarter start, month start, and week start.

type TimeMore

type TimeMore struct {
	// contains filtered or unexported fields
}

TimeMore is a struct for holding various times related to a current time, including year start, quarter start, month start, and week start.

func NewTimeMore

func NewTimeMore(t time.Time, d time.Weekday) TimeMore

func NewTimeMoreQuarterEndString

func NewTimeMoreQuarterEndString(yyyyq string, d time.Weekday) (TimeMore, error)

func NewTimeMoreQuarterStartString

func NewTimeMoreQuarterStartString(yyyyq string, d time.Weekday) (TimeMore, error)

func (TimeMore) DT14 added in v0.46.0

func (tm TimeMore) DT14() int64

Dt14ForTime returns a Dt14 value given a time.Time struct.

func (TimeMore) DT6 added in v0.46.0

func (tm TimeMore) DT6() int32

DT6 returns the Dt6 value for time.Time.

func (TimeMore) DT8 added in v0.46.0

func (tm TimeMore) DT8() int32

Dt8ForTime returns a Dt8 value given a time struct.

func (TimeMore) DayEnd added in v0.46.0

func (tm TimeMore) DayEnd() time.Time

func (TimeMore) DayStart added in v0.46.0

func (tm TimeMore) DayStart() time.Time

func (TimeMore) IntervalStart added in v0.46.0

func (tm TimeMore) IntervalStart(interval Interval) (time.Time, error)

func (TimeMore) IsMonthStart added in v0.46.0

func (tm TimeMore) IsMonthStart() bool

func (TimeMore) IsQuarterStart added in v0.46.0

func (tm TimeMore) IsQuarterStart() bool

func (TimeMore) IsYearStart added in v0.46.0

func (tm TimeMore) IsYearStart() bool

func (TimeMore) IsZeroAny added in v0.46.0

func (tm TimeMore) IsZeroAny() bool

func (TimeMore) MonthEnd added in v0.46.0

func (tm TimeMore) MonthEnd() time.Time

func (TimeMore) MonthStart

func (tm TimeMore) MonthStart() time.Time

func (TimeMore) Quarter

func (tm TimeMore) Quarter() int32

func (TimeMore) QuarterDuration added in v0.46.0

func (tm TimeMore) QuarterDuration() time.Duration

QuarterDuration returns a `time.Duration` representing the calendar quarter for the time provided.

func (TimeMore) QuarterEnd

func (tm TimeMore) QuarterEnd() time.Time

func (TimeMore) QuarterStart

func (tm TimeMore) QuarterStart() time.Time

func (TimeMore) Time

func (tm TimeMore) Time() time.Time

func (TimeMore) TimeMeta added in v0.46.0

func (tm TimeMore) TimeMeta() TimeMeta

TimeMeta returns a TimeMeta struct given `time.Time` and `time.Weekday` parameters.

func (TimeMore) WeekEnd added in v0.46.0

func (tm TimeMore) WeekEnd() time.Time

func (TimeMore) WeekStart

func (tm TimeMore) WeekStart() time.Time

func (TimeMore) WeekStartDay added in v0.46.0

func (tm TimeMore) WeekStartDay() time.Weekday

func (TimeMore) WeekdayNext added in v0.46.0

func (tm TimeMore) WeekdayNext(d time.Weekday) time.Time

func (TimeMore) Year

func (tm TimeMore) Year() int32

func (TimeMore) YearEnd

func (tm TimeMore) YearEnd() time.Time

func (TimeMore) YearStart

func (tm TimeMore) YearStart() time.Time

type TimeOpts

type TimeOpts struct {
	Year       int
	Month      int
	Day        int
	Hour       int
	Minute     int
	Second     int
	Nanosecond int
	Location   *time.Location
}

TimeOpts represnts a struct for `time.Date`.

func (TimeOpts) Time

func (opts TimeOpts) Time() time.Time

Time returns a `time.Time` struct. If no `Location` is set, `time.UTC` is used.

type TimeRange

type TimeRange struct {
	Max     time.Time
	Min     time.Time
	HaveMax bool
	HaveMin bool
}

TimeRange represents a time range with a max and min value.

func (*TimeRange) Duration

func (tr *TimeRange) Duration() time.Duration

func (*TimeRange) HasIntersection

func (tr *TimeRange) HasIntersection(tr2 TimeRange) bool

func (*TimeRange) Insert

func (tr *TimeRange) Insert(t time.Time)

Insert updates a time range min and max values for a given time.

func (*TimeRange) InsertMax

func (tr *TimeRange) InsertMax(t time.Time)

InsertMax updates a time range max value for a given time.

func (*TimeRange) InsertMin

func (tr *TimeRange) InsertMin(t time.Time)

InsertMin updates a time range min value for a given time.

func (*TimeRange) IntersectionDuration

func (tr *TimeRange) IntersectionDuration(tr2 TimeRange) time.Duration

func (*TimeRange) Nanoseconds

func (tr *TimeRange) Nanoseconds() uint64

func (*TimeRange) Normalize

func (tr *TimeRange) Normalize()

type TimeRanges

type TimeRanges []*TimeRange

func (TimeRanges) FilterNonZero

func (trs TimeRanges) FilterNonZero() TimeRanges

func (TimeRanges) IntersectionAny

func (trs TimeRanges) IntersectionAny() time.Duration

type Times added in v0.46.0

type Times []time.Time

Times is a slice of `time.Time` that supports a number of functions and can be used for sorting, e.g. `sort.Sort(times)` or `sort.Sort(sort.Reverse(times))`.

func ParseTimes added in v0.46.0

func ParseTimes(format string, times []string) (Times, error)

func (Times) Dedupe added in v0.46.0

func (ts Times) Dedupe() Times

func (Times) Duplicate added in v0.46.0

func (ts Times) Duplicate() Times

func (Times) Equal added in v0.46.0

func (ts Times) Equal(compare Times) bool

func (Times) Format added in v0.46.0

func (ts Times) Format(format string) []string

func (Times) Len added in v0.46.0

func (ts Times) Len() int

func (Times) Less added in v0.46.0

func (ts Times) Less(i, j int) bool

func (Times) RangeLower added in v0.46.0

func (ts Times) RangeLower(t time.Time, inclusive bool) (time.Time, error)

RangeLower returns the TimeSlice time value for the range lower than or equal to the supplied time.

func (Times) RangeUpper added in v0.46.0

func (ts Times) RangeUpper(t time.Time, inclusive bool) (time.Time, error)

RangeUpper returns the Times time value for the range lower than or equal to the supplied time. The time `t` must be less than or equal to the upper range.

func (Times) Sort added in v0.46.0

func (ts Times) Sort()

func (Times) SortReverse added in v0.46.0

func (ts Times) SortReverse()

func (Times) Swap added in v0.46.0

func (ts Times) Swap(i, j int)

type XOXTimes

type XOXTimes struct {
	CurrentTime   time.Time
	CurrentStart  time.Time
	PreviousTime  time.Time
	PreviousStart time.Time
}

func QOQTimes

func QOQTimes(thisTime time.Time) XOXTimes

func YOYTimes

func YOYTimes(t time.Time) XOXTimes

Jump to

Keyboard shortcuts

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