Documentation
¶
Overview ¶
Package civiltime represents calendar values that do not identify a unique instant. Use DateTime.In only at a boundary where a location is known.
Index ¶
- Variables
- type Date
- func (d Date) AddDays(n int) Date
- func (d Date) AddMonths(n int) Date
- func (d Date) After(other Date) bool
- func (d Date) Before(other Date) bool
- func (d Date) Compare(other Date) int
- func (d Date) In(loc *stdtime.Location) stdtime.Time
- func (d Date) IsValid() bool
- func (d Date) IsZero() bool
- func (d Date) MarshalJSON() ([]byte, error)
- func (d Date) MarshalText() ([]byte, error)
- func (d *Date) Scan(src any) error
- func (d Date) String() string
- func (d *Date) UnmarshalJSON(data []byte) error
- func (d *Date) UnmarshalText(data []byte) error
- func (d Date) Value() (driver.Value, error)
- func (d Date) Weekday() stdtime.Weekday
- type DateTime
- func (dt DateTime) Add(d stdtime.Duration) DateTime
- func (dt DateTime) AddDays(n int) DateTime
- func (dt DateTime) AddMonths(n int) DateTime
- func (dt DateTime) After(other DateTime) bool
- func (dt DateTime) Before(other DateTime) bool
- func (dt DateTime) Compare(other DateTime) int
- func (dt DateTime) In(loc *stdtime.Location) stdtime.Time
- func (dt DateTime) IsValid() bool
- func (dt DateTime) IsZero() bool
- func (dt DateTime) MarshalJSON() ([]byte, error)
- func (dt DateTime) MarshalText() ([]byte, error)
- func (dt *DateTime) Scan(src any) error
- func (dt DateTime) String() string
- func (dt DateTime) Sub(other DateTime) stdtime.Duration
- func (dt *DateTime) UnmarshalJSON(data []byte) error
- func (dt *DateTime) UnmarshalText(data []byte) error
- func (dt DateTime) Value() (driver.Value, error)
- type NullDate
- type NullDateTime
- type NullTime
- type Time
- func (t Time) After(other Time) bool
- func (t Time) Before(other Time) bool
- func (t Time) Compare(other Time) int
- func (t Time) IsValid() bool
- func (t Time) IsZero() bool
- func (t Time) MarshalJSON() ([]byte, error)
- func (t Time) MarshalText() ([]byte, error)
- func (t *Time) Scan(src any) error
- func (t Time) String() string
- func (t *Time) UnmarshalJSON(data []byte) error
- func (t *Time) UnmarshalText(data []byte) error
- func (t Time) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidDate reports a date with an impossible calendar value. ErrInvalidDate = errors.New("civiltime: invalid date") // ErrInvalidTime reports a time with an impossible clock value. ErrInvalidTime = errors.New("civiltime: invalid time") // ErrInvalidDateTime reports a DateTime containing an invalid Date or Time. ErrInvalidDateTime = errors.New("civiltime: invalid datetime") // ErrNull reports an attempt to scan or unmarshal null into a non-nullable value. ErrNull = errors.New("civiltime: null is not allowed") )
Functions ¶
This section is empty.
Types ¶
type Date ¶
Date is a calendar date without location or clock-time information. Valid years range from 0 to 9999; the zero value is not a valid date.
func (Date) AddDays ¶
AddDays returns d shifted by n calendar days. Invalid dates are returned unchanged. Results outside years 0 through 9999 are invalid; check IsValid before use.
func (Date) AddMonths ¶
AddMonths returns d shifted by n calendar months. If the target month has fewer days, the result is clamped to that month's last day. Invalid inputs are returned unchanged. Results outside years 0 through 9999 are invalid; check IsValid before use.
func (Date) In ¶
In returns midnight on d in loc. It panics when d or loc is invalid. Missing or repeated midnights follow time.Date, which may return a different civil date and does not guarantee which offset is chosen at a transition.
func (Date) IsZero ¶
IsZero reports whether d is its zero value. The zero value is not a valid date.
func (Date) MarshalJSON ¶
MarshalJSON encodes d as a JSON string.
func (Date) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Date) Scan ¶
Scan implements database/sql.Scanner. SQL NULL is rejected; use a nullable database field type when NULL is part of the schema.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON date string. null is rejected.
func (*Date) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type DateTime ¶
DateTime combines a Date and a Time without location information. It does not identify a unique instant until converted with In.
func DateTimeOf ¶
DateTimeOf extracts the civil date and time in t's location.
func ParseDateTime ¶
ParseDateTime parses YYYY-MM-DDTHH:MM:SS[.fraction]. A lower-case t or a space is also accepted for database text formats.
func (DateTime) Add ¶
Add returns dt shifted by d. The arithmetic uses fixed 24-hour civil days; no timezone or daylight-saving rule is involved. Invalid inputs are returned unchanged. Results outside years 0 through 9999 are invalid; check IsValid before use.
func (DateTime) AddDays ¶
AddDays returns dt shifted by n calendar days. Invalid values are returned unchanged. Results outside years 0 through 9999 are invalid; check IsValid before use.
func (DateTime) AddMonths ¶
AddMonths returns dt shifted by n calendar months while preserving its time. Invalid inputs are returned unchanged. Results outside years 0 through 9999 are invalid; check IsValid before use.
func (DateTime) In ¶
In converts dt to a time in loc. The conversion is explicit because dt has no timezone of its own; DST rules are therefore applied by time.Date. Missing or repeated local times follow time.Date, which may change the civil fields and does not guarantee which offset is chosen at a transition. A field-preserving round trip does not prove that the local time is unique. In panics if dt is invalid or loc is nil.
func (DateTime) MarshalJSON ¶
MarshalJSON encodes dt as a JSON string.
func (DateTime) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*DateTime) Scan ¶
Scan implements database/sql.Scanner. A time.Time is read by its calendar fields; its location and offset are deliberately ignored.
func (DateTime) String ¶
String returns dt in canonical YYYY-MM-DDTHH:MM:SS[.fraction] form, or <invalid-datetime>.
func (DateTime) Sub ¶
Sub returns the civil-time difference dt-other. Invalid values return zero. Like time.Time.Sub, an unrepresentable result is saturated to the limits of time.Duration.
func (*DateTime) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON datetime string. null is rejected.
func (*DateTime) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type NullDate ¶
NullDate represents a Date that may be SQL NULL or JSON null.
func (NullDate) MarshalJSON ¶
MarshalJSON encodes an invalid NullDate as JSON null.
func (*NullDate) UnmarshalJSON ¶
UnmarshalJSON decodes a date string or JSON null.
type NullDateTime ¶
NullDateTime represents a DateTime that may be SQL NULL or JSON null.
func (NullDateTime) MarshalJSON ¶
func (n NullDateTime) MarshalJSON() ([]byte, error)
MarshalJSON encodes an invalid NullDateTime as JSON null.
func (*NullDateTime) Scan ¶
func (n *NullDateTime) Scan(src any) error
Scan implements database/sql.Scanner.
func (NullDateTime) String ¶
func (n NullDateTime) String() string
String returns the datetime or an empty string when invalid.
func (*NullDateTime) UnmarshalJSON ¶
func (n *NullDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a datetime string or JSON null.
type NullTime ¶
NullTime represents a Time that may be SQL NULL or JSON null.
func (NullTime) MarshalJSON ¶
MarshalJSON encodes an invalid NullTime as JSON null.
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON decodes a time string or JSON null.
type Time ¶
Time is a wall-clock time without location information.
func (Time) MarshalJSON ¶
MarshalJSON encodes t as a JSON string.
func (Time) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON time string. null is rejected.
func (*Time) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sqladapter adapts domain values to database/sql.
|
Package sqladapter adapts domain values to database/sql. |