timeutil

package
v0.37.5 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: MIT Imports: 15 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 (
	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
)

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"
	RFC3339ZeroUnix    = "1970-01-01T00:00:00Z"
	RFC3339YMDZeroUnix = int64(-62135596800)
)
View Source
const (
	YearSeconds            = (365 * 24 * 60 * 60) + (6 * 60 * 60)
	WeekSeconds            = 7 * 24 * 60 * 60
	DaySeconds             = 24 * 60 * 60
	MonthsEN               = `["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]`
	MillisToNanoMultiplier = 1000000
)

Variables

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 DayStart

func DayStart(dt time.Time) time.Time

func DaysAgoDow

func DaysAgoDow(baseDow int, wantDow int, wantInclusive bool) (int, error)

func DaysAgoDowStrings

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

func DaysToDow

func DaysToDow(baseDow int, wantDow int, wantInclusive bool) (int, error)

func DaysToDowStrings

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

func Dd6ToTime

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

func DeltaQuarterInt32

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

func DeltaQuarters

func DeltaQuarters(dt time.Time, num int) time.Time

func Distinct

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

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

func Dt14ForInts

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

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

func Dt14ForString

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

Dt14ForString returns a Dt14 value given a layout and value to parse to time.Parse.

func Dt14ForTime

func Dt14ForTime(t time.Time) int64

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

func Dt14Now

func Dt14Now() int64

Dt14Now returns a Dt14 value for the current time.

func Dt6ForDt14

func Dt6ForDt14(dt14 int64) int32

Dt6ForDt14 returns the Dt6 value for Dt14.

func Dt6ForTime

func Dt6ForTime(dt time.Time) int32

Dt6ForTime returns the Dt6 value for time.Time.

func Dt6MinMaxSlice

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

func Dt8ForInts

func Dt8ForInts(yyyy, mm, dd int) int32

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

func Dt8ForString

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

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

func Dt8ForTime

func Dt8ForTime(t time.Time) int32

Dt8ForTime returns a Dt8 value given a time struct.

func Dt8Now

func Dt8Now() int32

Dt8Now returns Dt8 value for the current time.

func DurationDays

func DurationDays(d time.Duration) float64

func DurationDaysInt64

func DurationDaysInt64(dur time.Duration) int64

func DurationForNowSubDt8

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 *duration.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 interface{}) 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 begin and end ranges are inclusive or exclusive. Exclusive ranges are the default.

func IntToBaseXString

func IntToBaseXString(baseX, val int) string

func IntervalStart

func IntervalStart(dt time.Time, interval Interval, dow time.Weekday) (time.Time, error)

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 IsQuarterStart

func IsQuarterStart(t time.Time) bool

func IsYearStart

func IsYearStart(dt time.Time) bool

func IsZero

func IsZero(u time.Time) bool

func IsZeroAny

func IsZeroAny(u time.Time) 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 MonthNames

func MonthNames() []string

func MonthStart

func MonthStart(dt time.Time) time.Time

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 NewDurationDays

func NewDurationDays(days uint16) time.Duration

NewDurationDays returns `time.Duration` given a number of days

func NewDurationSeconds

func NewDurationSeconds(secs float64) time.Duration

NewDurationSeconds returns a new `time.Duration` given a number of seconds.

func NewDurationStrings

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

func NextDt6

func NextDt6(dt6 int32) int32

func NextQuarter

func NextQuarter(dt time.Time) time.Time

func NextQuarterInt32

func NextQuarterInt32(yyyyq int32) (int32, error)

func NextQuarters

func NextQuarters(dt time.Time, num uint) time.Time

func NextWeekday

func NextWeekday(dow time.Weekday) time.Time

func NextYearStart

func NextYearStart(dt time.Time) time.Time

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(value string) (int, error)

func ParseDt6

func ParseDt6(dt6 int32) (int16, int8)

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 PrevDt6

func PrevDt6(dt6 int32) int32

func PrevQuarter

func PrevQuarter(dt time.Time) time.Time

func PrevQuarters

func PrevQuarters(dt time.Time, num uint) time.Time

func QuarterDuration

func QuarterDuration(dt time.Time) time.Duration

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

func QuarterEnd

func QuarterEnd(dt time.Time) time.Time

QuarterEnd returns a time.Time for the end of the quarter by second in UTC time.

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 QuarterStart

func QuarterStart(dt time.Time) time.Time

QuarterStart returns a time.Time for the beginning of the quarter in UTC time.

func QuarterStartString

func QuarterStartString(dt 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(begin, 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 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 int, 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 TimeDt4AddNYears

func TimeDt4AddNYears(dt time.Time, numYears int) time.Time

func TimeDt6AddNMonths

func TimeDt6AddNMonths(dt time.Time, numMonths int) time.Time

func TimeDt6SubNMonths

func TimeDt6SubNMonths(dt time.Time, numMonths int) time.Time

func TimeForDt14

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

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

func TimeForDt6

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

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

func TimeForDt8

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

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

func TimeIsZeroAny

func TimeIsZeroAny(u time.Time) bool

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 UnixMillis

func UnixMillis(epochMillis int64) time.Time

TimeForEpochMillis returns the time.Time value for an epoch in milliseconds

func UnixToDay

func UnixToDay(epoch int64) time.Time

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

func WeekStart

func WeekStart(dt time.Time, dow time.Weekday) (time.Time, error)

WeekStart takes a time.Time object and a week start day in the time.Weekday format.

func YearEnd

func YearEnd(dt time.Time) time.Time

YearEnd returns a a time.Time for the end of the year in UTC time.

func YearStart

func YearStart(dt time.Time) time.Time

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 (
	Decade Interval = iota
	Year
	Quarter
	Month
	Week
	Day
	Hour
	Minute
	Second
	Millisecond
	Microsecond
	Nanosecond
)

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
	YearStart    time.Time
	QuarterStart time.Time
	MonthStart   time.Time
	WeekStart    time.Time
}

// WeekStart takes a time.Time object and a week start day // in the time.Weekday format.

func WeekStart(dt time.Time, dow time.Weekday) (time.Time, error) {
	return TimeDeltaDowInt(dt.UTC(), int(dow), -1, true, true)
}

// MonthStart returns a time.Time for the beginning of the // month in UTC time.

func MonthStart(dt time.Time) time.Time {
	dt = dt.UTC()
	return time.Date(dt.Year(), dt.Month(), 1, 0, 0, 0, 0, time.UTC)
}

// QuarterEnd returns a time.Time for the end of the // quarter by second in UTC time.

func QuarterEnd(dt time.Time) time.Time {
	qs := QuarterStart(dt.UTC())
	qn := TimeDt6AddNMonths(qs, 3)
	return time.Date(qn.Year(), qn.Month(), 0, 23, 59, 59, 0, time.UTC)
}

// YearStart returns a a time.Time for the beginning of the year // in UTC time.

func YearStart(dt time.Time) time.Time {
	return time.Date(dt.UTC().Year(), time.January, 1, 0, 0, 0, 0, time.UTC)
}

// YearEnd returns a a time.Time for the end of the year in UTC time.

func YearEnd(dt time.Time) time.Time {
	return time.Date(dt.UTC().Year(), time.December, 31, 23, 59, 59, 999999999, time.UTC)
}
func NextYearStart(dt time.Time) time.Time {
	return time.Date(dt.UTC().Year()+1, time.January, 1, 0, 0, 0, 0, time.UTC)
}
func IsYearStart(t time.Time) bool {
	t = t.UTC()
	if t.Nanosecond() == 0 &&
		t.Second() == 0 &&
		t.Minute() == 0 &&
		t.Hour() == 0 &&
		t.Day() == 1 &&
		t.Month() == time.January {
		return true
	}
	return false
}
func ToMonthStart(t time.Time) time.Time {
	return time.Date(
		t.Year(), t.Month(), 1,
		0, 0, 0, 0,
		t.Location())
}

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

func NewTimeMeta

func NewTimeMeta(dt time.Time, dow time.Weekday) (TimeMeta, error)

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

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(thisTime time.Time, dow time.Weekday) TimeMore

func NewTimeMoreQuarterEndString

func NewTimeMoreQuarterEndString(yyyyqStr string, dow time.Weekday) (TimeMore, error)

func NewTimeMoreQuarterStartString

func NewTimeMoreQuarterStartString(yyyyqStr string, dow time.Weekday) (TimeMore, error)

func (*TimeMore) DOW

func (tm *TimeMore) DOW() time.Weekday

func (*TimeMore) MonthStart

func (tm *TimeMore) MonthStart() time.Time

func (*TimeMore) Quarter

func (tm *TimeMore) Quarter() int32

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) WeekStart

func (tm *TimeMore) WeekStart() 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 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(thisTime time.Time) XOXTimes

Jump to

Keyboard shortcuts

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