Documentation
¶
Overview ¶
Package rawdate provides a simple date handling utility without time. It uses zero-based values for year, month, and day to maintain consistency with time.Time, where an uninitialized instance defaults to the year 0001-01-01.
Index ¶
- Constants
- Variables
- func Compare(a, b RawDate) int
- type RawDate
- func (r RawDate) AddDate(years, months, days int) RawDate
- func (r RawDate) Compare(a RawDate) int
- func (r RawDate) Day() int
- func (r RawDate) Format(format string) string
- func (r RawDate) IsValid() bool
- func (r RawDate) IsZero() bool
- func (r RawDate) Month() time.Month
- func (r RawDate) String() string
- func (r RawDate) Time(location *time.Location) time.Time
- func (r RawDate) Weekday() time.Weekday
- func (r RawDate) Year() int
Constants ¶
const ISODate = time.DateOnly
ISODate represents the format for a date-only value in ISO standard.
Variables ¶
var Zero = RawDate{0, 0, 0}
Zero represents a zero value for RawDate corresponding to the date 0001-01-01.
Functions ¶
Types ¶
type RawDate ¶
RawDate represents a date without time information. Year0, Month0, and Day0 are zero-based values for year, month, and day respectively. These fields are exported for marshaling purposes and should be used with the understanding that they are zero-based.
func MustNew ¶
MustNew creates a new RawDate given the year, month, and day. Panics if the provided values do not form a valid date.
func New ¶
New creates a new RawDate given the year, month, and day. Returns an error if the provided values do not form a valid date.
func Now ¶ added in v0.4.2
func Now() RawDate
Now creates a new RawDate with the current date (in local time)
func Parse ¶
Parse parses a string representing a date and returns the corresponding RawDate. An error is returned if the string does not represent a valid date.
func (RawDate) AddDate ¶ added in v0.3.3
AddDate adds the specified number of years, months, and days to the RawDate. Returns a new RawDate with the updated values.
func (RawDate) Compare ¶
Compare compares the RawDate with another RawDate. Returns 1 if r > a, -1 if r < a, and 0 if r == a.
func (RawDate) Time ¶
Time converts the RawDate to a time.Time value, with the provided location and zero time.