timeutil

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClock

func AddClock(t time.Time, c Clock) time.Time

AddClock will add the provided number of clock hours to the given time, taking things like DST into account.

func HoursBetween

func HoursBetween(a, b time.Time) int

HoursBetween will return the number of full hours from a to b with respect to clock time and DST.

It is assumed a and b are of the same location.

func NextWeekday

func NextWeekday(t time.Time, w time.Weekday) time.Time

NextWeekday will return t at the start of the next weekday w. The returned value will always be in the future.

func PrevWeekday

func PrevWeekday(t time.Time, w time.Weekday) time.Time

PrevWeekday will return t at the start of the most recent weekday w. The returned value will be identical if it is already the start of the requested weekday.

func StartOfDay

func StartOfDay(t time.Time) time.Time

StartOfDay will return the start of the day in t's location.

Types

type Clock

type Clock time.Duration

Clock represents wall-clock time. It is a duration since midnight.

func ClockDiff

func ClockDiff(a, b time.Time) Clock

ClockDiff will return the amount of clock time from a to b with respect to DST.

It is assumed a and b are of the same location.

func IsDST

func IsDST(t time.Time) (dst bool, at, change Clock)

IsDST will return true if there is a DST change within 24-hours AFTER t.

If so, the clock-time and amount of change is calculated.

func NewClock

func NewClock(hour, minute int) Clock

NewClock returns a Clock value equal to the provided 24-hour value and minute.

func NewClockFromTime

func NewClockFromTime(t time.Time) Clock

NewClockFromTime will return the Clock value of the provided time.

func ParseClock

func ParseClock(value string) (Clock, error)

ParseClock will return a new Clock value given a value in the format of '15:04' or '15:04:05'. The resulting value will be truncated to the minute.

func (Clock) Days

func (c Clock) Days() (int, Clock)

Days will return the number of whole days and the remainder Clock value.

func (Clock) FirstOfDay

func (c Clock) FirstOfDay(t time.Time) time.Time

FirstOfDay will return the first timestamp where the time matches the clock value, or the first instant after, if it does not exist.

func (Clock) Format

func (c Clock) Format(layout string) string

Format will format the clock value using the same format string used by time.Time.

func (Clock) Hour

func (c Clock) Hour() int

Hour returns the hour of the Clock value.

func (Clock) Is

func (c Clock) Is(t time.Time) bool

Is returns true if t represents the same clock time.

func (Clock) LastOfDay

func (c Clock) LastOfDay(t time.Time) time.Time

LastOfDay will return the last timestamp where the time matches the clock value, or the first instant after, if it does not exist.

func (Clock) MarshalGQL added in v0.28.0

func (c Clock) MarshalGQL(w io.Writer)

func (Clock) MarshalText added in v0.28.0

func (c Clock) MarshalText() ([]byte, error)

func (Clock) Minute

func (c Clock) Minute() int

Minute returns the minute of the Clock value.

func (*Clock) Scan

func (c *Clock) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (Clock) String

func (c Clock) String() string

String returns a string representation of the format '15:04'.

func (*Clock) UnmarshalGQL added in v0.28.0

func (c *Clock) UnmarshalGQL(v interface{}) error

func (*Clock) UnmarshalText added in v0.28.0

func (c *Clock) UnmarshalText(data []byte) error

func (Clock) Value

func (c Clock) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type WeekdayFilter added in v0.28.0

type WeekdayFilter [7]byte

func EveryDay added in v0.28.0

func EveryDay() WeekdayFilter

EveryDay returns a WeekdayFilter that is permanently active.

func (WeekdayFilter) Day added in v0.28.0

func (f WeekdayFilter) Day(d time.Weekday) bool

Day will return true if the given weekday is enabled.

func (WeekdayFilter) DaysSince added in v0.28.0

func (f WeekdayFilter) DaysSince(d time.Weekday, enabled bool) int

DaysSince will give the number of days since an enabled day from the given weekday. -1 is returned if all days are disabled.

func (WeekdayFilter) DaysUntil added in v0.28.0

func (f WeekdayFilter) DaysUntil(d time.Weekday, enabled bool) int

DaysUntil will give the number of days until a matching day from the given weekday. -1 is returned if no days match.

func (WeekdayFilter) IsAlways added in v0.28.0

func (f WeekdayFilter) IsAlways() bool

func (WeekdayFilter) IsNever added in v0.28.0

func (f WeekdayFilter) IsNever() bool

func (WeekdayFilter) MarshalGQL added in v0.28.0

func (f WeekdayFilter) MarshalGQL(w io.Writer)

func (WeekdayFilter) MarshalText added in v0.28.0

func (f WeekdayFilter) MarshalText() ([]byte, error)

func (WeekdayFilter) NextActive added in v0.28.0

func (f WeekdayFilter) NextActive(t time.Time) time.Time

NextActive returns the next time, at midnight, from t that is active.

If the filter is active every day or no days, zero time is returned. Otherwise the returned value will always be in the future.

func (WeekdayFilter) NextInactive added in v0.28.0

func (f WeekdayFilter) NextInactive(t time.Time) time.Time

NextInactive returns the next time, at midnight, from t that is no longer active.

If the filter is active every day or no days, zero time is returned. Otherwise the returned value will always be in the future.

func (*WeekdayFilter) Scan added in v0.28.0

func (f *WeekdayFilter) Scan(src interface{}) error

Scan scans the WeekdayFilter from a DB array of bool.

func (*WeekdayFilter) SetDay added in v0.28.0

func (f *WeekdayFilter) SetDay(d time.Weekday, enabled bool)

SetDay will update the filter for the given weekday.

func (WeekdayFilter) StartTime added in v0.28.0

func (f WeekdayFilter) StartTime(t time.Time) time.Time

StartTime returns midnight of the day the filter became active, from the perspective of t.

If the filter is active every day or no days, zero time is returned. If the current day is not active, zero time is returned.

func (WeekdayFilter) String added in v0.28.0

func (f WeekdayFilter) String() string

String returns a string representation of the WeekdayFilter.

func (*WeekdayFilter) UnmarshalGQL added in v0.28.0

func (f *WeekdayFilter) UnmarshalGQL(v interface{}) error

func (*WeekdayFilter) UnmarshalText added in v0.28.0

func (f *WeekdayFilter) UnmarshalText(data []byte) error

func (WeekdayFilter) Value added in v0.28.0

func (f WeekdayFilter) Value() (driver.Value, error)

Value converts the WeekdayFilter to a DB array of bool.

Jump to

Keyboard shortcuts

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