Documentation
¶
Overview ¶
Package cal provides simple date handling.
Index ¶
Constants ¶
const RFC3339Milli = "2006-01-02T15:04:05.000Z"
RFC3339Milli is the canonical marshaling format used by Timestamp: RFC3339 in UTC with a Z suffix and millisecond precision.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Date ¶
Date represents a simple date without time used most frequently with business documents.
func DateOf ¶ added in v0.52.4
DateOf returns the Date in which a time occurs in the time's location.
func TodayIn ¶ added in v0.40.0
TodayIn generates a new date instance for today in the given location.
func (Date) Add ¶ added in v0.52.4
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) JSONSchema ¶
func (Date) JSONSchema() *jsonschema.Schema
JSONSchema returns a custom json schema for the date.
func (Date) TimeIn ¶ added in v0.52.4
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
UnmarshalJSON is used to parse a date from json and ensures that we can handle invalid data reasonably.
type DateTest ¶ added in v0.400.0
type DateTest struct {
// contains filtered or unexported fields
}
DateTest is used to validate a date according to the provided rules.
func DateAfter ¶
DateAfter returns a validation rule which checks to ensure the date is *after* the provided date.
func DateBefore ¶
DateBefore is used during validation to ensure the date is before the value passed in.
func (DateTest) Check ¶ added in v0.400.0
Check will perform the defines date test on the provided value.
type DateTime ¶ added in v0.56.0
DateTime represents a combination of date and time without location specific information nor support for millisecond precision.
func DateTimeOf ¶ added in v0.56.0
DateTimeOf returns the DateTime from the provided time.
func MakeDateTime ¶ added in v0.56.0
MakeDateTime provides a new date time instance.
func NewDateTime ¶ added in v0.56.0
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
ThisSecondIn provides a new date time using the current time from the provided location as a reference.
func (DateTime) In ¶ added in v0.56.0
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
TimeZ returns a new time.Time instance with the UTC location.
func (*DateTime) UnmarshalJSON ¶ added in v0.56.0
UnmarshalJSON is used to parse a date from json and ensures that we can handle invalid data reasonably.
type DateTimeTest ¶ added in v0.400.0
type DateTimeTest struct {
// contains filtered or unexported fields
}
DateTimeTest is used to validate a date time according to the provided rules.
func DateTimeAfter ¶ added in v0.56.0
func DateTimeAfter(dt DateTime) DateTimeTest
DateTimeAfter returns a validation rule which checks to ensure the date time is *after* the provided date time.
func DateTimeBefore ¶ added in v0.56.0
func DateTimeBefore(dt DateTime) DateTimeTest
DateTimeBefore is used during validation to ensure the date time is before the value passed in.
func DateTimeNotZero ¶ added in v0.56.0
func DateTimeNotZero() DateTimeTest
DateTimeNotZero ensures the date time is not a zero value.
func (DateTimeTest) Check ¶ added in v0.400.0
func (d DateTimeTest) Check(value any) bool
Check will perform the defined date time test on the provided value.
func (DateTimeTest) String ¶ added in v0.400.0
func (d DateTimeTest) String() string
String provides a description of the test.
func (DateTimeTest) Validate ¶ added in v0.400.0
func (d DateTimeTest) Validate(value any) error
Validate is used to check a date time's value.
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.
type Time ¶ added in v0.215.0
Time represents a simple time of day without a date component.
func TimeNowIn ¶ added in v0.215.0
TimeNowIn provides the current time of the day in the provided location.
func (Time) IsZero ¶ added in v0.401.0
IsZero returns true if the time is the zero value (00:00:00). This is used by the `omitzero` JSON tag to determine if the time should be omitted from JSON output.
func (Time) JSONSchema ¶ added in v0.215.0
func (Time) JSONSchema() *jsonschema.Schema
JSONSchema returns a custom json schema for the current hour, minute, and seconds of the day.
func (*Time) UnmarshalJSON ¶ added in v0.215.0
UnmarshalJSON is used to parse a time from json and ensures that we can handle invalid data reasonably.
type Timestamp ¶ added in v0.401.0
Timestamp wraps time.Time with JSON serialization in RFC3339 format, always in UTC with a `Z` suffix and millisecond precision. Parsing tolerates optional sub-second precision up to nanoseconds and arbitrary offsets, always normalizing to UTC.
func ParseTimestamp ¶ added in v0.401.0
ParseTimestamp parses an RFC3339 formatted string (sub-second precision optional) and returns it as a UTC Timestamp.
func TimestampNow ¶ added in v0.401.0
func TimestampNow() Timestamp
TimestampNow returns the current time as a UTC Timestamp.
func TimestampOf ¶ added in v0.401.0
TimestampOf returns t as a Timestamp normalized to UTC.
func (Timestamp) JSONSchema ¶ added in v0.401.0
func (Timestamp) JSONSchema() *jsonschema.Schema
JSONSchema returns a custom json schema for the timestamp.
func (Timestamp) MarshalJSON ¶ added in v0.401.0
MarshalJSON emits the timestamp in canonical RFC3339 UTC millisecond format. A zero timestamp is emitted as `null`.
func (Timestamp) String ¶ added in v0.401.0
String provides the timestamp in RFC3339 UTC format with millisecond precision.
func (*Timestamp) UnmarshalJSON ¶ added in v0.401.0
UnmarshalJSON accepts an RFC3339 encoded string (with or without sub-second precision, any offset) or a JSON null.
type TimestampTest ¶ added in v0.401.0
type TimestampTest struct {
// contains filtered or unexported fields
}
TimestampTest is used to validate a timestamp according to the provided rules.
func TimestampAfter ¶ added in v0.401.0
func TimestampAfter(t Timestamp) TimestampTest
TimestampAfter returns a validation rule which checks to ensure the timestamp is *after* the provided timestamp.
func TimestampBefore ¶ added in v0.401.0
func TimestampBefore(t Timestamp) TimestampTest
TimestampBefore is used during validation to ensure the timestamp is before the value passed in.
func TimestampNotZero ¶ added in v0.401.0
func TimestampNotZero() TimestampTest
TimestampNotZero ensures the timestamp is not a zero value.
func (TimestampTest) Check ¶ added in v0.401.0
func (d TimestampTest) Check(value any) bool
Check will perform the defined timestamp test on the provided value.
func (TimestampTest) String ¶ added in v0.401.0
func (d TimestampTest) String() string
String provides a description of the test.
func (TimestampTest) Validate ¶ added in v0.401.0
func (d TimestampTest) Validate(value any) error
Validate is used to check a timestamp's value.