Documentation
¶
Index ¶
- Variables
- type Date
- func (d Date) AddDate(years, months, days int) Date
- func (d Date) AddDays(days int) Date
- func (d Date) AddMonths(months int) Date
- func (d Date) AddYears(years int) Date
- func (d Date) After(other Date) bool
- func (d Date) Before(other Date) bool
- func (d Date) BeginOfDay() Date
- func (d Date) BeginOfMonth() Date
- func (d Date) BeginOfQuarter() Date
- func (d Date) BeginOfWeek() Date
- func (d Date) BeginOfYear() Date
- func (d Date) Between(start, end Date) bool
- func (d Date) Day() int
- func (d Date) EndOfDay() Date
- func (d Date) EndOfMonth() Date
- func (d Date) EndOfQuarter() Date
- func (d Date) EndOfWeek() Date
- func (d Date) EndOfYear() Date
- func (d Date) Equal(other Date) bool
- func (d Date) Format(layout string) string
- func (d Date) Friday() Date
- func (d Date) IsZero() bool
- func (d Date) Location() *time.Location
- func (d Date) MarshalJSON() ([]byte, error)
- func (d Date) MarshalText() ([]byte, error)
- func (d Date) Monday() Date
- func (d Date) Month() time.Month
- func (d Date) Saturday() Date
- func (d *Date) Scan(src any) error
- func (d Date) Since() time.Duration
- func (d Date) String() string
- func (d Date) Sub(other Date) time.Duration
- func (d Date) Sunday() Date
- func (d Date) Thursday() Date
- func (d Date) Tuesday() Date
- func (d Date) Unix() int64
- func (d *Date) UnmarshalJSON(bs []byte) error
- func (d *Date) UnmarshalText(text []byte) error
- func (d Date) Until() time.Duration
- func (d Date) Unwrap() time.Time
- func (d Date) Value() (driver.Value, error)
- func (d Date) Wednesday() Date
- func (d Date) Weekday() time.Weekday
- func (d Date) Year() int
- func (d Date) YearDay() int
- type DateTime
- func (dt DateTime) Add(d time.Duration) DateTime
- func (dt DateTime) AddDate(years, months, days int) DateTime
- func (dt DateTime) AddDays(days int) DateTime
- func (dt DateTime) AddHours(hours int) DateTime
- func (dt DateTime) AddMinutes(minutes int) DateTime
- func (dt DateTime) AddMonths(months int) DateTime
- func (dt DateTime) AddSeconds(seconds int) DateTime
- func (dt DateTime) AddYears(years int) DateTime
- func (dt DateTime) After(other DateTime) bool
- func (dt DateTime) Before(other DateTime) bool
- func (dt DateTime) BeginOfDay() DateTime
- func (dt DateTime) BeginOfHour() DateTime
- func (dt DateTime) BeginOfMinute() DateTime
- func (dt DateTime) BeginOfMonth() DateTime
- func (dt DateTime) BeginOfQuarter() DateTime
- func (dt DateTime) BeginOfWeek() DateTime
- func (dt DateTime) BeginOfYear() DateTime
- func (dt DateTime) Between(start, end DateTime) bool
- func (dt DateTime) Day() int
- func (dt DateTime) EndOfDay() DateTime
- func (dt DateTime) EndOfHour() DateTime
- func (dt DateTime) EndOfMinute() DateTime
- func (dt DateTime) EndOfMonth() DateTime
- func (dt DateTime) EndOfQuarter() DateTime
- func (dt DateTime) EndOfWeek() DateTime
- func (dt DateTime) EndOfYear() DateTime
- func (dt DateTime) Equal(other DateTime) bool
- func (dt DateTime) Format(layout string) string
- func (dt DateTime) Friday() DateTime
- func (dt DateTime) Hour() int
- func (dt DateTime) IsZero() bool
- func (dt DateTime) Location() *time.Location
- func (dt DateTime) MarshalJSON() ([]byte, error)
- func (dt DateTime) MarshalText() ([]byte, error)
- func (dt DateTime) Minute() int
- func (dt DateTime) Monday() DateTime
- func (dt DateTime) Month() time.Month
- func (dt DateTime) Nanosecond() int
- func (dt DateTime) Saturday() DateTime
- func (dt *DateTime) Scan(src any) error
- func (dt DateTime) Second() int
- func (dt DateTime) Since() time.Duration
- func (dt DateTime) String() string
- func (dt DateTime) Sub(other DateTime) time.Duration
- func (dt DateTime) Sunday() DateTime
- func (dt DateTime) Thursday() DateTime
- func (dt DateTime) Tuesday() DateTime
- func (dt DateTime) Unix() int64
- func (dt DateTime) UnixMicro() int64
- func (dt DateTime) UnixMilli() int64
- func (dt DateTime) UnixNano() int64
- func (dt *DateTime) UnmarshalJSON(bs []byte) error
- func (dt *DateTime) UnmarshalText(text []byte) error
- func (dt DateTime) Until() time.Duration
- func (dt DateTime) Unwrap() time.Time
- func (dt DateTime) Value() (driver.Value, error)
- func (dt DateTime) Wednesday() DateTime
- func (dt DateTime) Weekday() time.Weekday
- func (dt DateTime) Year() int
- func (dt DateTime) YearDay() int
- type Time
- func (t Time) Add(d time.Duration) Time
- func (t Time) AddHours(hours int) Time
- func (t Time) AddMicroseconds(microseconds int64) Time
- func (t Time) AddMilliseconds(milliseconds int64) Time
- func (t Time) AddMinutes(minutes int) Time
- func (t Time) AddNanoseconds(nanoseconds int64) Time
- func (t Time) AddSeconds(seconds int) Time
- func (t Time) After(other Time) bool
- func (t Time) Before(other Time) bool
- func (t Time) BeginOfHour() Time
- func (t Time) BeginOfMinute() Time
- func (t Time) Between(start, end Time) bool
- func (t Time) EndOfHour() Time
- func (t Time) EndOfMinute() Time
- func (t Time) Equal(other Time) bool
- func (t Time) Format(layout string) string
- func (t Time) Hour() int
- func (t Time) IsZero() bool
- func (t Time) MarshalJSON() ([]byte, error)
- func (t Time) MarshalText() ([]byte, error)
- func (t Time) Minute() int
- func (t Time) Nanosecond() int
- func (t *Time) Scan(src any) error
- func (t Time) Second() int
- func (t Time) String() string
- func (t Time) Sub(other Time) time.Duration
- func (t Time) ToDuration() time.Duration
- func (t *Time) UnmarshalJSON(bs []byte) error
- func (t *Time) UnmarshalText(text []byte) error
- func (t Time) Unwrap() time.Time
- func (t Time) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidDateFormat indicates date format is invalid. ErrInvalidDateFormat = errors.New("invalid date format") // ErrInvalidDateTimeFormat indicates datetime format is invalid. ErrInvalidDateTimeFormat = errors.New("invalid datetime format") // ErrInvalidTimeFormat indicates time format is invalid. ErrInvalidTimeFormat = errors.New("invalid time format") // ErrFailedScan indicates scan target type/value is invalid. ErrFailedScan = errors.New("failed to scan value") // ErrUnsupportedDestType indicates dest type is unsupported. ErrUnsupportedDestType = errors.New("unsupported destination type") )
Functions ¶
This section is empty.
Types ¶
type Date ¶
Date represents a calendar date (year, month, day) without a time-of-day component. It uses the standard time.DateOnly format (2006-01-02).
Date is a civil date: Equal, Before, After, Between, and Sub compare by calendar date and ignore the underlying time.Time location, so two Date values for the same day are equal even when constructed from time.Time values in different zones (e.g. a local literal versus a UTC database row). Sub therefore always returns a whole number of 24-hour days.
func ParseDate ¶
ParseDate parses a date string and returns a Date. First tries with the provided pattern, then falls back to cast.ToTime as a backup.
func (Date) AddDate ¶ added in v0.23.0
AddDate returns the date corresponding to adding the given number of years, months, and days to d, mirroring time.Time.AddDate. Month-end overflow is normalized (e.g. Jan 31 + 1 month → Mar 3).
func (Date) After ¶
After reports whether the calendar date d is after other, regardless of location.
func (Date) Before ¶
Before reports whether the calendar date d is before other, regardless of location.
func (Date) BeginOfDay ¶
BeginOfDay returns the beginning of the day for d (same as the date itself).
func (Date) BeginOfMonth ¶
BeginOfMonth returns the beginning of the month for d.
func (Date) BeginOfQuarter ¶
BeginOfQuarter returns the beginning of the quarter for d.
func (Date) BeginOfWeek ¶
BeginOfWeek returns the beginning of the week (Sunday) for d.
func (Date) BeginOfYear ¶
BeginOfYear returns the beginning of the year for d.
func (Date) Between ¶
Between reports whether d falls strictly between start and end, exclusive of both endpoints (the open interval (start, end)). d equal to start or end returns false.
func (Date) EndOfMonth ¶
EndOfMonth returns the end of the month for d.
func (Date) EndOfQuarter ¶
EndOfQuarter returns the end of the quarter for d.
func (Date) Equal ¶
Equal reports whether d and other are the same calendar date, regardless of location.
func (Date) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface, emitting the canonical DateOnly layout.
func (Date) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Date) Sub ¶
Sub returns the duration d-other as a whole number of 24-hour days, computed on the calendar date and independent of location.
func (Date) Unix ¶
Unix returns d as a Unix time, the number of seconds elapsed since January 1, 1970 UTC.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. It accepts a JSON string in the canonical DateOnly layout; any other shape (including a datetime string) is rejected.
func (*Date) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. Like UnmarshalJSON it is strict: the text must match the canonical DateOnly layout.
type DateTime ¶
DateTime represents a date and time value with database and JSON support. It uses the standard time.DateTime format (2006-01-02 15:04:05).
func FromUnix ¶
FromUnix returns the DateTime corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC.
func FromUnixMicro ¶
FromUnixMicro returns the DateTime corresponding to the given Unix time, usec microseconds since January 1, 1970 UTC.
func FromUnixMilli ¶
FromUnixMilli returns the DateTime corresponding to the given Unix time, msec milliseconds since January 1, 1970 UTC.
func Parse ¶
Parse parses a date time string and returns a DateTime. First tries with the provided pattern, then falls back to cast.ToTime as a backup.
func (DateTime) AddDate ¶
AddDate returns the datetime corresponding to adding the given number of years, months, and days to dt.
func (DateTime) AddMinutes ¶
AddMinutes adds the specified number of minutes to the datetime.
func (DateTime) AddSeconds ¶
AddSeconds adds the specified number of seconds to the datetime.
func (DateTime) BeginOfDay ¶
BeginOfDay returns the beginning of the day for dt.
func (DateTime) BeginOfHour ¶
BeginOfHour returns the beginning of the hour for dt.
func (DateTime) BeginOfMinute ¶
BeginOfMinute returns the beginning of the minute for dt.
func (DateTime) BeginOfMonth ¶
BeginOfMonth returns the beginning of the month for dt.
func (DateTime) BeginOfQuarter ¶
BeginOfQuarter returns the beginning of the quarter for dt.
func (DateTime) BeginOfWeek ¶
BeginOfWeek returns the beginning of the week (Sunday) for dt.
func (DateTime) BeginOfYear ¶
BeginOfYear returns the beginning of the year for dt.
func (DateTime) Between ¶
Between reports whether dt falls strictly between start and end, exclusive of both endpoints (the open interval (start, end)). dt equal to start or end returns false.
func (DateTime) EndOfMinute ¶
EndOfMinute returns the end of the minute for dt.
func (DateTime) EndOfMonth ¶
EndOfMonth returns the end of the month for dt.
func (DateTime) EndOfQuarter ¶
EndOfQuarter returns the end of the quarter for dt.
func (DateTime) IsZero ¶
IsZero reports whether dt represents the zero time instant, January 1, year 1, 00:00:00 UTC.
func (DateTime) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface, emitting the canonical DateTime layout.
func (DateTime) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (DateTime) Minute ¶
Minute returns the minute offset within the hour specified by dt, in the range [0, 59].
func (DateTime) Nanosecond ¶
Nanosecond returns the nanosecond offset within the second specified by dt, in the range [0, 999999999].
func (DateTime) Second ¶
Second returns the second offset within the minute specified by dt, in the range [0, 59].
func (DateTime) String ¶
String returns the string representation using the standard DateTime layout.
func (DateTime) Unix ¶
Unix returns dt as a Unix time, the number of seconds elapsed since January 1, 1970 UTC.
func (DateTime) UnixMicro ¶
UnixMicro returns dt as a Unix time, the number of microseconds elapsed since January 1, 1970 UTC.
func (DateTime) UnixMilli ¶
UnixMilli returns dt as a Unix time, the number of milliseconds elapsed since January 1, 1970 UTC.
func (DateTime) UnixNano ¶
UnixNano returns dt as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC.
func (*DateTime) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. It accepts a JSON string in the canonical DateTime layout; any other shape is rejected.
func (*DateTime) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. Like UnmarshalJSON it is strict: the text must match the canonical DateTime layout.
type Time ¶
Time represents a time-of-day (hour, minute, second, nanosecond) without a date component. It uses the standard time.TimeOnly format (15:04:05).
Time is a civil clock value: Equal, Before, After, Between, and Sub compare by time-of-day and ignore the underlying time.Time location, so two Time values for the same clock reading are equal even when constructed from time.Time values in different zones.
func ParseTime ¶
ParseTime parses a time string and returns a Time. First tries with the provided pattern, then falls back to cast.ToTime as a backup.
func (Time) AddMicroseconds ¶
AddMicroseconds adds the specified number of microseconds to the time.
func (Time) AddMilliseconds ¶
AddMilliseconds adds the specified number of milliseconds to the time.
func (Time) AddMinutes ¶
AddMinutes adds the specified number of minutes to the time.
func (Time) AddNanoseconds ¶
AddNanoseconds adds the specified number of nanoseconds to the time.
func (Time) AddSeconds ¶
AddSeconds adds the specified number of seconds to the time.
func (Time) Before ¶
Before reports whether the time-of-day t is before other, regardless of location.
func (Time) BeginOfHour ¶
BeginOfHour returns the beginning of the hour for t.
func (Time) BeginOfMinute ¶
BeginOfMinute returns the beginning of the minute for t.
func (Time) Between ¶
Between reports whether t falls strictly between start and end, exclusive of both endpoints (the open interval (start, end)). t equal to start or end returns false.
func (Time) EndOfMinute ¶
EndOfMinute returns the end of the minute for t.
func (Time) Equal ¶
Equal reports whether t and other are the same time-of-day, regardless of location.
func (Time) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface, emitting the canonical TimeOnly layout.
func (Time) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Time) Minute ¶
Minute returns the minute offset within the hour specified by t, in the range [0, 59].
func (Time) Nanosecond ¶
Nanosecond returns the nanosecond offset within the second specified by t, in the range [0, 999999999].
func (Time) Second ¶
Second returns the second offset within the minute specified by t, in the range [0, 59].
func (Time) Sub ¶
Sub returns the duration t-other, computed on the time-of-day and independent of location.
func (Time) ToDuration ¶ added in v0.23.0
ToDuration returns the time-of-day expressed as a duration since midnight. Useful for cron-style scheduling and business-hours arithmetic.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. It accepts a JSON string in the canonical TimeOnly layout; any other shape is rejected.
func (*Time) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. Like UnmarshalJSON it is strict: the text must match the canonical TimeOnly layout.