cal

package
v0.205.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 8 Imported by: 7

Documentation

Overview

Package cal provides simple date handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DateAfter

func DateAfter(date Date) validation.Rule

DateAfter returns a validation rule which checks to ensure the date is *after* the provided date.

func DateBefore

func DateBefore(date Date) validation.Rule

DateBefore is used during validation to ensure the date is before the value passed in.

func DateNotZero

func DateNotZero() validation.Rule

DateNotZero ensures the date is not a zero value.

func DateTimeAfter added in v0.56.0

func DateTimeAfter(dt DateTime) validation.Rule

DateTimeAfter returns a validation rule which checks to ensure the date is *after* the provided date.

func DateTimeBefore added in v0.56.0

func DateTimeBefore(dt DateTime) validation.Rule

DateTimeBefore is used during validation to ensure the date is before the value passed in.

func DateTimeNotZero added in v0.56.0

func DateTimeNotZero() validation.Rule

DateTimeNotZero ensures the date is not a zero value.

Types

type Date

type Date struct {
	civil.Date
}

Date represents a simple date without time used most frequently with business documents.

func DateOf added in v0.52.4

func DateOf(t time.Time) Date

DateOf returns the Date in which a time occurs in the time's location.

func MakeDate

func MakeDate(year int, month time.Month, day int) Date

MakeDate provides a new date instance.

func NewDate

func NewDate(year int, month time.Month, day int) *Date

NewDate provides a pointer to a new date instance.

func Today added in v0.40.0

func Today() Date

Today generates a new date instance for today.

func TodayIn added in v0.40.0

func TodayIn(loc *time.Location) Date

TodayIn generates a new date instance for today in the given location.

func (Date) Add added in v0.52.4

func (d Date) Add(years, months, days int) Date

Add returns a new date with the given number of years, months and days. This uses the time package to do the arithmetic.

func (*Date) Clone added in v0.42.2

func (d *Date) Clone() *Date

Clone returns a new pointer to a copy of the date.

func (Date) JSONSchema

func (Date) JSONSchema() *jsonschema.Schema

JSONSchema returns a custom json schema for the date.

func (Date) Time added in v0.52.4

func (d Date) Time() time.Time

Time returns a time object for the date.

func (Date) TimeIn added in v0.52.4

func (d Date) TimeIn(loc *time.Location) time.Time

TimeIn returns a time object for the date in the given location which may be important when considering timezones and arithmetic.

func (*Date) UnmarshalJSON added in v0.39.0

func (d *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON is used to parse a date from json and ensures that we can handle invalid data reasonably.

func (Date) Validate added in v0.39.0

func (d Date) Validate() error

Validate ensures the the date object looks valid.

type DateTime added in v0.56.0

type DateTime struct {
	civil.DateTime
}

DateTime represents a combination of date and time without location specific information nor support for millisecond precision.

func DateTimeOf added in v0.56.0

func DateTimeOf(t time.Time) DateTime

DateTimeOf returns the DateTime from the provided time.

func MakeDateTime added in v0.56.0

func MakeDateTime(year int, month time.Month, day, hour, minute, second int) DateTime

MakeDateTime provides a new date time instance.

func NewDateTime added in v0.56.0

func NewDateTime(year int, month time.Month, day, hour, minute, second int) *DateTime

NewDateTime provides a pointer to a new date time instance.

func ThisSecond added in v0.56.0

func ThisSecond() DateTime

ThisSecond produces a new date time instance for the current UTC time to the nearest second.

func ThisSecondIn added in v0.56.0

func ThisSecondIn(loc *time.Location) DateTime

ThisSecondIn provides a new date time using the current time from the provided location as a reference.

func (*DateTime) Clone added in v0.56.0

func (dt *DateTime) Clone() *DateTime

Clone returns a new pointer to a copy of the date time.

func (DateTime) In added in v0.56.0

func (dt DateTime) In(loc *time.Location) time.Time

In returns a new time.Time instance with the provided location.

func (DateTime) JSONSchema added in v0.56.0

func (DateTime) JSONSchema() *jsonschema.Schema

JSONSchema returns a custom json schema for the date time.

func (DateTime) TimeZ added in v0.56.0

func (dt DateTime) TimeZ() time.Time

TimeZ returns a new time.Time instance with the UTC location.

func (*DateTime) UnmarshalJSON added in v0.56.0

func (dt *DateTime) UnmarshalJSON(data []byte) error

UnmarshalJSON is used to parse a date from json and ensures that we can handle invalid data reasonably.

func (DateTime) Validate added in v0.56.0

func (dt DateTime) Validate() error

Validate ensures the date time object looks valid

type Period

type Period struct {
	// Label is a short description of the period.
	Label string `json:"label,omitempty" jsonschema:"title=Label"`
	// Start indicates when this period starts.
	Start Date `json:"start" jsonschema:"title=Start"`
	// End indicates when the period ends, and must be after the start date.
	End Date `json:"end" jsonschema:"title=End"`
}

Period represents two dates with a start and finish.

func (*Period) Validate

func (p *Period) Validate() error

Validate checks to ensure the period looks correct.

Jump to

Keyboard shortcuts

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