timeutil

package
v0.63.9 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 15 Imported by: 85

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 (
	Day         = 24 * time.Hour
	Week        = 7 * Day
	WorkDay     = 8 * time.Hour
	WorkWeek    = 5 * WorkDay
	WorkDay996  = 12 * time.Hour
	WorkWeek996 = 6 * WorkDay996

	HoursPerDay = float32(24)
	DaysPerWeek = float32(7)

	DaySeconds  = 24 * 60 * 60
	WeekSeconds = 7 * DaySeconds
	YearSeconds = (365 * DaySeconds) + (6 * 60 * 60)

	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"
	DIN5008FullDate    = "02.01.2006" // German DIN 5008 standard
	DIN5008Date        = "02.01.06"
	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"
	ISO9075            = "2006-01-02 15:04:05"           // ISO/IEC 9075 used by MySQL, BigQuery, etc.
	ISO9075MicroTZ     = "2006-01-02 15:04:05.999999-07" // ISO/IEC 9075 used by PostgreSQL
	// SQLTimestamp     = "2006-01-02 15:04:05"           // ISO/IEC 9075 used by MySQL, BigQuery, etc.
	// SQLTimestampPgTz = "2006-01-02 15:04:05.999999-07" // ISO/IEC 9075 used by PostgreSQL
	Ruby              = "2006-01-02 15:04:05 -0700" // Ruby Time.now.to_s
	InsightlyAPIQuery = "_1/_2/2006 _3:04:05 PM"
	DateMDY           = "1/2/2006" // an underscore results in a space.
	DateMDYSlash      = "01/02/2006"
	DateDMYDash       = "_2-01-2006"     // Jira XML Date format
	DateDMYHM2        = "02:01:06 15:04" // GMT time in format dd:mm:yy hh:mm
	DateYMD           = RFC3339FullDate
	DateTextUS        = "January _2, 2006"
	DateTextUSAbbr3   = "Jan _2, 2006"
	DateTextEU        = "_2 January 2006"
	DateTextEUAbbr3   = "_2 Jan 2006"
)

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 (
	LayoutNameDT4  = "dt4"
	LayoutNameDT6  = "dt6"
	LayoutNameDT8  = "dt8"
	LayoutNameDT14 = "dt14"
)
View Source
const (
	NanosecondString  = "naonsecond"
	MicrosecondString = "microsecond"
	MillisecondString = "millisecond"
	SecondString      = "second"
	MinuteString      = "minute"
	HourString        = "hour"
	DayString         = "day"
	WeekString        = "week"
	MonthString       = "month"
	QuarterString     = "quarter"
	HalfYearString    = "halfyear"
	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 ErrDateTime8Invalid = errors.New("timeutil.datetime8: invalid value")
View Source
var ErrDateTime8OutOfBounds = errors.New("datetime8: time.Time is out of bounds")
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 CanonicalMonthMap added in v0.63.8

func CanonicalMonthMap() map[string][]string

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 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 DurationStringMinutesSeconds

func DurationStringMinutesSeconds(durationSeconds int64) (string, error)

func DurationWeeks added in v0.53.0

func DurationWeeks(d time.Duration) float64

func DurationYears

func DurationYears(d time.Duration) float64

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 IsDTX added in v0.50.0

func IsDTX(d int32) (string, error)

IsDTX returns the dtx format if conformant to various DTX values (dt4, dt6, dt8, dt14).

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 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, nsec int) time.Duration

func NewDurationFloat added in v0.51.0

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

func NewDurationStrings

func NewDurationStrings(hour, min, sec 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 ParseTimeCanonical added in v0.63.8

func ParseTimeCanonical(layout, value string) (time.Time, error)

func ParseTimeCanonicalFunc added in v0.63.8

func ParseTimeCanonicalFunc(layout string) func(s 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 Yearquarter) time.Month

QuarterToMonth converts a calendar quarter to a month.

func QuartersInt32RelToAbs

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

QuartersInt32RelToAbs is useful relative date queries.

func ReplaceMonthCanonical added in v0.63.8

func ReplaceMonthCanonical(s string) string

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 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 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 DateTime8 added in v0.51.0

type DateTime8 uint32

DateTime8 represents a datetime `int32` value in the `yyyymmdd` format. It supports dates from 1000-01-01 to 9999-12-31.

func DT8ParseString added in v0.51.0

func DT8ParseString(layout, value string) (DateTime8, error)

DT8ParseString returns a `DateTime8` value given a layout and value to parse to time.Parse.

func DT8ParseUints added in v0.51.0

func DT8ParseUints(yyyy, mm, dd uint) (DateTime8, error)

DT8ParseUints returns a `DateTime8` value for year, month, and day.

func (DateTime8) Format added in v0.51.0

func (dt8 DateTime8) Format(layout string, loc *time.Location) (string, error)

func (DateTime8) Split added in v0.51.0

func (dt8 DateTime8) Split() (uint32, uint32, uint32)

func (DateTime8) SubTime added in v0.51.0

func (dt8 DateTime8) SubTime(u time.Time, loc *time.Location) (time.Duration, error)

Sub returns the duration dt8-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute dt8-d for a duration d, use t.Add(-d).

func (DateTime8) Time added in v0.51.0

func (dt8 DateTime8) Time(loc *time.Location) (time.Time, error)

func (*DateTime8) UnmarshalJSON added in v0.51.0

func (dt8 *DateTime8) UnmarshalJSON(data []byte) error

func (DateTime8) Validate added in v0.51.0

func (dt8 DateTime8) Validate() error

type DateTime8UnmarshalError added in v0.51.0

type DateTime8UnmarshalError struct {
	Msg string
}

func (*DateTime8UnmarshalError) Error added in v0.51.0

func (e *DateTime8UnmarshalError) Error() string

type DurationInfo

type DurationInfo struct {
	DaysPerWeek  float32
	HoursPerDay  float32
	Weeks        int64
	Days         int64
	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(d time.Duration, daysPerWeek, hoursPerDay float32) DurationInfo

NewDurationInfo returns a DurationInfo struct for a duration in nanos. If 'daysPerWeek` or `hoursPerDay` are set to zero, the default values of 7 and 24 are used.

func ParseDurationInfo added in v0.52.0

func ParseDurationInfo(s string) (DurationInfo, error)

ParseDurationInfo converts a Jira human readable string into a `DurationInfo` struct.

func (DurationInfo) Duration

func (di DurationInfo) Duration(hoursPerDay, daysPerWeek float32) time.Duration

Duration returns a `time.Duration` struct. Params for `hoursPerDay` and `daysPerWeek` are used for atlernate values such as working hours per day and working days per week, e.g. 8 hours per day and 5 days per week.

type DurationInfoString added in v0.56.0

type DurationInfoString struct {
	DaysPerWeek  float32
	HoursPerDay  float32
	Weeks        string
	Days         string
	Hours        string
	Minutes      string
	Seconds      string
	Milliseconds string
	Microseconds string
	Nanoseconds  string
}

DurationInfoString represets a set of time duration data. It is useful for converting parsed time data into a `time.Duration` struct. `DaysPerWeek` and `HoursPerDay` are provided as overrides to standard value of 7 and 24 in the case of business context, e.g. 5 days per week and 8 hours per day.

func (DurationInfoString) Duration added in v0.56.0

func (dis DurationInfoString) Duration() (time.Duration, error)

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 (
	IntervalNanosecond Interval = iota
	IntervalMicrosecond
	IntervalMillisecond
	IntervalSecond
	IntervalMinute
	IntervalHour
	IntervalDay
	IntervalWeek
	IntervalMonth
	IntervalQuarter
	IntervalHalfYear
	IntervalYear
	IntervalDecade
	IntervalScore
	IntervalCentury
	IntervalMillennia
)

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() (DateTime8, error)

Dt8ForTime returns a `DateTime8` 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) HalfYear added in v0.62.2

func (tm TimeMore) HalfYear() uint8

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) QuarterCalendar added in v0.62.1

func (tm TimeMore) QuarterCalendar() Yearquarter

QuarterCalendar returns the quarter of the year specified by tm.Time.

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) SeasonMeteorological added in v0.62.1

func (tm TimeMore) SeasonMeteorological() Yearquarter

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) YearHalf added in v0.62.2

func (tm TimeMore) YearHalf() string

YearHalf returns a string in the format of "2006H1"

func (TimeMore) YearMonth added in v0.62.2

func (tm TimeMore) YearMonth() string

YearMonth returns a string in the format of "2006M1"

func (TimeMore) YearQuarter added in v0.62.2

func (tm TimeMore) YearQuarter() string

YearQuarter returns a string in the format of "2006Q1"

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
	MinSet bool
	MaxSet bool
}

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

func ParseTimeRangeInterval added in v0.62.0

func ParseTimeRangeInterval(s string) (TimeRange, error)

ParseTimeRangeInterval takes a string in the form of `YYYY[MQHX]XX`.

func (*TimeRange) Contains added in v0.62.0

func (tr *TimeRange) Contains(t time.Time, inclusiveMin, inclusiveMax bool) (bool, error)

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

type Yearquarter added in v0.62.1

type Yearquarter uint8

A Yearquarter specifies a quarter of the year (Winter = 1, ...).

const (
	Winter Yearquarter = 1 + iota
	Spring
	Summer
	Autumn
)

func MonthToQuarter

func MonthToQuarter(month time.Month) Yearquarter

MonthToQuarter converts a month to a calendar quarter.

Jump to

Keyboard shortcuts

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