Documentation
¶
Overview ¶
Package civil holds dates and times as people write them, with no time zone: Date is a calendar day (a schema.lidza date field, a Postgres date column), DateTime a wall-clock time as a form's date-time input sends it (a schema.lidza localtime field). JSON carries them as written, "2026-10-06" and "2026-10-06T10:30", so no client shifts a day across a time zone on the way.
A DateTime becomes an instant only in a zone: In(loc) resolves it, including the hour a daylight-saving change skips or repeats. The i18n pack does it in the request's zone (i18n.From(ctx).At).
Index ¶
- type Date
- func (d Date) AddDays(n int) Date
- func (d Date) After(o Date) bool
- func (d Date) Before(o Date) bool
- func (d Date) Compare(o Date) int
- func (d Date) DateValue() (pgtype.Date, error)
- func (d Date) DaysUntil(o Date) int
- func (d Date) In(loc *time.Location) time.Time
- 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) ScanDate(v pgtype.Date) error
- func (d Date) String() string
- func (d *Date) UnmarshalJSON(b []byte) error
- func (d *Date) UnmarshalText(b []byte) error
- func (d Date) Value() (driver.Value, error)
- type DateTime
- func (dt DateTime) In(loc *time.Location) (t time.Time, skipped bool)
- func (dt DateTime) IsZero() bool
- func (dt DateTime) MarshalJSON() ([]byte, error)
- func (dt DateTime) MarshalText() ([]byte, error)
- func (dt DateTime) String() string
- func (dt *DateTime) UnmarshalJSON(b []byte) error
- func (dt *DateTime) UnmarshalText(b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Date ¶
Date is a calendar day. The zero value is no date: it encodes as JSON null and as SQL NULL.
func DateOf ¶
DateOf is the calendar day of t, as t's own zone reads it: the day of an instant depends on the zone, so pass t.In(loc) for a person's day.
func (Date) In ¶
In is the start of the day in loc (00:00 there, or the first instant of the day when a daylight-saving change skips midnight).
func (Date) MarshalJSON ¶
MarshalJSON writes "2026-10-06", or null for no date.
func (Date) MarshalText ¶
MarshalText and UnmarshalText serve query strings and form values.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON reads "2026-10-06" or null. A full timestamp ("2026-10-06T00:00:00Z", what releases before this type wrote) is read by its date as written, never shifted to another zone.
func (*Date) UnmarshalText ¶
type DateTime ¶
DateTime is a wall-clock time with no zone: what a person typed into a date-time input. The zero value is none.
func ParseDateTime ¶
ParseDateTime reads "2026-10-06T10:30" or "2026-10-06T10:30:15" (a space instead of the T works too). A zone or offset is refused: such a value is an instant, a time field's.
func (DateTime) In ¶
In is the instant dt names in loc. A daylight-saving change makes two cases: a time the clocks skip (02:30 when they jump from 02:00 to 03:00) is the moment the same distance past the change, 03:30, as most calendars do; a time they pass twice (01:30 when they fall back) is the first of the two. Skipped reports the first case so a form can say so.
func (DateTime) MarshalJSON ¶
MarshalJSON writes "2026-10-06T10:30", or null for none.
func (DateTime) MarshalText ¶
MarshalText and UnmarshalText serve query strings and form values.
func (*DateTime) UnmarshalJSON ¶
UnmarshalJSON reads "2026-10-06T10:30[:15]" or null.