Documentation
¶
Overview ¶
Package godate providers functionality for working with dates. It follows the design of package time in the standard library.
Index ¶
- Constants
- func ValidateDate(year int, month time.Month, day int) error
- type Date
- func (d Date) Add(duration Duration) Date
- func (d Date) After(other Date) bool
- func (d Date) Before(other Date) bool
- func (d Date) Compare(other Date) int
- func (d Date) Date() (int, time.Month, int)
- func (d Date) Day() int
- func (d Date) Equal(other Date) bool
- func (d Date) IsZero() bool
- func (d Date) MarshalJSON() ([]byte, error)
- func (d Date) MarshalText() ([]byte, error)
- func (d Date) Month() time.Month
- func (d *Date) Scan(src any) error
- func (d Date) String() string
- func (d Date) Sub(other Date) Duration
- func (d Date) ToTime() time.Time
- func (d *Date) UnmarshalJSON(data []byte) error
- func (d *Date) UnmarshalText(data []byte) error
- func (d Date) Value() (driver.Value, error)
- func (d Date) Year() int
- type Duration
Constants ¶
const Day = Duration(1)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Date ¶
type Date uint32
A Date represent one date from range from "0001-01-01" to "9999-12-31"
A Date value can be used by multiple goroutines simultaneously except that the methods Date.UnmarshalJSON and Date.UnmarshalText are not concurrency-safe.
dates can be compared using the Date.Before, Date.After and Date.Equal methods. The Date.Sub method subtracts two dates, producing a Duration. The Date.Add method adds a Date and a Duration, producing a Date.
Representations of a Date value saved by the Date.MarshalJSON and Date.MarshalText methods.
func FromString ¶
FromString returns the date which corresponds given string. It function use time.Parse with time.DateOnly("2006-01-02") layout string so if it returns err FromString returns this error.
func MustNew ¶
MustNew returns date and error from given year, month and day. If year was out of range [1, 9999] and month was out of range [1, 12] and day was more than days count in month function called panic!
func New ¶
New returns date and error from given year, month and day. If year was out of range [1, 9999] and month was out of range [1, 12] and day was more than days count in month function returned error.
func ZeroDate ¶
func ZeroDate() Date
ZeroDate returns date which corresponds zero value Date - "0001-01-01" or 0.
func (Date) Compare ¶
Compare compares the date d with other. If t is before other, it returns -1; if t is after other, it returns +1; if they're the same, it returns 0.
func (Date) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. The date must be in the ISO 8601 format.
func (Date) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The output matches that of calling the Date.String method.
func (*Date) Scan ¶
Scan implements the [sql.Scanner].
Scan parse some value. If the value is nil the date will be zero. If the value holds string or []byte it calls FromString method; if the value holds time.Time it calls FromTime method; else Scan returns error.
func (Date) ToTime ¶
ToTime returns time.Time instant which corresponds Date with 0 minutes, 0 seconds etc and based on zero UTC offset.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. The date must be in the ISO 8601 format.
func (*Date) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The date must be in the ISO 8601 format.
func (Date) Value ¶
Value implements the driver.Valuer.
If Date.IsZero is true Value return nil as value for database; else it is false Value returns Date.String method's result.