Documentation
¶
Overview ¶
Package timekit is a collection of time related helpers
Deprecated: not deprecated, but experimental, API is subject to changes.
Index ¶
- Constants
- func DayDiff(ref, target time.Time) int
- func EnableTimeEnum() func()
- func MonthDiff(ref, target time.Month) int
- func Months() []time.Month
- func ShiftMonth(m time.Month, n int) time.Month
- func ShiftWeekday(wd time.Weekday, d int) time.Weekday
- func ToDate(ref time.Time) (year int, month time.Month, day int, tz *time.Location)
- func WeekdayDiff(ref, target time.Weekday) int
- func Weekdays() []time.Weekday
- type DayTime
- type Duration
- func (d Duration) Add(o Duration) Duration
- func (d Duration) AddDuration(duration time.Duration) Duration
- func (d Duration) AddTo(t time.Time) time.Time
- func (Duration) Between(from, till time.Time) Duration
- func (Duration) ByDuration(duration time.Duration) Duration
- func (d Duration) Compare(o Duration) int
- func (d Duration) IsZero() bool
- func (d Duration) Iter() iter.Seq[time.Duration]
- func (Duration) Parse(raw string) (Duration, error)
- func (d Duration) String() string
- type Interval
- type Monthly
- type Range
- type Schedule
Examples ¶
Constants ¶
const ErrParseDuration errorkit.Error = "ErrParseDuration"
Variables ¶
This section is empty.
Functions ¶
func DayDiff ¶
DayDiff returns the difference in days between two times, truncating each to midnight before comparison.
func EnableTimeEnum ¶
func EnableTimeEnum() func()
func MonthDiff ¶
MonthDiff calculates the number of months between ref and target. It assumes a cyclic nature, meaning that if target is before ref in the year, it wraps around after December.
Example ¶
package main
import (
"time"
"go.llib.dev/frameless/pkg/timekit"
)
func main() {
_ = timekit.MonthDiff(time.January, time.January) // 0
_ = timekit.MonthDiff(time.January, time.February) // 1
_ = timekit.MonthDiff(time.January, time.March) // 2
_ = timekit.MonthDiff(time.January, time.April) // 3
_ = timekit.MonthDiff(time.January, time.May) // 4
_ = timekit.MonthDiff(time.January, time.June) // 5
_ = timekit.MonthDiff(time.January, time.July) // 6
_ = timekit.MonthDiff(time.January, time.August) // 7
_ = timekit.MonthDiff(time.January, time.September) // 8
_ = timekit.MonthDiff(time.January, time.October) // 9
_ = timekit.MonthDiff(time.January, time.November) // 10
_ = timekit.MonthDiff(time.January, time.December) // 11
_ = timekit.MonthDiff(time.December, time.January) // 1
_ = timekit.MonthDiff(time.October, time.January) // 3
}
func WeekdayDiff ¶
WeekdayDiff calculates the number of days between ref and target. It assumes a cyclic nature, meaning that if target is before ref in the week, it wraps around after Sunday.
Example ¶
package main
import (
"time"
"go.llib.dev/frameless/pkg/timekit"
)
func main() {
_ = timekit.WeekdayDiff(time.Monday, time.Monday) // 0
_ = timekit.WeekdayDiff(time.Monday, time.Tuesday) // 1
_ = timekit.WeekdayDiff(time.Monday, time.Wednesday) // 2
_ = timekit.WeekdayDiff(time.Monday, time.Thursday) // 3
_ = timekit.WeekdayDiff(time.Monday, time.Friday) // 4
_ = timekit.WeekdayDiff(time.Monday, time.Saturday) // 5
_ = timekit.WeekdayDiff(time.Monday, time.Sunday) // 6
}
Types ¶
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration allows to describe distances between two time point, that normally would not be possible with time.Duration.
Example ¶
package main
import (
"time"
"go.llib.dev/frameless/pkg/timekit"
)
func main() {
var d timekit.Duration
d = d.Between(time.Now(), time.Now().AddDate(1000, 0, 0)) // 1000 years worth of duration relative to time now.
_ = d.String()
}
type Schedule ¶
type Schedule struct {
// DayTime is the time during a day, where the scheduling begins.
DayTime DayTime
// Duration is length of the scheduling.
Duration time.Duration
// Month defines for which month the AvailabilityPolicy is meant for.
Months []time.Month
// Day defines for which day the AvailabilityPolicy is meant for.
Days []int
// Weekday defines if the policy is meant for a given day, or for any day of the week.
// if nil, then it is interpreted as unbound.
Weekdays []time.Weekday
// Location of the AvailabilityPolicy.
// When no Location set, then Product specific configuration is expected.
Location *time.Location
}
Schedule allows to define an abstract time, that continously reoccurs in time based on the specifications set in its field.