date

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 6 Imported by: 5

README

date

Date type implementation

Documentation

Overview

The package date implements special type to replace standard time.Time in places where ony date part is required.

Index

Constants

This section is empty.

Variables

View Source
var (
	Separator         byte = '-'
	DatabaseSeparator byte = '-'

	FiveYearBefore = Today().Add(-5, 0, 0)
	FiveYearAfter  = Today().Add(5, 0, 0)
)

Functions

func Converter

func Converter(value string) reflect.Value

func InitPreformattedValues

func InitPreformattedValues(from, to Date)

InitPreformattedValues

func YearsBetween

func YearsBetween(past, now Date) int

YearsBetween количество лет между двумя датами.

func YearsBetweenToday

func YearsBetweenToday(dt Date) int

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 New

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

New creates Date with specified year, month and day.

func NewFromTime

func NewFromTime(t time.Time) Date

NewFromTime creates Date from Time. Be careful with timezones.

func Null

func Null() Date

Null returns null Date.

func Parse

func Parse(s string) (Date, error)

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 Today

func Today() Date

Today returns today's date.

func (Date) Add

func (d Date) Add(years, months, days int) Date

Add adds years, months or days or all together.

func (Date) Date

func (d Date) Date() (int, time.Month, int)

func (Date) Day

func (d Date) Day() int

Day returns day of the date.

func (*Date) Format

func (d *Date) Format(s string) string

func (Date) In added in v0.3.0

func (d Date) In(loc *time.Location) time.Time

In convers Date to time.Time in specified location.

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json Marshaller interface.

func (Date) Month

func (d Date) Month() time.Month

Month returns month of the date.

func (*Date) Parse

func (d *Date) Parse(s string) error

Parse parses input string. String expected in format YYYY*MM*DD where * is any single char separator.

func (*Date) Scan

func (d *Date) Scan(value interface{}) error

Scan implements database/sql Scanner interface.

func (Date) String

func (d Date) String() string

String implements interface Stringer. Returns empty string if date is empty. If not, returns date as a string YYYY-MM-DD.

func (Date) Time

func (d Date) Time() time.Time

Time converts Date to Time.

func (Date) UTC

func (d Date) UTC() time.Time

UTC convert Date to time.Time in UTC zone.

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(b []byte) error

Scan implements encoding/json Unmarshaller interface.

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(b []byte) error

Scan implements encoding/json Unmarshaller interface.

func (Date) Valid

func (d Date) Valid() bool

Valid return false if Date is null.

func (Date) Value

func (d Date) Value() (driver.Value, error)

Value implements interface sql.Valuer

func (Date) Year

func (d Date) Year() int

Year returns year of the date.

Jump to

Keyboard shortcuts

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