Documentation ¶
Overview ¶
The package date implements special type to replace standard time.Time in places where ony date part is required.
Index ¶
- Variables
- func Converter(value string) reflect.Value
- func InitPreformattedValues(from, to Date)
- func YearsBetween(past, now Date) int
- func YearsBetweenToday(dt Date) int
- type Date
- func (d Date) Add(years, months, days int) Date
- func (d Date) Date() (int, time.Month, int)
- func (d Date) Day() int
- func (d *Date) Format(s string) string
- func (d Date) In(loc *time.Location) time.Time
- func (d Date) MarshalJSON() ([]byte, error)
- 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) UnmarshalJSON(b []byte) error
- func (d *Date) UnmarshalText(b []byte) error
- 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 = Today().Add(-5, 0, 0) FiveYearAfter = Today().Add(5, 0, 0) )
Functions ¶
func YearsBetween ¶
YearsBetween количество лет между двумя датами.
func YearsBetweenToday ¶
Types ¶
type Date ¶
type Date uint32
Date is an nullable date type without time and timezone. In memory it stores year, month and day like joined hex integer 0x20180131 what makes it comparable and sortable as integer. In database it stores as DATE. Null value is represented in memory as 0.
func NewFromTime ¶
NewFromTime creates Date from Time. Be careful with timezones.
func Parse ¶
Parse decodes string YYYY-MM-DD or quoted "YYYY-MM-DD" to Date. TODO: improve performance by implementing date parsing without calling time.Parse().
func (Date) MarshalJSON ¶
MarshalJSON implements encoding/json Marshaller interface.
func (*Date) Parse ¶
Parse parses input string. String expected in format YYYY*MM*DD where * is any single char separator.
func (Date) String ¶
String implements interface Stringer. Returns empty string if date is empty. If not, returns date as a string YYYY-MM-DD.
func (*Date) UnmarshalJSON ¶
Scan implements encoding/json Unmarshaller interface.
func (*Date) UnmarshalText ¶
Scan implements encoding/json Unmarshaller interface.