Documentation
¶
Overview ¶
Package types provides nullable wrappers and not-null helpers for values that must travel through both database/sql and JSON.
Every wrapper implements sql.Scanner and driver.Valuer so the types can be used directly with sql.Row.Scan and db.Exec, and every wrapper implements json.Marshaler / json.Unmarshaler with a canonical shape: an invalid value marshals to null, a valid one to its documented string form (for example "2006-01-02" for Date/NullDate). Each type exposes an IsEmpty method (see Emptiable) and a ToString method (see ToStringAble) that returns "" when the value is NULL.
The package is organised around pairs that share a single serializer/parser:
- Date / NullDate — calendar date ("2006-01-02" or "02.01.2006" on input; always "2006-01-02" on output).
- LocalDateTime / NullLocalDateTime — wall-clock date-time without a timezone ("2006-01-02T15:04:05[.fff…]").
- OffsetDateTime / NullOffsetDateTime — date-time with an offset ("2006-01-02T15:04:05[.fff…]Z" or "±HH:MM").
- LocalTime / NullLocalTime — wall-clock time of day without a timezone ("15:04:05[.fff…]").
- OffsetTime / NullOffsetTime — time of day with an offset ("15:04:05[.fff…]Z" or "±HH:MM").
Additional nullable wrappers cover primitive types: NullString, NullBool, NullInt16/32/64, NullFloat, NullDecimal and NullUUID.
Nullable types accept the JSON token null on UnmarshalJSON and SQL NULL on Scan; their not-null counterparts reject both. Scan delegates to the corresponding sql.Null* wrapper so that typed nils from database drivers are honoured.
Index ¶
- Constants
- func AssembleDateTime(dateValue *time.Time, timeValue *time.Time, location *time.Location) *time.Time
- func AssembleDateTimeTZ(dateValue *time.Time, timeValue *time.Time, timeZone string) (*time.Time, error)
- func AssembleNullDateTimeTZ(dateValue *NullDate, defaultDate *time.Time, timeValue *NullOffsetTime, ...) (*time.Time, error)
- func DateTimeToString(t time.Time) string
- func DateToString(date time.Time) string
- func GetNullString(s sql.NullString) string
- func IsEmpty(t interface{}) bool
- func MaxDateTime(dt1, dt2 time.Time) time.Time
- func MinDateTime(dt1, dt2 time.Time) time.Time
- func NSFromString(s string) sql.NullString
- func ParseDateFromString(strValue string) (*time.Time, error)
- func ParseDateTimeFromString(strValue string) (*time.Time, error)
- func ParseTimeFromString(strValue string) (*time.Time, error)
- func ParseTimezoneExtended(strValue string) (*time.Location, string, error)
- func ToString(val interface{}) string
- type Date
- func (thisVal Date) Add(d time.Duration) Date
- func (thisVal Date) AddDate(years, months, days int) Date
- func (thisVal Date) After(other Date) bool
- func (thisVal Date) AsTime() time.Time
- func (thisVal Date) Before(other Date) bool
- func (thisVal Date) Compare(other Date) int
- func (thisVal Date) Day() int
- func (thisVal Date) Equal(other Date) bool
- func (thisVal Date) MarshalJSON() ([]byte, error)
- func (thisVal Date) Month() time.Month
- func (thisVal *Date) Scan(value interface{}) error
- func (thisVal Date) Sub(other Date) time.Duration
- func (thisVal Date) ToString() string
- func (thisVal Date) Unix() int64
- func (thisVal Date) UnixMicro() int64
- func (thisVal Date) UnixMilli() int64
- func (thisVal Date) UnixNano() int64
- func (thisVal *Date) UnmarshalJSON(data []byte) error
- func (thisVal Date) Value() (driver.Value, error)
- func (thisVal Date) Year() int
- func (thisVal Date) YearDay() int
- type Emptiable
- type LocalDateTime
- func (thisVal LocalDateTime) Add(d time.Duration) LocalDateTime
- func (thisVal LocalDateTime) AddDate(years, months, days int) LocalDateTime
- func (thisVal LocalDateTime) After(other LocalDateTime) bool
- func (thisVal LocalDateTime) Before(other LocalDateTime) bool
- func (thisVal LocalDateTime) Compare(other LocalDateTime) int
- func (thisVal LocalDateTime) Equal(other LocalDateTime) bool
- func (thisVal LocalDateTime) MarshalJSON() ([]byte, error)
- func (thisVal *LocalDateTime) Scan(value interface{}) error
- func (thisVal LocalDateTime) Sub(other LocalDateTime) time.Duration
- func (thisVal LocalDateTime) ToString() string
- func (thisVal LocalDateTime) ToTime(loc *time.Location) time.Time
- func (thisVal LocalDateTime) Truncate(d time.Duration) LocalDateTime
- func (thisVal *LocalDateTime) UnmarshalJSON(data []byte) error
- func (thisVal LocalDateTime) Value() (driver.Value, error)
- func (thisVal LocalDateTime) YearDay() int
- type LocalTime
- func (thisVal LocalTime) Add(d time.Duration) LocalTime
- func (thisVal LocalTime) After(other LocalTime) bool
- func (thisVal LocalTime) Before(other LocalTime) bool
- func (thisVal LocalTime) Compare(other LocalTime) int
- func (thisVal LocalTime) Equal(other LocalTime) bool
- func (thisVal LocalTime) MarshalJSON() ([]byte, error)
- func (thisVal *LocalTime) Scan(value interface{}) error
- func (thisVal LocalTime) Sub(other LocalTime) time.Duration
- func (thisVal LocalTime) ToString() string
- func (thisVal LocalTime) ToTime() time.Time
- func (thisVal LocalTime) Truncate(d time.Duration) LocalTime
- func (thisVal *LocalTime) UnmarshalJSON(data []byte) error
- func (thisVal LocalTime) Value() (driver.Value, error)
- type NullBool
- func (thisVal *NullBool) IsEmpty() bool
- func (thisVal NullBool) IsZero() bool
- func (thisVal NullBool) MarshalJSON() ([]byte, error)
- func (thisVal *NullBool) Scan(value interface{}) error
- func (thisVal NullBool) ToString() string
- func (thisVal *NullBool) UnmarshalJSON(data []byte) error
- func (thisVal NullBool) Value() (driver.Value, error)
- type NullDate
- func (thisVal NullDate) Add(d time.Duration) NullDate
- func (thisVal NullDate) AddDate(years, months, days int) NullDate
- func (thisVal NullDate) After(other NullDate) bool
- func (thisVal NullDate) Before(other NullDate) bool
- func (thisVal NullDate) Compare(other NullDate) int
- func (thisVal NullDate) Equal(other NullDate) bool
- func (thisVal *NullDate) IsEmpty() bool
- func (thisVal NullDate) IsZero() bool
- func (thisVal NullDate) MarshalJSON() ([]byte, error)
- func (thisVal *NullDate) Scan(value interface{}) error
- func (thisVal NullDate) SubOk(other NullDate) (time.Duration, bool)
- func (thisVal NullDate) ToString() string
- func (thisVal NullDate) UnixMicroOk() (int64, bool)
- func (thisVal NullDate) UnixMilliOk() (int64, bool)
- func (thisVal NullDate) UnixNanoOk() (int64, bool)
- func (thisVal NullDate) UnixOk() (int64, bool)
- func (thisVal *NullDate) UnmarshalJSON(data []byte) error
- func (thisVal NullDate) Value() (driver.Value, error)
- type NullDecimal
- func (thisVal *NullDecimal) IsEmpty() bool
- func (thisVal NullDecimal) IsZero() bool
- func (thisVal NullDecimal) MarshalJSON() ([]byte, error)
- func (thisVal *NullDecimal) Scan(value interface{}) error
- func (thisVal NullDecimal) ToString() string
- func (thisVal *NullDecimal) UnmarshalJSON(data []byte) error
- func (thisVal NullDecimal) Value() (driver.Value, error)
- type NullFloat
- func (thisVal *NullFloat) IsEmpty() bool
- func (thisVal NullFloat) IsZero() bool
- func (thisVal NullFloat) MarshalJSON() ([]byte, error)
- func (thisVal *NullFloat) Scan(value interface{}) error
- func (thisVal NullFloat) ToString() string
- func (thisVal *NullFloat) UnmarshalJSON(data []byte) error
- func (thisVal NullFloat) Value() (driver.Value, error)
- type NullInt16
- func (thisVal *NullInt16) IsEmpty() bool
- func (thisVal NullInt16) IsZero() bool
- func (thisVal NullInt16) MarshalJSON() ([]byte, error)
- func (thisVal *NullInt16) Scan(value interface{}) error
- func (thisVal NullInt16) ToString() string
- func (thisVal *NullInt16) UnmarshalJSON(data []byte) error
- func (thisVal NullInt16) Value() (driver.Value, error)
- type NullInt32
- func (thisVal *NullInt32) IsEmpty() bool
- func (thisVal NullInt32) IsZero() bool
- func (thisVal NullInt32) MarshalJSON() ([]byte, error)
- func (thisVal *NullInt32) Scan(value interface{}) error
- func (thisVal NullInt32) ToString() string
- func (thisVal *NullInt32) UnmarshalJSON(data []byte) error
- func (thisVal NullInt32) Value() (driver.Value, error)
- type NullInt64
- func (thisVal *NullInt64) IsEmpty() bool
- func (thisVal NullInt64) IsZero() bool
- func (thisVal NullInt64) MarshalJSON() ([]byte, error)
- func (thisVal *NullInt64) Scan(value interface{}) error
- func (thisVal NullInt64) ToString() string
- func (thisVal *NullInt64) UnmarshalJSON(data []byte) error
- func (thisVal NullInt64) Value() (driver.Value, error)
- type NullLocalDateTime
- func (thisVal NullLocalDateTime) Add(d time.Duration) NullLocalDateTime
- func (thisVal NullLocalDateTime) AddDate(years, months, days int) NullLocalDateTime
- func (thisVal NullLocalDateTime) After(other NullLocalDateTime) bool
- func (thisVal NullLocalDateTime) Before(other NullLocalDateTime) bool
- func (thisVal NullLocalDateTime) Compare(other NullLocalDateTime) int
- func (thisVal NullLocalDateTime) Equal(other NullLocalDateTime) bool
- func (thisVal *NullLocalDateTime) IsEmpty() bool
- func (thisVal NullLocalDateTime) IsZero() bool
- func (thisVal NullLocalDateTime) MarshalJSON() ([]byte, error)
- func (thisVal *NullLocalDateTime) Scan(value interface{}) error
- func (thisVal NullLocalDateTime) SubOk(other NullLocalDateTime) (time.Duration, bool)
- func (thisVal NullLocalDateTime) ToString() string
- func (thisVal NullLocalDateTime) Truncate(d time.Duration) NullLocalDateTime
- func (thisVal *NullLocalDateTime) UnmarshalJSON(data []byte) error
- func (thisVal NullLocalDateTime) Value() (driver.Value, error)
- type NullLocalTime
- func (thisVal NullLocalTime) Add(d time.Duration) NullLocalTime
- func (thisVal NullLocalTime) After(other NullLocalTime) bool
- func (thisVal NullLocalTime) Before(other NullLocalTime) bool
- func (thisVal NullLocalTime) Compare(other NullLocalTime) int
- func (thisVal NullLocalTime) Equal(other NullLocalTime) bool
- func (thisVal *NullLocalTime) IsEmpty() bool
- func (thisVal NullLocalTime) IsZero() bool
- func (thisVal NullLocalTime) MarshalJSON() ([]byte, error)
- func (thisVal *NullLocalTime) Scan(value interface{}) error
- func (thisVal NullLocalTime) SubOk(other NullLocalTime) (time.Duration, bool)
- func (thisVal NullLocalTime) ToString() string
- func (thisVal NullLocalTime) Truncate(d time.Duration) NullLocalTime
- func (thisVal *NullLocalTime) UnmarshalJSON(data []byte) error
- func (thisVal NullLocalTime) Value() (driver.Value, error)
- type NullOffsetDateTime
- func (thisVal NullOffsetDateTime) Add(d time.Duration) NullOffsetDateTime
- func (thisVal NullOffsetDateTime) AddDate(years, months, days int) NullOffsetDateTime
- func (thisVal NullOffsetDateTime) After(other NullOffsetDateTime) bool
- func (thisVal NullOffsetDateTime) Before(other NullOffsetDateTime) bool
- func (thisVal NullOffsetDateTime) Compare(other NullOffsetDateTime) int
- func (thisVal NullOffsetDateTime) Equal(other NullOffsetDateTime) bool
- func (thisVal NullOffsetDateTime) In(loc *time.Location) NullOffsetDateTime
- func (thisVal *NullOffsetDateTime) IsEmpty() bool
- func (thisVal NullOffsetDateTime) IsZero() bool
- func (thisVal NullOffsetDateTime) MarshalJSON() ([]byte, error)
- func (thisVal *NullOffsetDateTime) Scan(value interface{}) error
- func (thisVal NullOffsetDateTime) SubOk(other NullOffsetDateTime) (time.Duration, bool)
- func (thisVal NullOffsetDateTime) ToString() string
- func (thisVal NullOffsetDateTime) Truncate(d time.Duration) NullOffsetDateTime
- func (thisVal NullOffsetDateTime) UTC() NullOffsetDateTime
- func (thisVal NullOffsetDateTime) UnixMicroOk() (int64, bool)
- func (thisVal NullOffsetDateTime) UnixMilliOk() (int64, bool)
- func (thisVal NullOffsetDateTime) UnixNanoOk() (int64, bool)
- func (thisVal NullOffsetDateTime) UnixOk() (int64, bool)
- func (thisVal *NullOffsetDateTime) UnmarshalJSON(data []byte) error
- func (thisVal NullOffsetDateTime) Value() (driver.Value, error)
- type NullOffsetTime
- func (thisVal NullOffsetTime) Add(d time.Duration) NullOffsetTime
- func (thisVal NullOffsetTime) After(other NullOffsetTime) bool
- func (thisVal NullOffsetTime) Before(other NullOffsetTime) bool
- func (thisVal NullOffsetTime) Compare(other NullOffsetTime) int
- func (thisVal NullOffsetTime) Equal(other NullOffsetTime) bool
- func (thisVal NullOffsetTime) In(loc *time.Location) NullOffsetTime
- func (thisVal *NullOffsetTime) IsEmpty() bool
- func (thisVal NullOffsetTime) IsZero() bool
- func (thisVal NullOffsetTime) MarshalJSON() ([]byte, error)
- func (thisVal *NullOffsetTime) Scan(value interface{}) error
- func (thisVal NullOffsetTime) SubOk(other NullOffsetTime) (time.Duration, bool)
- func (thisVal NullOffsetTime) ToString() string
- func (thisVal NullOffsetTime) Truncate(d time.Duration) NullOffsetTime
- func (thisVal NullOffsetTime) UTC() NullOffsetTime
- func (thisVal *NullOffsetTime) UnmarshalJSON(data []byte) error
- func (thisVal NullOffsetTime) Value() (driver.Value, error)
- type NullString
- func (thisVal *NullString) IsEmpty() bool
- func (thisVal NullString) IsZero() bool
- func (thisVal NullString) MarshalJSON() ([]byte, error)
- func (thisVal *NullString) Scan(value interface{}) error
- func (thisVal NullString) ToString() string
- func (thisVal *NullString) UnmarshalJSON(data []byte) error
- func (thisVal NullString) Value() (driver.Value, error)
- type NullUUID
- func (thisVal *NullUUID) IsEmpty() bool
- func (thisVal NullUUID) IsZero() bool
- func (thisVal NullUUID) MarshalJSON() ([]byte, error)
- func (thisVal *NullUUID) Scan(value interface{}) error
- func (thisVal NullUUID) ToString() string
- func (thisVal *NullUUID) UnmarshalJSON(data []byte) error
- func (thisVal NullUUID) Value() (driver.Value, error)
- type OffsetDateTime
- func (thisVal OffsetDateTime) Add(d time.Duration) OffsetDateTime
- func (thisVal OffsetDateTime) AddDate(years, months, days int) OffsetDateTime
- func (thisVal OffsetDateTime) After(other OffsetDateTime) bool
- func (thisVal OffsetDateTime) AsTime() time.Time
- func (thisVal OffsetDateTime) Before(other OffsetDateTime) bool
- func (thisVal OffsetDateTime) Compare(other OffsetDateTime) int
- func (thisVal OffsetDateTime) Day() int
- func (thisVal OffsetDateTime) Equal(other OffsetDateTime) bool
- func (thisVal OffsetDateTime) Hour() int
- func (thisVal OffsetDateTime) In(loc *time.Location) OffsetDateTime
- func (thisVal OffsetDateTime) MarshalJSON() ([]byte, error)
- func (thisVal OffsetDateTime) Minute() int
- func (thisVal OffsetDateTime) Month() time.Month
- func (thisVal OffsetDateTime) Nanosecond() int
- func (thisVal *OffsetDateTime) Scan(value interface{}) error
- func (thisVal OffsetDateTime) Second() int
- func (thisVal OffsetDateTime) Sub(other OffsetDateTime) time.Duration
- func (thisVal OffsetDateTime) ToString() string
- func (thisVal OffsetDateTime) Truncate(d time.Duration) OffsetDateTime
- func (thisVal OffsetDateTime) UTC() OffsetDateTime
- func (thisVal OffsetDateTime) Unix() int64
- func (thisVal OffsetDateTime) UnixMicro() int64
- func (thisVal OffsetDateTime) UnixMilli() int64
- func (thisVal OffsetDateTime) UnixNano() int64
- func (thisVal *OffsetDateTime) UnmarshalJSON(data []byte) error
- func (thisVal OffsetDateTime) Value() (driver.Value, error)
- func (thisVal OffsetDateTime) Year() int
- func (thisVal OffsetDateTime) YearDay() int
- type OffsetTime
- func (thisVal OffsetTime) Add(d time.Duration) OffsetTime
- func (thisVal OffsetTime) After(other OffsetTime) bool
- func (thisVal OffsetTime) AsTime() time.Time
- func (thisVal OffsetTime) Before(other OffsetTime) bool
- func (thisVal OffsetTime) Compare(other OffsetTime) int
- func (thisVal OffsetTime) Equal(other OffsetTime) bool
- func (thisVal OffsetTime) Hour() int
- func (thisVal OffsetTime) In(loc *time.Location) OffsetTime
- func (thisVal OffsetTime) MarshalJSON() ([]byte, error)
- func (thisVal OffsetTime) Minute() int
- func (thisVal OffsetTime) Nanosecond() int
- func (thisVal *OffsetTime) Scan(value interface{}) error
- func (thisVal OffsetTime) Second() int
- func (thisVal OffsetTime) String() string
- func (thisVal OffsetTime) Sub(other OffsetTime) time.Duration
- func (thisVal OffsetTime) ToString() string
- func (thisVal OffsetTime) Truncate(d time.Duration) OffsetTime
- func (thisVal OffsetTime) UTC() OffsetTime
- func (thisVal *OffsetTime) UnmarshalJSON(data []byte) error
- func (thisVal OffsetTime) Value() (driver.Value, error)
- type ToStringAble
Constants ¶
const RuOnlyDateMask = "02.01.2006"
RuOnlyDateMask is the dd.MM.yyyy locale date format accepted by parseDate in addition to ISO 8601 (time.DateOnly).
Variables ¶
This section is empty.
Functions ¶
func AssembleDateTime ¶
func AssembleDateTime( dateValue *time.Time, timeValue *time.Time, location *time.Location, ) *time.Time
AssembleDateTime combines the calendar date from dateValue with the wall-clock components from timeValue. If location is non-nil it is used as the resulting time.Location, otherwise timeValue's location is kept.
func AssembleDateTimeTZ ¶
func AssembleDateTimeTZ( dateValue *time.Time, timeValue *time.Time, timeZone string, ) (*time.Time, error)
AssembleDateTimeTZ combines dateValue and timeValue and resolves the resulting location from the textual timeZone using ParseTimezoneExtended (IANA names, "Z", and "+HH:MM" / "+HHMM" offsets are all accepted). On a zone parse error the original dateValue is returned alongside the error.
func AssembleNullDateTimeTZ ¶
func AssembleNullDateTimeTZ( dateValue *NullDate, defaultDate *time.Time, timeValue *NullOffsetTime, defaultTime *time.Time, timeZone string, ) (*time.Time, error)
AssembleNullDateTimeTZ is the NULL-aware variant of AssembleDateTimeTZ. A NULL date or time is replaced by the corresponding default (defaultDate / defaultTime); the returned pointer reflects the assembled instant in the zone decoded from timeZone.
func DateTimeToString ¶
DateTimeToString renders a datetime in the library's canonical TZ-aware format. Kept as a thin wrapper for callers that operate on bare time.Time values.
func DateToString ¶
DateToString renders a calendar date in the library's canonical ISO 8601 form ("2006-01-02").
func GetNullString ¶
func GetNullString(s sql.NullString) string
GetNullString returns the underlying string of an sql.NullString, or "" when the value is NULL. Mirrors NSFromString on the read side.
func IsEmpty ¶
func IsEmpty(t interface{}) bool
IsEmpty reports whether v should be treated as empty/NULL. It accepts nil, primitives, the standard library's sql.Null* family, and any value that implements Emptiable (including pointer-receiver implementations invoked on a value).
func MaxDateTime ¶
MaxDateTime returns the later of dt1 and dt2. Ties return dt2.
func MinDateTime ¶
MinDateTime returns the earlier of dt1 and dt2. Ties return dt2.
func NSFromString ¶
func NSFromString(s string) sql.NullString
NSFromString builds an sql.NullString from a raw string, treating the empty string as NULL. Handy when composing queries against the database/sql package directly.
func ParseDateFromString ¶
ParseDateFromString parses a calendar date from a string using the formats supported by the library (ISO 8601 and dd.MM.yyyy). The returned pointer is never nil on success.
func ParseDateTimeFromString ¶
ParseDateTimeFromString parses a datetime string. The date and time parts must be separated by either 'T' or ' '. The time part may carry an optional timezone designator ("Z", "+HH:MM", "+HHMM").
func ParseTimeFromString ¶
ParseTimeFromString parses a time-of-day with an optional timezone designator ("HH:MM[:SS[.fff…]][Z|±HH:MM|±HHMM]").
func ParseTimezoneExtended ¶
ParseTimezoneExtended attempts to extract a trailing timezone designator from strValue. Supported forms are "Z" (RFC 3339 UTC literal), "+HH:MM" / "-HH:MM" (six chars) and "+HHMM" / "-HHMM" (five chars). When a designator is found it is removed from the returned string and represented as a *time.Location; otherwise time.Local is returned.
Types ¶
type Date ¶
Date is a not-null calendar date (no time component, no timezone).
Date shares its serializer with NullDate: both render as "2006-01-02" and accept the same parser inputs (ISO 8601 and dd.MM.yyyy). Use Date for required JSON or SQL fields where NULL is not permitted; use NullDate for optional ones.
In(loc) and UTC() are not provided by design: Date is a calendar concept without a time-of-day, so zone reinterpretation is meaningless. Use OffsetDateTime if a zone-aware instant is required.
func DateFromString ¶
DateFromString parses a calendar date using the formats supported by the library (ISO 8601 and dd.MM.yyyy).
func NewDate ¶
NewDate wraps t as a Date. The time-of-day component is preserved on the underlying value but is dropped by the serializer (formatDate writes only "YYYY-MM-DD").
func (Date) Add ¶ added in v0.3.0
Add returns the date shifted by d. Sub-day components of d are applied to the underlying time.Time but do not surface in the serialised form (Date renders only YYYY-MM-DD).
func (Date) AddDate ¶ added in v0.3.0
AddDate returns the date with the given number of years, months, and days added.
func (Date) Compare ¶ added in v0.3.0
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other.
func (Date) Equal ¶ added in v0.3.0
Equal reports whether thisVal and other denote the same instant.
func (Date) MarshalJSON ¶
MarshalJSON renders the date as a JSON string in the library's canonical format ("2006-01-02").
func (Date) Month ¶ added in v0.3.0
Month returns the calendar month (1-based, time.January..December).
func (*Date) Scan ¶
Scan implements the database/sql.Scanner interface. A NULL value is rejected — Date cannot be empty.
func (Date) Sub ¶ added in v0.3.0
Sub returns the duration thisVal − other. Convert to days via `dur / (24 * time.Hour)` if needed.
func (Date) Unix ¶ added in v0.3.0
Unix returns the underlying instant as a Unix timestamp (seconds since 1970-01-01 UTC). For Date values constructed at midnight UTC this is the conventional "date as epoch seconds".
func (Date) UnixMicro ¶ added in v0.3.0
UnixMicro returns the underlying instant as microseconds since 1970-01-01 UTC.
func (Date) UnixMilli ¶ added in v0.3.0
UnixMilli returns the underlying instant as milliseconds since 1970-01-01 UTC.
func (Date) UnixNano ¶ added in v0.3.0
UnixNano returns the underlying instant as nanoseconds since 1970-01-01 UTC.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON parses a JSON string in any of the formats accepted by DateFromString. JSON null is rejected — Date cannot be empty.
type Emptiable ¶
type Emptiable interface {
IsEmpty() bool
}
Emptiable is the interface implemented by every nullable type in the package. IsEmpty reports whether the value is missing (NULL).
type LocalDateTime ¶
type LocalDateTime struct {
Year int
Month time.Month
Day int
Hour int
Minute int
Second int
Nanosec int
}
LocalDateTime is a not-null wall-clock datetime without a timezone.
Use LocalDateTime for business events anchored to a calendar moment in a human's wall-clock time (e.g. "contract signed on 2026-04-18 at 13:00") where the offset is intentionally absent. For points in time with a known offset, use OffsetDateTime instead.
In(loc) and UTC() are not provided by design: LocalDateTime carries no timezone, so zone reinterpretation is meaningless. Use ToTime(loc) to materialise a time.Time in a chosen zone.
func LocalDateTimeFromString ¶
func LocalDateTimeFromString(strValue string) (LocalDateTime, error)
LocalDateTimeFromString parses a wall-clock datetime in either ISO 8601 "T" form ("2006-01-02T15:04:05[.fff]") or the equivalent space-separated form. Inputs carrying a timezone designator are rejected.
func LocalDateTimeFromTime ¶
func LocalDateTimeFromTime(t time.Time) LocalDateTime
LocalDateTimeFromTime extracts the wall-clock components of t and discards its location.
func NewLocalDateTime ¶
func NewLocalDateTime(year int, month time.Month, day, hour, minute, second, nanosec int) LocalDateTime
NewLocalDateTime constructs a LocalDateTime from its components.
func (LocalDateTime) Add ¶ added in v0.3.0
func (thisVal LocalDateTime) Add(d time.Duration) LocalDateTime
Add returns thisVal shifted by d on the wall-clock components.
func (LocalDateTime) AddDate ¶ added in v0.3.0
func (thisVal LocalDateTime) AddDate(years, months, days int) LocalDateTime
AddDate returns thisVal with the given years/months/days added.
func (LocalDateTime) After ¶ added in v0.3.0
func (thisVal LocalDateTime) After(other LocalDateTime) bool
After reports whether thisVal is after other.
func (LocalDateTime) Before ¶ added in v0.3.0
func (thisVal LocalDateTime) Before(other LocalDateTime) bool
Before reports whether thisVal precedes other. Comparison operates on wall-clock components (year/month/.../nanosec) since LocalDateTime carries no timezone.
func (LocalDateTime) Compare ¶ added in v0.3.0
func (thisVal LocalDateTime) Compare(other LocalDateTime) int
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other.
func (LocalDateTime) Equal ¶ added in v0.3.0
func (thisVal LocalDateTime) Equal(other LocalDateTime) bool
Equal reports whether thisVal and other have identical wall-clock components.
func (LocalDateTime) MarshalJSON ¶
func (thisVal LocalDateTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in the library's canonical format.
func (*LocalDateTime) Scan ¶
func (thisVal *LocalDateTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. A NULL value is rejected — LocalDateTime cannot be empty.
func (LocalDateTime) Sub ¶ added in v0.3.0
func (thisVal LocalDateTime) Sub(other LocalDateTime) time.Duration
Sub returns thisVal − other as a time.Duration on the wall-clock components.
func (LocalDateTime) ToString ¶
func (thisVal LocalDateTime) ToString() string
ToString renders the value in the library's canonical format ("2006-01-02T15:04:05[.fff]").
func (LocalDateTime) ToTime ¶
func (thisVal LocalDateTime) ToTime(loc *time.Location) time.Time
ToTime materialises the wall-clock components in the given location. Pass time.UTC, time.Local, or a fixed zone according to how the value should be interpreted at the boundary with timezone-aware code. A nil loc is treated as time.UTC.
func (LocalDateTime) Truncate ¶ added in v0.3.0
func (thisVal LocalDateTime) Truncate(d time.Duration) LocalDateTime
Truncate returns thisVal rounded down to the nearest multiple of d since the zero time.
func (*LocalDateTime) UnmarshalJSON ¶
func (thisVal *LocalDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string in any of the formats accepted by LocalDateTimeFromString. JSON null is rejected — LocalDateTime cannot be empty.
func (LocalDateTime) Value ¶
func (thisVal LocalDateTime) Value() (driver.Value, error)
Value implements the database/sql/driver.Valuer interface. The value is emitted in time.UTC; the SQL column type should be TIMESTAMP WITHOUT TIME ZONE so the driver writes the wall-clock fields verbatim.
func (LocalDateTime) YearDay ¶ added in v0.3.0
func (thisVal LocalDateTime) YearDay() int
YearDay returns the day-of-year (1-365 / 1-366 in leap years). Year/Month/Day/Hour/Minute/Second/Nanosec are exposed as struct fields directly.
type LocalTime ¶
LocalTime is a not-null wall-clock time-of-day without a timezone.
Use LocalTime for values like "shop opens at 09:00" — a time-of-day with no offset. For points in time with a known offset, use OffsetTime instead.
In(loc) and UTC() are not provided by design: LocalTime carries no timezone, so zone reinterpretation is meaningless. Use ToTime() to materialise a time.Time on the zero date in UTC.
func LocalTimeFromString ¶
LocalTimeFromString parses a wall-clock time-of-day in ISO 8601 form ("HH:MM[:SS[.fff]]"). Inputs carrying a timezone designator are rejected.
func LocalTimeFromTime ¶
LocalTimeFromTime extracts the time-of-day components of t and discards its date and location.
func NewLocalTime ¶
NewLocalTime constructs a LocalTime from its components.
func (LocalTime) Add ¶ added in v0.3.0
Add returns thisVal shifted by d. No modulo-24h enforcement: a duration that crosses midnight rotates the implicit date in the underlying time.Time, but the date is not part of LocalTime's serialised form. Consume with care.
func (LocalTime) Before ¶ added in v0.3.0
Before reports whether thisVal precedes other. Comparison operates on wall-clock components (hour/minute/second/nanosec) since LocalTime carries no timezone.
func (LocalTime) Compare ¶ added in v0.3.0
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other.
func (LocalTime) Equal ¶ added in v0.3.0
Equal reports whether thisVal and other have identical wall-clock components.
func (LocalTime) MarshalJSON ¶
MarshalJSON renders the value as a JSON string in the library's canonical format.
func (*LocalTime) Scan ¶
Scan implements the database/sql.Scanner interface. Accepts time.Time, string, or []byte. A NULL value is rejected — LocalTime cannot be empty.
func (LocalTime) Sub ¶ added in v0.3.0
Sub returns thisVal − other as a time.Duration. The implicit dates participate in the calculation; for same-day pairs the result is sub-24h.
func (LocalTime) ToString ¶
ToString renders the value in the library's canonical format ("15:04:05[.fff]").
func (LocalTime) ToTime ¶
ToTime materialises the time-of-day on the zero date (year 0, January 1) in time.UTC.
func (LocalTime) Truncate ¶ added in v0.3.0
Truncate returns thisVal rounded down to the nearest multiple of d since the zero time.
func (*LocalTime) UnmarshalJSON ¶
UnmarshalJSON parses a JSON string in any of the formats accepted by LocalTimeFromString. JSON null is rejected — LocalTime cannot be empty.
type NullBool ¶
NullBool is a nullable boolean. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullBool ¶
NewNullBool constructs a valid NullBool wrapping value.
func NewNullBoolEmpty ¶
func NewNullBoolEmpty() NullBool
NewNullBoolEmpty returns an invalid (NULL) NullBool.
func NullBoolFromString ¶
NullBoolFromString parses a bool from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullBool.
func (NullBool) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullBool) MarshalJSON ¶
MarshalJSON renders the value as a JSON boolean, or null when empty. The valid path returns a shared literal slice ("true"/"false") to skip the reflection dispatch and allocation that json.Marshal does for the primitive bool type.
func (*NullBool) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullBool so that the driver's NULL signalling is honoured.
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON parses a JSON boolean or the token null. Any other input is treated as a parse error.
type NullDate ¶
NullDate is a nullable calendar date (year/month/day with no time-of-day or zone component). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullDate ¶
NewNullDate constructs a valid NullDate wrapping value. Use NullDateFromTime when starting from a time.Time.
func NewNullDateEmpty ¶
func NewNullDateEmpty() NullDate
NewNullDateEmpty returns an invalid (NULL) NullDate.
func NullDateFromString ¶
NullDateFromString parses a date from the string pointer using the library's accepted formats (ISO 8601 "2006-01-02" and the Russian "dd.MM.yyyy"). A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullDate.
func NullDateFromTime ¶ added in v0.3.0
NullDateFromTime constructs a valid NullDate from a time.Time. Equivalent to NewNullDate(Date(value)).
func (NullDate) Add ¶ added in v0.3.0
Add returns the date shifted by d. NULL propagates: an invalid receiver is returned unchanged.
func (NullDate) AddDate ¶ added in v0.3.0
AddDate returns the date with the given years/months/days added. NULL propagates.
func (NullDate) After ¶ added in v0.3.0
After reports whether thisVal is after other under sortable NULL semantics: NULL is never after any value (including another NULL).
func (NullDate) Before ¶ added in v0.3.0
Before reports whether thisVal precedes other under sortable NULL semantics: NULL is strictly less than any valid value, two NULLs compare equal (so neither is Before the other).
func (NullDate) Compare ¶ added in v0.3.0
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other under sortable NULL semantics: NULL precedes any valid value, two NULLs compare equal.
func (NullDate) Equal ¶ added in v0.3.0
Equal reports whether thisVal and other are equal under sortable NULL semantics: two NULLs are equal; NULL is never equal to a valid value.
func (NullDate) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullDate) MarshalJSON ¶
MarshalJSON renders the date as a JSON string in ISO 8601 form, or null when empty. The valid path writes directly to a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal would perform.
func (*NullDate) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullTime so that the driver's NULL signalling is honoured.
func (NullDate) SubOk ¶ added in v0.3.0
SubOk returns (thisVal − other, true) when both operands are valid, and (0, false) otherwise.
func (NullDate) UnixMicroOk ¶ added in v0.3.0
UnixMicroOk returns the microsecond-precision Unix timestamp and ok=true if the receiver is valid; (0, false) for NULL.
func (NullDate) UnixMilliOk ¶ added in v0.3.0
UnixMilliOk returns the millisecond-precision Unix timestamp and ok=true if the receiver is valid; (0, false) for NULL.
func (NullDate) UnixNanoOk ¶ added in v0.3.0
UnixNanoOk returns the nanosecond-precision Unix timestamp and ok=true if the receiver is valid; (0, false) for NULL.
func (NullDate) UnixOk ¶ added in v0.3.0
UnixOk returns the underlying instant as a Unix timestamp (seconds since 1970-01-01 UTC) and ok=true if the receiver is valid; (0, false) for NULL.
func (*NullDate) UnmarshalJSON ¶
UnmarshalJSON parses a JSON string using the accepted date formats (ISO 8601, dd.MM.yyyy) or the token null.
type NullDecimal ¶
NullDecimal is a nullable arbitrary-precision decimal backed by github.com/shopspring/decimal. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func MulNullDecimals ¶
func MulNullDecimals(val1, val2 NullDecimal) NullDecimal
MulNullDecimals multiplies two NullDecimals. The result is NULL if either operand is NULL.
func NewNullDecimal ¶
func NewNullDecimal(val decimal.Decimal) NullDecimal
NewNullDecimal constructs a valid NullDecimal wrapping val.
func NewNullDecimalEmpty ¶
func NewNullDecimalEmpty() NullDecimal
NewNullDecimalEmpty returns an invalid (NULL) NullDecimal.
func NullDecimalFromString ¶
func NullDecimalFromString(strValue *string) NullDecimal
NullDecimalFromString parses a decimal from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullDecimal.
func (*NullDecimal) IsEmpty ¶
func (thisVal *NullDecimal) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullDecimal) IsZero ¶
func (thisVal NullDecimal) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullDecimal) MarshalJSON ¶
func (thisVal NullDecimal) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON number (the format decimal.Decimal itself emits), or null when empty.
func (*NullDecimal) Scan ¶
func (thisVal *NullDecimal) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. The decimal is received as text from the driver (via sql.NullString) and parsed through NullDecimalFromString so precision is preserved.
func (NullDecimal) ToString ¶
func (thisVal NullDecimal) ToString() string
ToString renders the decimal via decimal.Decimal.String (no trailing zeros), or "" when NULL.
func (*NullDecimal) UnmarshalJSON ¶
func (thisVal *NullDecimal) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON number, JSON string, or the token null. Any other input is treated as a parse error.
type NullFloat ¶
NullFloat is a nullable float64. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullFloat ¶
NewNullFloat constructs a valid NullFloat wrapping value.
func NewNullFloatEmpty ¶
func NewNullFloatEmpty() NullFloat
NewNullFloatEmpty returns an invalid (NULL) NullFloat.
func NullFloatFromString ¶
NullFloatFromString parses a float64 from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullFloat.
func (NullFloat) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullFloat) MarshalJSON ¶
MarshalJSON renders the value as a JSON number, or null when empty. The valid path uses strconv.AppendFloat directly to skip the reflection dispatch and intermediate buffer allocation that json.Marshal does for primitive numeric types. The 'g' verb mirrors encoding/json's own format for float64.
func (*NullFloat) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullFloat64 so that the driver's NULL signalling is honoured.
func (*NullFloat) UnmarshalJSON ¶
UnmarshalJSON parses a JSON number or the token null. Any other input is treated as a parse error.
type NullInt16 ¶
NullInt16 is a nullable int16. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullInt16 ¶
NewNullInt16 constructs a valid NullInt16 wrapping value.
func NewNullInt16Empty ¶
func NewNullInt16Empty() NullInt16
NewNullInt16Empty returns an invalid (NULL) NullInt16.
func NullInt16FromNullString ¶
func NullInt16FromNullString(str NullString) NullInt16
NullInt16FromNullString parses an int16 from a NullString. An invalid or empty NullString, or a parse error, produce an invalid NullInt16.
func NullInt16FromString ¶
NullInt16FromString parses an int16 from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullInt16.
func (NullInt16) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullInt16) MarshalJSON ¶
MarshalJSON renders the value as a JSON number, or null when empty. The valid path uses strconv.AppendInt directly to skip the reflection dispatch and intermediate buffer allocation that json.Marshal does for primitive numeric types.
func (*NullInt16) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullInt16 so that the driver's NULL signalling is honoured.
func (*NullInt16) UnmarshalJSON ¶
UnmarshalJSON parses a JSON number or the token null. Any other input is treated as a parse error.
type NullInt32 ¶
NullInt32 is a nullable int32. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullInt32 ¶
NewNullInt32 constructs a valid NullInt32 wrapping value.
func NewNullInt32Empty ¶
func NewNullInt32Empty() NullInt32
NewNullInt32Empty returns an invalid (NULL) NullInt32.
func NullInt32FromNullString ¶
func NullInt32FromNullString(str NullString) NullInt32
NullInt32FromNullString parses an int32 from a NullString. An invalid or empty NullString, or a parse error, produce an invalid NullInt32.
func NullInt32FromString ¶
NullInt32FromString parses an int32 from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullInt32.
func (NullInt32) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullInt32) MarshalJSON ¶
MarshalJSON renders the value as a JSON number, or null when empty. The valid path uses strconv.AppendInt directly to skip the reflection dispatch and intermediate buffer allocation that json.Marshal does for primitive numeric types.
func (*NullInt32) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullInt32 so that the driver's NULL signalling is honoured.
func (*NullInt32) UnmarshalJSON ¶
UnmarshalJSON parses a JSON number or the token null. Any other input is treated as a parse error.
type NullInt64 ¶
NullInt64 is a nullable int64. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullInt64 ¶
NewNullInt64 constructs a valid NullInt64 wrapping value.
func NewNullInt64Empty ¶
func NewNullInt64Empty() NullInt64
NewNullInt64Empty returns an invalid (NULL) NullInt64.
func NullInt64FromNullString ¶
func NullInt64FromNullString(str NullString) NullInt64
NullInt64FromNullString parses an int64 from a NullString. An invalid or empty NullString, or a parse error, produce an invalid NullInt64.
func NullInt64FromString ¶
NullInt64FromString parses an int64 from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullInt64.
func (NullInt64) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullInt64) MarshalJSON ¶
MarshalJSON renders the value as a JSON number, or null when empty. The valid path uses strconv.AppendInt directly to skip the reflection dispatch and intermediate buffer allocation that json.Marshal does for primitive numeric types.
func (*NullInt64) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullInt64 so that the driver's NULL signalling is honoured.
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON parses a JSON number or the token null. Any other input is treated as a parse error.
type NullLocalDateTime ¶
type NullLocalDateTime struct {
Val LocalDateTime
Valid bool
}
NullLocalDateTime is the nullable counterpart of LocalDateTime. It shares the same serializer (formatLocalDateTime / parseLocalDateTime). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullLocalDateTime ¶
func NewNullLocalDateTime(value LocalDateTime) NullLocalDateTime
NewNullLocalDateTime constructs a valid NullLocalDateTime wrapping value. Use NullLocalDateTimeFromTime when starting from a time.Time.
func NewNullLocalDateTimeEmpty ¶
func NewNullLocalDateTimeEmpty() NullLocalDateTime
NewNullLocalDateTimeEmpty returns an invalid (NULL) NullLocalDateTime.
func NullLocalDateTimeFromString ¶
func NullLocalDateTimeFromString(strValue *string) NullLocalDateTime
NullLocalDateTimeFromString parses a local datetime from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullLocalDateTime.
func NullLocalDateTimeFromTime ¶ added in v0.3.0
func NullLocalDateTimeFromTime(value time.Time) NullLocalDateTime
NullLocalDateTimeFromTime constructs a valid NullLocalDateTime from a time.Time. The time-of-day fields are read in t's current location; the zone itself is dropped (LocalDateTime carries no zone by design).
func (NullLocalDateTime) Add ¶ added in v0.3.0
func (thisVal NullLocalDateTime) Add(d time.Duration) NullLocalDateTime
Add returns thisVal shifted by d. NULL propagates.
func (NullLocalDateTime) AddDate ¶ added in v0.3.0
func (thisVal NullLocalDateTime) AddDate(years, months, days int) NullLocalDateTime
AddDate returns thisVal with the given years/months/days added. NULL propagates.
func (NullLocalDateTime) After ¶ added in v0.3.0
func (thisVal NullLocalDateTime) After(other NullLocalDateTime) bool
After reports whether thisVal is after other under sortable NULL semantics: NULL is never after any value (including another NULL).
func (NullLocalDateTime) Before ¶ added in v0.3.0
func (thisVal NullLocalDateTime) Before(other NullLocalDateTime) bool
Before reports whether thisVal precedes other under sortable NULL semantics: NULL is strictly less than any valid value, two NULLs compare equal (so neither is Before the other).
func (NullLocalDateTime) Compare ¶ added in v0.3.0
func (thisVal NullLocalDateTime) Compare(other NullLocalDateTime) int
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other under sortable NULL semantics.
func (NullLocalDateTime) Equal ¶ added in v0.3.0
func (thisVal NullLocalDateTime) Equal(other NullLocalDateTime) bool
Equal reports whether thisVal and other are equal under sortable NULL semantics: two NULLs are equal; NULL is never equal to a valid value.
func (*NullLocalDateTime) IsEmpty ¶
func (thisVal *NullLocalDateTime) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullLocalDateTime) IsZero ¶
func (thisVal NullLocalDateTime) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullLocalDateTime) MarshalJSON ¶
func (thisVal NullLocalDateTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in canonical local datetime form, or null when empty. The valid path appends directly into a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal(formatLocalDateTime(...)) would perform.
func (*NullLocalDateTime) Scan ¶
func (thisVal *NullLocalDateTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface, delegating to sql.NullTime so that the driver's NULL signalling is honoured. The returned time's wall-clock components are preserved verbatim.
func (NullLocalDateTime) SubOk ¶ added in v0.3.0
func (thisVal NullLocalDateTime) SubOk(other NullLocalDateTime) (time.Duration, bool)
SubOk returns (thisVal − other, true) when both operands are valid, and (0, false) otherwise.
func (NullLocalDateTime) ToString ¶
func (thisVal NullLocalDateTime) ToString() string
ToString renders the value in the library's canonical local datetime form, or "" when NULL.
func (NullLocalDateTime) Truncate ¶ added in v0.3.0
func (thisVal NullLocalDateTime) Truncate(d time.Duration) NullLocalDateTime
Truncate returns thisVal rounded down to the nearest multiple of d since the zero time. NULL propagates.
func (*NullLocalDateTime) UnmarshalJSON ¶
func (thisVal *NullLocalDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string containing a local datetime, or the token null. Any other input is treated as a parse error.
func (NullLocalDateTime) Value ¶
func (thisVal NullLocalDateTime) Value() (driver.Value, error)
Value implements the database/sql/driver.Valuer interface. A NULL value is emitted as (nil, nil); the valid case is materialised as a time.Time in UTC (drivers interpret TIMESTAMP WITHOUT TIME ZONE as the wall-clock components).
type NullLocalTime ¶
NullLocalTime is the nullable counterpart of LocalTime. It shares the same serializer (formatLocalTime / parseLocalTime). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullLocalTime ¶
func NewNullLocalTime(value LocalTime) NullLocalTime
NewNullLocalTime constructs a valid NullLocalTime wrapping value. Use NullLocalTimeFromTime when starting from a time.Time.
func NewNullLocalTimeEmpty ¶
func NewNullLocalTimeEmpty() NullLocalTime
NewNullLocalTimeEmpty returns an invalid (NULL) NullLocalTime.
func NullLocalTimeFromString ¶
func NullLocalTimeFromString(strValue *string) NullLocalTime
NullLocalTimeFromString parses a local time from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullLocalTime.
func NullLocalTimeFromTime ¶ added in v0.3.0
func NullLocalTimeFromTime(value time.Time) NullLocalTime
NullLocalTimeFromTime constructs a valid NullLocalTime from a time.Time. The wall-clock fields are read in t's current location; the zone itself is dropped (LocalTime carries no zone by design).
func (NullLocalTime) Add ¶ added in v0.3.0
func (thisVal NullLocalTime) Add(d time.Duration) NullLocalTime
Add returns thisVal shifted by d. NULL propagates. No modulo-24h enforcement — see LocalTime.Add.
func (NullLocalTime) After ¶ added in v0.3.0
func (thisVal NullLocalTime) After(other NullLocalTime) bool
After reports whether thisVal is after other under sortable NULL semantics: NULL is never after any value (including another NULL).
func (NullLocalTime) Before ¶ added in v0.3.0
func (thisVal NullLocalTime) Before(other NullLocalTime) bool
Before reports whether thisVal precedes other under sortable NULL semantics: NULL is strictly less than any valid value, two NULLs compare equal (so neither is Before the other).
func (NullLocalTime) Compare ¶ added in v0.3.0
func (thisVal NullLocalTime) Compare(other NullLocalTime) int
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other under sortable NULL semantics.
func (NullLocalTime) Equal ¶ added in v0.3.0
func (thisVal NullLocalTime) Equal(other NullLocalTime) bool
Equal reports whether thisVal and other are equal under sortable NULL semantics: two NULLs are equal; NULL is never equal to a valid value.
func (*NullLocalTime) IsEmpty ¶
func (thisVal *NullLocalTime) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullLocalTime) IsZero ¶
func (thisVal NullLocalTime) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullLocalTime) MarshalJSON ¶
func (thisVal NullLocalTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in canonical local time form, or null when empty. The valid path appends directly into a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal(formatLocalTime(...)) would perform.
func (*NullLocalTime) Scan ¶
func (thisVal *NullLocalTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. NULL values produce an invalid NullLocalTime; non-NULL values are delegated to LocalTime.Scan.
func (NullLocalTime) SubOk ¶ added in v0.3.0
func (thisVal NullLocalTime) SubOk(other NullLocalTime) (time.Duration, bool)
SubOk returns (thisVal − other, true) when both operands are valid, and (0, false) otherwise.
func (NullLocalTime) ToString ¶
func (thisVal NullLocalTime) ToString() string
ToString renders the value in the library's canonical local time form, or "" when NULL.
func (NullLocalTime) Truncate ¶ added in v0.3.0
func (thisVal NullLocalTime) Truncate(d time.Duration) NullLocalTime
Truncate returns thisVal rounded down to the nearest multiple of d since the zero time. NULL propagates.
func (*NullLocalTime) UnmarshalJSON ¶
func (thisVal *NullLocalTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string containing a local time, or the token null. Any other input is treated as a parse error.
type NullOffsetDateTime ¶
type NullOffsetDateTime struct {
Val OffsetDateTime
Valid bool
}
NullOffsetDateTime is the nullable counterpart of OffsetDateTime. It shares the same serializer (formatOffsetDateTime / parseOffsetDateTime). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullOffsetDateTime ¶
func NewNullOffsetDateTime(value OffsetDateTime) NullOffsetDateTime
NewNullOffsetDateTime constructs a valid NullOffsetDateTime wrapping value. Use NullOffsetDateTimeFromTime when starting from a time.Time.
func NewNullOffsetDateTimeEmpty ¶
func NewNullOffsetDateTimeEmpty() NullOffsetDateTime
NewNullOffsetDateTimeEmpty returns an invalid (NULL) NullOffsetDateTime.
func NullOffsetDateTimeFromString ¶
func NullOffsetDateTimeFromString(strValue *string) NullOffsetDateTime
NullOffsetDateTimeFromString parses an offset datetime from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullOffsetDateTime.
func NullOffsetDateTimeFromTime ¶ added in v0.3.0
func NullOffsetDateTimeFromTime(value time.Time) NullOffsetDateTime
NullOffsetDateTimeFromTime constructs a valid NullOffsetDateTime from a time.Time. Equivalent to NewNullOffsetDateTime(OffsetDateTime(value)).
func (NullOffsetDateTime) Add ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) Add(d time.Duration) NullOffsetDateTime
Add returns thisVal shifted by d. NULL propagates.
func (NullOffsetDateTime) AddDate ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) AddDate(years, months, days int) NullOffsetDateTime
AddDate returns thisVal with the given years/months/days added. NULL propagates.
func (NullOffsetDateTime) After ¶
func (thisVal NullOffsetDateTime) After(other NullOffsetDateTime) bool
After reports whether thisVal is after other under sortable NULL semantics: NULL is never after any value (including another NULL).
func (NullOffsetDateTime) Before ¶
func (thisVal NullOffsetDateTime) Before(other NullOffsetDateTime) bool
Before reports whether thisVal precedes other under sortable NULL semantics: NULL is strictly less than any valid value, two NULLs compare equal (so neither is Before the other).
func (NullOffsetDateTime) Compare ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) Compare(other NullOffsetDateTime) int
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other under sortable NULL semantics: NULL precedes any valid value, two NULLs compare equal.
func (NullOffsetDateTime) Equal ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) Equal(other NullOffsetDateTime) bool
Equal reports whether thisVal and other are equal under sortable NULL semantics: two NULLs are equal; NULL is never equal to a valid value.
func (NullOffsetDateTime) In ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) In(loc *time.Location) NullOffsetDateTime
In returns the same instant rendered in loc, mirroring OffsetDateTime.In. NULL propagates: an invalid receiver is returned unchanged.
func (*NullOffsetDateTime) IsEmpty ¶
func (thisVal *NullOffsetDateTime) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullOffsetDateTime) IsZero ¶
func (thisVal NullOffsetDateTime) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullOffsetDateTime) MarshalJSON ¶
func (thisVal NullOffsetDateTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in canonical offset datetime form, or null when empty. The valid path appends directly into a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal(formatOffsetDateTime(...)) would perform.
func (*NullOffsetDateTime) Scan ¶
func (thisVal *NullOffsetDateTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface, delegating to sql.NullTime so that the driver's NULL signalling is honoured.
func (NullOffsetDateTime) SubOk ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) SubOk(other NullOffsetDateTime) (time.Duration, bool)
SubOk returns (thisVal − other, true) when both operands are valid, and (0, false) otherwise.
func (NullOffsetDateTime) ToString ¶
func (thisVal NullOffsetDateTime) ToString() string
ToString renders the value in the library's canonical offset datetime form, or "" when NULL.
func (NullOffsetDateTime) Truncate ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) Truncate(d time.Duration) NullOffsetDateTime
Truncate returns thisVal rounded down to the nearest multiple of d since the zero time. NULL propagates.
func (NullOffsetDateTime) UTC ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) UTC() NullOffsetDateTime
UTC is shorthand for In(time.UTC). NULL propagates.
func (NullOffsetDateTime) UnixMicroOk ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) UnixMicroOk() (int64, bool)
UnixMicroOk returns the microsecond-precision Unix timestamp and ok=true if the receiver is valid; (0, false) for NULL.
func (NullOffsetDateTime) UnixMilliOk ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) UnixMilliOk() (int64, bool)
UnixMilliOk returns the millisecond-precision Unix timestamp and ok=true if the receiver is valid; (0, false) for NULL.
func (NullOffsetDateTime) UnixNanoOk ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) UnixNanoOk() (int64, bool)
UnixNanoOk returns the nanosecond-precision Unix timestamp and ok=true if the receiver is valid; (0, false) for NULL.
func (NullOffsetDateTime) UnixOk ¶ added in v0.3.0
func (thisVal NullOffsetDateTime) UnixOk() (int64, bool)
UnixOk returns the underlying instant as a Unix timestamp (seconds since 1970-01-01 UTC) and ok=true if the receiver is valid. For NULL the result is (0, false) — distinguishing NULL from the Unix epoch, which the legacy Unix() method (removed in v0.3.0) could not.
func (*NullOffsetDateTime) UnmarshalJSON ¶
func (thisVal *NullOffsetDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string containing an offset datetime, or the token null. Any other input is treated as a parse error.
type NullOffsetTime ¶
type NullOffsetTime struct {
Val OffsetTime
Valid bool
}
NullOffsetTime is the nullable counterpart of OffsetTime. It shares the same serializer (formatOffsetTime / parseOffsetTime). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullOffsetTime ¶
func NewNullOffsetTime(value OffsetTime) NullOffsetTime
NewNullOffsetTime constructs a valid NullOffsetTime wrapping value. Use NullOffsetTimeFromTime when starting from a time.Time.
func NewNullOffsetTimeEmpty ¶
func NewNullOffsetTimeEmpty() NullOffsetTime
NewNullOffsetTimeEmpty returns an invalid (NULL) NullOffsetTime.
func NullOffsetTimeFromString ¶
func NullOffsetTimeFromString(strValue *string) NullOffsetTime
NullOffsetTimeFromString parses an offset time from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullOffsetTime.
func NullOffsetTimeFromTime ¶ added in v0.3.0
func NullOffsetTimeFromTime(value time.Time) NullOffsetTime
NullOffsetTimeFromTime constructs a valid NullOffsetTime from a time.Time. Equivalent to NewNullOffsetTime(OffsetTime(value)).
func (NullOffsetTime) Add ¶ added in v0.3.0
func (thisVal NullOffsetTime) Add(d time.Duration) NullOffsetTime
Add returns thisVal shifted by d. NULL propagates. No modulo-24h enforcement — see OffsetTime.Add.
func (NullOffsetTime) After ¶ added in v0.3.0
func (thisVal NullOffsetTime) After(other NullOffsetTime) bool
After reports whether thisVal is after other under sortable NULL semantics: NULL is never after any value (including another NULL).
func (NullOffsetTime) Before ¶ added in v0.3.0
func (thisVal NullOffsetTime) Before(other NullOffsetTime) bool
Before reports whether thisVal precedes other under sortable NULL semantics: NULL is strictly less than any valid value, two NULLs compare equal (so neither is Before the other).
func (NullOffsetTime) Compare ¶ added in v0.3.0
func (thisVal NullOffsetTime) Compare(other NullOffsetTime) int
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other under sortable NULL semantics.
func (NullOffsetTime) Equal ¶ added in v0.3.0
func (thisVal NullOffsetTime) Equal(other NullOffsetTime) bool
Equal reports whether thisVal and other are equal under sortable NULL semantics: two NULLs are equal; NULL is never equal to a valid value.
func (NullOffsetTime) In ¶ added in v0.3.0
func (thisVal NullOffsetTime) In(loc *time.Location) NullOffsetTime
In returns the same instant rendered in loc, mirroring OffsetTime.In. NULL propagates: an invalid receiver is returned unchanged.
func (*NullOffsetTime) IsEmpty ¶
func (thisVal *NullOffsetTime) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullOffsetTime) IsZero ¶
func (thisVal NullOffsetTime) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullOffsetTime) MarshalJSON ¶
func (thisVal NullOffsetTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in canonical offset time form, or null when empty. The valid path appends directly into a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal(formatOffsetTime(...)) would perform.
func (*NullOffsetTime) Scan ¶
func (thisVal *NullOffsetTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface, delegating to sql.NullTime so that the driver's NULL signalling is honoured.
func (NullOffsetTime) SubOk ¶ added in v0.3.0
func (thisVal NullOffsetTime) SubOk(other NullOffsetTime) (time.Duration, bool)
SubOk returns (thisVal − other, true) when both operands are valid, and (0, false) otherwise.
func (NullOffsetTime) ToString ¶
func (thisVal NullOffsetTime) ToString() string
ToString renders the value in the library's canonical offset time form, or "" when NULL.
func (NullOffsetTime) Truncate ¶ added in v0.3.0
func (thisVal NullOffsetTime) Truncate(d time.Duration) NullOffsetTime
Truncate returns thisVal rounded down to the nearest multiple of d since the zero time. NULL propagates.
func (NullOffsetTime) UTC ¶ added in v0.3.0
func (thisVal NullOffsetTime) UTC() NullOffsetTime
UTC is shorthand for In(time.UTC). NULL propagates.
func (*NullOffsetTime) UnmarshalJSON ¶
func (thisVal *NullOffsetTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string containing an offset time, or the token null. Any other input is treated as a parse error.
type NullString ¶
NullString is a nullable string. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullString ¶
func NewNullString(value string) NullString
NewNullString constructs a valid NullString wrapping value. The empty string is preserved as a valid value; use NewNullStringEmpty or NSFromString if an empty input should collapse to NULL.
func NewNullStringEmpty ¶
func NewNullStringEmpty() NullString
NewNullStringEmpty returns an invalid (NULL) NullString.
func (*NullString) IsEmpty ¶
func (thisVal *NullString) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullString) IsZero ¶
func (thisVal NullString) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullString) MarshalJSON ¶
func (thisVal NullString) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string, or null when empty.
func (*NullString) Scan ¶
func (thisVal *NullString) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface, delegating to sql.NullString so that the driver's NULL signalling is honoured.
func (NullString) ToString ¶
func (thisVal NullString) ToString() string
ToString returns the underlying string, or "" when NULL. Note that valid empty strings are indistinguishable from NULL in this output — use the Valid field directly to discriminate.
func (*NullString) UnmarshalJSON ¶
func (thisVal *NullString) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string or the token null. Surrounding quotes and JSON escape sequences are decoded via encoding/json.
type NullUUID ¶ added in v0.2.0
NullUUID is a nullable UUID backed by github.com/google/uuid. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullUUID ¶ added in v0.2.0
NewNullUUID constructs a valid NullUUID wrapping val.
func NewNullUUIDEmpty ¶ added in v0.2.0
func NewNullUUIDEmpty() NullUUID
NewNullUUIDEmpty returns an invalid (NULL) NullUUID.
func NullUUIDFromString ¶ added in v0.2.0
NullUUIDFromString parses a UUID from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullUUID.
func (*NullUUID) IsEmpty ¶ added in v0.2.0
IsEmpty reports whether the value is NULL (Valid == false).
func (NullUUID) IsZero ¶ added in v0.2.0
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullUUID) MarshalJSON ¶ added in v0.2.0
MarshalJSON renders the value as a JSON string in canonical UUID form, or null when empty.
func (*NullUUID) Scan ¶ added in v0.2.0
Scan implements the database/sql.Scanner interface. The UUID is received as text from the driver (via sql.NullString) and parsed through NullUUIDFromString.
func (NullUUID) ToString ¶ added in v0.2.0
ToString renders the UUID in canonical 8-4-4-4-12 hex form, or "" when NULL.
func (*NullUUID) UnmarshalJSON ¶ added in v0.2.0
UnmarshalJSON parses a JSON string containing a UUID, or the token null. Any other input is treated as a parse error.
type OffsetDateTime ¶
OffsetDateTime is a not-null datetime with a timezone offset (RFC 3339).
Use OffsetDateTime when the value is anchored to a specific point in time (e.g. an event timestamp). For wall-clock datetimes without an offset, use LocalDateTime.
func NewOffsetDateTime ¶
func NewOffsetDateTime(t time.Time) OffsetDateTime
NewOffsetDateTime wraps t as an OffsetDateTime, preserving its location.
func OffsetDateTimeFromString ¶
func OffsetDateTimeFromString(strValue string) (OffsetDateTime, error)
OffsetDateTimeFromString parses a datetime in any of the formats accepted by ParseDateTimeFromString.
func (OffsetDateTime) Add ¶ added in v0.3.0
func (thisVal OffsetDateTime) Add(d time.Duration) OffsetDateTime
Add returns thisVal shifted by d.
func (OffsetDateTime) AddDate ¶ added in v0.3.0
func (thisVal OffsetDateTime) AddDate(years, months, days int) OffsetDateTime
AddDate returns thisVal with the given years/months/days added.
func (OffsetDateTime) After ¶
func (thisVal OffsetDateTime) After(other OffsetDateTime) bool
After reports whether thisVal is after other.
func (OffsetDateTime) AsTime ¶
func (thisVal OffsetDateTime) AsTime() time.Time
AsTime returns the underlying time.Time.
func (OffsetDateTime) Before ¶
func (thisVal OffsetDateTime) Before(other OffsetDateTime) bool
Before reports whether thisVal precedes other.
func (OffsetDateTime) Compare ¶ added in v0.3.0
func (thisVal OffsetDateTime) Compare(other OffsetDateTime) int
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other.
func (OffsetDateTime) Day ¶ added in v0.3.0
func (thisVal OffsetDateTime) Day() int
Day returns the day of the month (1-31).
func (OffsetDateTime) Equal ¶ added in v0.3.0
func (thisVal OffsetDateTime) Equal(other OffsetDateTime) bool
Equal reports whether thisVal and other denote the same instant. Two values that differ only in zone (e.g. "10:00:00+04:00" and "06:00:00Z") are Equal.
func (OffsetDateTime) Hour ¶ added in v0.3.0
func (thisVal OffsetDateTime) Hour() int
Hour returns the hour of the day (0-23).
func (OffsetDateTime) In ¶ added in v0.3.0
func (thisVal OffsetDateTime) In(loc *time.Location) OffsetDateTime
In returns the same instant rendered in loc. Mirrors time.Time.In: the absolute moment is preserved, only the displayed offset / wall clock changes (e.g. "10:00:00+04:00" becomes "06:00:00Z" when converted to UTC).
func (OffsetDateTime) MarshalJSON ¶
func (thisVal OffsetDateTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in the library's canonical TZ-aware format.
func (OffsetDateTime) Minute ¶ added in v0.3.0
func (thisVal OffsetDateTime) Minute() int
Minute returns the minute of the hour (0-59).
func (OffsetDateTime) Month ¶ added in v0.3.0
func (thisVal OffsetDateTime) Month() time.Month
Month returns the calendar month.
func (OffsetDateTime) Nanosecond ¶ added in v0.3.0
func (thisVal OffsetDateTime) Nanosecond() int
Nanosecond returns the nanosecond offset within the second (0-999999999).
func (*OffsetDateTime) Scan ¶
func (thisVal *OffsetDateTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. A NULL value is rejected — OffsetDateTime cannot be empty.
func (OffsetDateTime) Second ¶ added in v0.3.0
func (thisVal OffsetDateTime) Second() int
Second returns the second of the minute (0-59).
func (OffsetDateTime) Sub ¶ added in v0.3.0
func (thisVal OffsetDateTime) Sub(other OffsetDateTime) time.Duration
Sub returns thisVal − other as a time.Duration.
func (OffsetDateTime) ToString ¶
func (thisVal OffsetDateTime) ToString() string
ToString renders the value in the library's canonical TZ-aware format.
func (OffsetDateTime) Truncate ¶ added in v0.3.0
func (thisVal OffsetDateTime) Truncate(d time.Duration) OffsetDateTime
Truncate returns thisVal rounded down to the nearest multiple of d since the zero time. Mirrors time.Time.Truncate.
func (OffsetDateTime) UTC ¶ added in v0.3.0
func (thisVal OffsetDateTime) UTC() OffsetDateTime
UTC is shorthand for In(time.UTC).
func (OffsetDateTime) Unix ¶
func (thisVal OffsetDateTime) Unix() int64
Unix returns the underlying instant as a Unix timestamp — the number of seconds elapsed since January 1, 1970 UTC.
func (OffsetDateTime) UnixMicro ¶ added in v0.3.0
func (thisVal OffsetDateTime) UnixMicro() int64
UnixMicro returns the underlying instant as microseconds since 1970-01-01 UTC.
func (OffsetDateTime) UnixMilli ¶ added in v0.3.0
func (thisVal OffsetDateTime) UnixMilli() int64
UnixMilli returns the underlying instant as milliseconds since 1970-01-01 UTC.
func (OffsetDateTime) UnixNano ¶ added in v0.3.0
func (thisVal OffsetDateTime) UnixNano() int64
UnixNano returns the underlying instant as nanoseconds since 1970-01-01 UTC.
func (*OffsetDateTime) UnmarshalJSON ¶
func (thisVal *OffsetDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string in any of the formats accepted by OffsetDateTimeFromString. JSON null is rejected — OffsetDateTime cannot be empty.
func (OffsetDateTime) Value ¶
func (thisVal OffsetDateTime) Value() (driver.Value, error)
Value implements the database/sql/driver.Valuer interface.
func (OffsetDateTime) Year ¶ added in v0.3.0
func (thisVal OffsetDateTime) Year() int
Year returns the calendar year (in the value's zone).
func (OffsetDateTime) YearDay ¶ added in v0.3.0
func (thisVal OffsetDateTime) YearDay() int
YearDay returns the day-of-year (1-365 / 1-366 in leap years).
type OffsetTime ¶
OffsetTime is a not-null time-of-day with a timezone offset.
Use OffsetTime when the time-of-day value carries a meaningful zone offset (e.g. exchange opens at "09:30:00-05:00"). For zone-less times, use LocalTime.
func NewOffsetTime ¶
func NewOffsetTime(t time.Time) OffsetTime
NewOffsetTime wraps t as an OffsetTime, preserving its location.
func OffsetTimeFromString ¶
func OffsetTimeFromString(strValue string) (OffsetTime, error)
OffsetTimeFromString parses a time-of-day with an optional timezone designator. When no designator is present, time.Local is assumed.
func (OffsetTime) Add ¶ added in v0.3.0
func (thisVal OffsetTime) Add(d time.Duration) OffsetTime
Add returns thisVal shifted by d. No modulo-24h enforcement: a duration that crosses midnight rotates the implicit date in the underlying time.Time, but the date is not part of OffsetTime's serialised form. Consume with care.
func (OffsetTime) After ¶ added in v0.3.0
func (thisVal OffsetTime) After(other OffsetTime) bool
After reports whether thisVal is after other.
func (OffsetTime) AsTime ¶
func (thisVal OffsetTime) AsTime() time.Time
AsTime returns the underlying time.Time.
func (OffsetTime) Before ¶ added in v0.3.0
func (thisVal OffsetTime) Before(other OffsetTime) bool
Before reports whether thisVal precedes other.
func (OffsetTime) Compare ¶ added in v0.3.0
func (thisVal OffsetTime) Compare(other OffsetTime) int
Compare returns -1, 0, or +1 as thisVal is before, equal to, or after other.
func (OffsetTime) Equal ¶ added in v0.3.0
func (thisVal OffsetTime) Equal(other OffsetTime) bool
Equal reports whether thisVal and other denote the same instant. Two values that differ only in zone (e.g. "10:00:00+04:00" and "06:00:00Z") are Equal.
func (OffsetTime) Hour ¶ added in v0.3.0
func (thisVal OffsetTime) Hour() int
Hour returns the hour of the day (0-23).
func (OffsetTime) In ¶ added in v0.3.0
func (thisVal OffsetTime) In(loc *time.Location) OffsetTime
In returns the same instant rendered in loc. Mirrors time.Time.In: only the wall-clock representation changes. The implicit date hidden in the underlying time.Time may shift by ±1 day across the zone boundary, but the date is not part of the OffsetTime serialised form.
func (OffsetTime) MarshalJSON ¶
func (thisVal OffsetTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in the library's canonical TZ-aware format.
func (OffsetTime) Minute ¶ added in v0.3.0
func (thisVal OffsetTime) Minute() int
Minute returns the minute of the hour (0-59).
func (OffsetTime) Nanosecond ¶ added in v0.3.0
func (thisVal OffsetTime) Nanosecond() int
Nanosecond returns the nanosecond offset within the second (0-999999999).
func (*OffsetTime) Scan ¶
func (thisVal *OffsetTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. A NULL value is rejected — OffsetTime cannot be empty.
func (OffsetTime) Second ¶ added in v0.3.0
func (thisVal OffsetTime) Second() int
Second returns the second of the minute (0-59).
func (OffsetTime) String ¶
func (thisVal OffsetTime) String() string
String renders the value in the library's canonical TZ-aware format.
func (OffsetTime) Sub ¶ added in v0.3.0
func (thisVal OffsetTime) Sub(other OffsetTime) time.Duration
Sub returns thisVal − other as a time.Duration. The implicit dates participate in the calculation (so a same-day pair yields a sub-24h difference), but Durations larger than 24h are possible if the operands were constructed at different days.
func (OffsetTime) ToString ¶
func (thisVal OffsetTime) ToString() string
ToString is an alias for String, satisfying the ToStringAble interface.
func (OffsetTime) Truncate ¶ added in v0.3.0
func (thisVal OffsetTime) Truncate(d time.Duration) OffsetTime
Truncate returns thisVal rounded down to the nearest multiple of d since the zero time.
func (OffsetTime) UTC ¶ added in v0.3.0
func (thisVal OffsetTime) UTC() OffsetTime
UTC is shorthand for In(time.UTC).
func (*OffsetTime) UnmarshalJSON ¶
func (thisVal *OffsetTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string in any of the formats accepted by OffsetTimeFromString. JSON null is rejected — OffsetTime cannot be empty.
type ToStringAble ¶
type ToStringAble interface {
ToString() string
}
ToStringAble is the interface implemented by every nullable type in the package. ToString renders the value in its canonical textual form (an empty string when the value is missing/NULL).
Source Files
¶
- date.go
- doc.go
- emptiable.go
- format_date.go
- format_local_datetime.go
- format_local_time.go
- format_offset_datetime.go
- format_offset_time.go
- local_datetime.go
- local_time.go
- null_bool.go
- null_date.go
- null_decimal.go
- null_float.go
- null_int16.go
- null_int32.go
- null_int64.go
- null_json.go
- null_local_datetime.go
- null_local_time.go
- null_offset_datetime.go
- null_offset_time.go
- null_string.go
- null_uuid.go
- offset_datetime.go
- offset_time.go
- string_able.go
- types_utils.go