dates

package
v0.77.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2020 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ISO8601Date = "2006-01-02"
)

Variables

View Source
var ZeroDate = Date{}

ZeroDate is our uninitialized date value

View Source
var ZeroTimeOfDay = TimeOfDay{}

ZeroTimeOfDay is our uninitialized time of day value

Functions

func DayToUTCRange

func DayToUTCRange(d time.Time, tz *time.Location) (time.Time, time.Time)

DayToUTCRange returns the UTC time range of the given day

func DaysBetween

func DaysBetween(date1 time.Time, date2 time.Time) int

DaysBetween returns the number of calendar days (an int) between the two dates. Note that if these are in different timezones then the local calendar day is used for each and the difference is calculated from that.

func FormatISO

func FormatISO(date time.Time) string

DateTimeToISO converts the passed in time.Time to a string in full ISO8601 format

func MonthsBetween

func MonthsBetween(date1 time.Time, date2 time.Time) int

MonthsBetween returns the number of calendar months (an int) between the two dates. Note that if these are in different timezones then the local calendar day is used for each and the difference is calculated from that.

func Now

func Now() time.Time

Now returns the time now.. according to the current source of now

func SetNowSource

func SetNowSource(source NowSource)

SetNowSource sets the time source used by Now()

Types

type Date

type Date struct {
	Year  int
	Month time.Month
	Day   int
}

Date is a local gregorian calendar date

func ExtractDate

func ExtractDate(dt time.Time) Date

ExtractDate extracts the date from the give datetime

func NewDate

func NewDate(year, month, day int) Date

NewDate creates a new date

func ParseDate

func ParseDate(layout string, value string) (Date, error)

ParseDate parses the given string into a date

func (Date) Combine

func (d Date) Combine(timeOfDay TimeOfDay, tz *time.Location) time.Time

Combine combines this date and a time to make a datetime

func (Date) Compare

func (d Date) Compare(other Date) int

Compare compares this time of day to another

func (Date) Equal

func (d Date) Equal(other Date) bool

Equal determines equality for this type

func (Date) Format

func (d Date) Format(layout string) string

Format formats this date as a string

func (Date) String

func (d Date) String() string

String returns the ISO8601 representation

func (Date) WeekNum added in v0.44.0

func (d Date) WeekNum() int

WeekNum returns the number of the week (1-54)

func (Date) Weekday

func (d Date) Weekday() time.Weekday

Weekday returns the day of the week

func (Date) YearDay added in v0.44.0

func (d Date) YearDay() int

YearDay returns the day of the year (1-366)

type NowSource

type NowSource interface {
	Now() time.Time
}

NowSource is something that can provide a now result

var DefaultNowSource NowSource = defaultNowSource{}

DefaultNowSource is the default time source

func NewFixedNowSource

func NewFixedNowSource(now time.Time) NowSource

NewFixedNowSource creates a new fixed time now source

func NewSequentialNowSource

func NewSequentialNowSource(start time.Time) NowSource

NewSequentialNowSource creates a new sequential time source

type TimeOfDay

type TimeOfDay struct {
	Hour   int
	Minute int
	Second int
	Nanos  int
}

TimeOfDay represents a local time of day value

func ExtractTimeOfDay

func ExtractTimeOfDay(dt time.Time) TimeOfDay

ExtractTimeOfDay extracts the time of day from the give datetime

func NewTimeOfDay

func NewTimeOfDay(hour, minute, second, nanos int) TimeOfDay

NewTimeOfDay creates a new time of day

func ParseTimeOfDay

func ParseTimeOfDay(layout string, value string) (TimeOfDay, error)

ParseTimeOfDay parses the given string into a time of day

func (TimeOfDay) Combine

func (t TimeOfDay) Combine(date Date, tz *time.Location) time.Time

Combine combines this time and a date to make a datetime

func (TimeOfDay) Compare

func (t TimeOfDay) Compare(other TimeOfDay) int

Compare compares this time of day to another

func (TimeOfDay) Equal

func (t TimeOfDay) Equal(other TimeOfDay) bool

Equal determines equality for this type

func (TimeOfDay) Format

func (t TimeOfDay) Format(layout string) string

Format formats this time of day as a string

func (TimeOfDay) String

func (t TimeOfDay) String() string

String returns the ISO8601 representation

Jump to

Keyboard shortcuts

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