rawdate

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 3 Imported by: 0

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

View Source
const ISODate = time.DateOnly

ISODate represents the format for a date-only value in ISO standard.

Variables

View Source
var Zero = RawDate{0, 0, 0}

Zero represents a zero value for RawDate corresponding to the date 0001-01-01.

Functions

func Compare

func Compare(a, b RawDate) int

Compare compares two RawDates. Returns 1 if a > b, -1 if a < b, and 0 if a == b.

Types

type RawDate

type RawDate struct {
	Year0  int
	Month0 int8
	Day0   int8
}

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 FromTime

func FromTime(t time.Time) RawDate

FromTime creates a RawDate from a time.Time value, ignoring the time portion.

func MustNew

func MustNew(y int, m time.Month, d int) RawDate

MustNew creates a new RawDate given the year, month, and day. Panics if the provided values do not form a valid date.

func New

func New(y int, m time.Month, d int) (RawDate, error)

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

func Parse(layout, s string) (RawDate, error)

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

func (r RawDate) AddDate(years, months, days int) RawDate

AddDate adds the specified number of years, months, and days to the RawDate. Returns a new RawDate with the updated values.

func (RawDate) Compare

func (r RawDate) Compare(a RawDate) int

Compare compares the RawDate with another RawDate. Returns 1 if r > a, -1 if r < a, and 0 if r == a.

func (RawDate) Day

func (r RawDate) Day() int

Day returns the day of the month for the RawDate.

func (RawDate) Format

func (r RawDate) Format(format string) string

Format formats the RawDate according to the provided layout string.

func (RawDate) IsValid

func (r RawDate) IsValid() bool

IsValid checks whether the RawDate represents a valid date.

func (RawDate) IsZero added in v0.3.2

func (r RawDate) IsZero() bool

IsZero checks if the RawDate is a zero date.

func (RawDate) Month

func (r RawDate) Month() time.Month

Month returns the month of the year for the RawDate.

func (RawDate) String

func (r RawDate) String() string

String returns a string representation of the RawDate in YYYY-MM-DD format.

func (RawDate) Time

func (r RawDate) Time(location *time.Location) time.Time

Time converts the RawDate to a time.Time value, with the provided location and zero time.

func (RawDate) Weekday added in v0.4.0

func (r RawDate) Weekday() time.Weekday

Weekday calculates and returns the day of the week for the RawDate.

func (RawDate) Year

func (r RawDate) Year() int

Year returns the year for the RawDate.

Jump to

Keyboard shortcuts

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