Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Date ¶
Date is a custom type for representing dates (without time-of-day).
func (Date) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. It converts the Date into a JSON string (or null if invalid).
func (*Date) Scan ¶
Scan implements the sql.Scanner interface. It converts a database value into a Date, handling NULL, time.Time, []byte, and string inputs.
func (Date) String ¶
String returns the Date formatted as YYYY-MM-DD, or an empty string if invalid.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. It parses a JSON string into a Date, handling null and empty strings.
type String ¶
String is a custom type for handling nullable strings. It wraps a string value and a validity flag, similar to sql.NullString, but with extra helpers for JSON and convenience.
func (String) IsZero ¶
IsZero returns true if the String is invalid or contains an empty string. Useful for omitempty behavior in JSON or zero-value checks.
func (String) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. It encodes the string as a JSON string, or null if invalid.
func (String) Ptr ¶
Ptr returns a pointer to the underlying string value. Returns nil if the String is invalid. Useful for APIs expecting *string.
func (*String) Scan ¶
Scan implements the sql.Scanner interface. It converts database values into a String, supporting NULL, string, and []byte.
func (String) String ¶
String returns the underlying string value, or an empty string if invalid. Implements the fmt.Stringer interface.
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. It decodes JSON input into the String type, handling "null" as invalid.
type Time ¶
type Time struct {
Time time.Time // The stored time-of-day (date is always set to year 1, month 1, day 1, UTC)
Valid bool
}
Time is a custom type for representing only the time of day (HH:MM), without any associated date. It includes a validity flag to support NULL-like semantics for database and JSON operations.
func NewTime ¶
NewTime creates a new valid Time from a time.Time, stripping away the date and seconds while keeping only HH:MM.
func (Time) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. It converts the Time into a JSON string ("HH:MM") or null if invalid.
func (*Time) Scan ¶
Scan implements the sql.Scanner interface. It converts database values into a Time, handling NULL, time.Time, []byte, and string values.
func (Time) String ¶
String returns the Time formatted as "HH:MM", or an empty string if invalid. Implements the fmt.Stringer interface.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. It parses a JSON string into a Time, handling null and empty strings.
type Timestamp ¶
type Timestamp struct {
Time time.Time // The stored timestamp value, normalized to UTC
Valid bool
}
Timestamp is a custom type for handling full date-time values (with timezone), stored in RFC3339 format. It includes a validity flag to support NULL-like semantics for databases and JSON.
func CombineDateAndTime ¶
CombineDateAndTime creates a new valid Timestamp from separate Date and Time values,
func NewTimestamp ¶
NewTimestamp creates a new valid Timestamp from a time.Time, normalizing to UTC and truncating to the nearest second.
func (Timestamp) IsZero ¶
IsZero reports whether the Timestamp is invalid or represents the zero time.
func (Timestamp) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. It converts the Timestamp into a JSON string in RFC3339 format, or null if invalid.
func (*Timestamp) Scan ¶
Scan implements the sql.Scanner interface. It converts database values into a Timestamp, handling NULL, time.Time, []byte, and string values.
func (Timestamp) String ¶
String returns the Timestamp formatted in RFC3339, or an empty string if invalid. Implements the fmt.Stringer interface.
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. It parses a JSON string into a Timestamp, handling null and empty strings.