kronos

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package kronos are time utilities.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Between

func Between(start, end time.Time, interval time.Duration) []time.Time

Between returns a slice of Times between the given start and end at each interval. start and end are inclusive. If end is before start, nil is returned. If end is earlier than an interval from start, a slice containing only start is returned.

Example
sta, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
end, _ := time.Parse(time.RFC3339, "2006-01-02T15:05:05Z")
bt := kronos.Between(sta, end, 28*time.Second)
fmt.Println("Len:", len(bt))
for _, t := range bt {
	fmt.Println(t.Format("15:04:05"))
}
Output:

Len: 3
15:04:05
15:04:33
15:05:01

func BetweenDates

func BetweenDates(start, end time.Time, offsetYear, offsetMonth, offsetDay int) []time.Time

BetweenDates returns a slice of Times between the given start and end dates, adding the given years/months/days between each iteration. start and end are inclusive. If end is before start, nil is returned. If end is earlier than an interval after start, a slice containing only start is returned.

Example
start, _ := time.Parse("2006-01-02", "2012-11-22")
end, _ := time.Parse("2006-01-02", "2015-03-06")
bt := kronos.BetweenDates(start, end, 1, 0, 0)
fmt.Println("Len:", len(bt))
for _, t := range bt {
	fmt.Println(t.Format("2006-01-02"))
}
Output:

Len: 3
2012-11-22
2013-11-22
2014-11-22

func BetweenDatesEach

func BetweenDatesEach(start, end time.Time, y, m, d int, each func(time.Time))

BetweenDatesEach calls each for every time between start and end. See BetweenDates for more information.

func BetweenEach

func BetweenEach(start, end time.Time, interval time.Duration, each func(time.Time))

BetweenEach calls each for every time between start and end. See Between for more information.

func Compare

func Compare(t1, t2 time.Time) int

func DaysInMonth

func DaysInMonth(t time.Time) int

DaysInMonth returns the number of days in the month of t.

func RollMonth

func RollMonth(t time.Time, months int) time.Time

RollMonth adds months number of months to t (months can be negative). Unlike Go's time.AddDate, this works on a calendar basis. For example, (October 31).AddDate(0, 1, 0) with Go's time package returns (December 1). RollMonth(October 31, 1) returns (November 30).

func TMax

func TMax(t, u time.Time) time.Time

TMax returns the later of two time instants.

func TMin

func TMin(t, u time.Time) time.Time

TMin returns the earlier of two time instants.

Types

This section is empty.

Jump to

Keyboard shortcuts

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