civil

package
v0.1.113 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date struct {
	Year  int
	Month time.Month
	Day   int
}

Date is a calendar day. The zero value is no date: it encodes as JSON null and as SQL NULL.

func DateOf

func DateOf(t time.Time) Date

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 ParseDate

func ParseDate(s string) (Date, error)

ParseDate reads "2026-10-06".

func Today

func Today(now time.Time, loc *time.Location) Date

Today is today's date in loc.

func (Date) AddDays

func (d Date) AddDays(n int) Date

AddDays is the date n days later (earlier for a negative n).

func (Date) After

func (d Date) After(o Date) bool

func (Date) Before

func (d Date) Before(o Date) bool

Before, After and Compare order dates.

func (Date) Compare

func (d Date) Compare(o Date) int

func (Date) DateValue

func (d Date) DateValue() (pgtype.Date, error)

func (Date) DaysUntil

func (d Date) DaysUntil(o Date) int

DaysUntil is how many days from d to o (negative when o is earlier).

func (Date) In

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

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) IsZero

func (d Date) IsZero() bool

IsZero reports whether d is no date.

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON writes "2026-10-06", or null for no date.

func (Date) MarshalText

func (d Date) MarshalText() ([]byte, error)

MarshalText and UnmarshalText serve query strings and form values.

func (*Date) Scan

func (d *Date) Scan(src any) error

Scan and Value serve database/sql.

func (*Date) ScanDate

func (d *Date) ScanDate(v pgtype.Date) error

ScanDate and DateValue let pgx read and write a date column.

func (Date) String

func (d Date) String() string

String is "2026-10-06"; "" for no date.

func (*Date) UnmarshalJSON

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

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

func (d *Date) UnmarshalText(b []byte) error

func (Date) Value

func (d Date) Value() (driver.Value, error)

type DateTime

type DateTime struct {
	Date
	Hour, Minute, Second int
}

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

func ParseDateTime(s string) (DateTime, error)

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

func (dt DateTime) In(loc *time.Location) (t time.Time, skipped bool)

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) IsZero

func (dt DateTime) IsZero() bool

IsZero reports whether dt is none.

func (DateTime) MarshalJSON

func (dt DateTime) MarshalJSON() ([]byte, error)

MarshalJSON writes "2026-10-06T10:30", or null for none.

func (DateTime) MarshalText

func (dt DateTime) MarshalText() ([]byte, error)

MarshalText and UnmarshalText serve query strings and form values.

func (DateTime) String

func (dt DateTime) String() string

String is "2026-10-06T10:30", with ":15" when the seconds are set.

func (*DateTime) UnmarshalJSON

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

UnmarshalJSON reads "2026-10-06T10:30[:15]" or null.

func (*DateTime) UnmarshalText

func (dt *DateTime) UnmarshalText(b []byte) error

Jump to

Keyboard shortcuts

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