Documentation ¶
Overview ¶
Package date provides a custom date type that omits time and timezone components, serving as a replacement for the standard time.Time type where only the date part is needed.
Index ¶
- Variables
- func InitPreformattedValues(from, to Date)
- type Date
- func (d Date) Add(years, months, days int) Date
- func (d Date) Day() int
- func (d Date) In(loc *time.Location) time.Time
- func (d Date) Month() time.Month
- func (d *Date) Parse(s string) error
- func (d *Date) Scan(value interface{}) error
- func (d Date) String() string
- func (d Date) Time() time.Time
- func (d Date) UTC() time.Time
- func (d Date) Valid() bool
- func (d Date) Value() (driver.Value, error)
- func (d Date) Year() int
Constants ¶
This section is empty.
Variables ¶
var ( Separator byte = '-' DatabaseSeparator byte = '-' // FiveYearBefore represents the date five years before today. FiveYearBefore = Today().Add(-5, 0, 0) // FiveYearAfter represents the date five years from today. FiveYearAfter = Today().Add(5, 0, 0) )
Predefined variables
Functions ¶
func InitPreformattedValues ¶
func InitPreformattedValues(from, to Date)
InitPreformattedValues initializes preformatted date values between a specified range. This function populates two maps, pfm and pjm, for date-to-string and string-to-date conversions, respectively, to optimize date marshaling and unmarshaling.
Types ¶
type Date ¶
type Date uint32
Date represents a nullable date type that excludes time and timezone information. Internally, it stores the year, month, and day as a combined hex integer (0xYYYYMMDD), making it comparable and sortable as an integer. In a database, it is stored as DATE. A null (empty) value is represented in memory as 0.
func Parse ¶
Parse converts a string in "YYYY-MM-DD" format into a Date. If the input string is enclosed in quotes, they are removed before parsing.
func (Date) Add ¶
Add returns a new Date that is the result of adding the specified number of years, months, and days to the original Date.
func (Date) In ¶ added in v0.3.0
In converts a Date to a time.Time instance in the specified location.
func (Date) String ¶
String returns the date as a string formatted as "YYYY-MM-DD". If the date is null, an empty string is returned.