date

package module
v0.0.0-...-89bacb1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2019 License: MIT Imports: 3 Imported by: 1

README

date

Build Status Documentation Coverage Status Go Report Card

Provides a data type Date that represents a day-precision point in time.

Date is conceptually similar to Unix time (also known as POSIX time or Unix Epoch time). But rather than operating at second-level precision, it operates at day-level precision. Under the hood, Date is an integer type that represents the number of days elapsed since the epoch date 1970-01-01.

date.Date leverages much of its functionality from the time package.

Features

  • Since Date is an integer type, the normal integer comparison and equality/inequality operators all work out of the box.

  • Conversions to and from ISO8601 (YYYY-MM-DD) string format.

  • Conversion to and from time.Time values.

  • Day, month, and year arithmetic (can add or subtract years, months, days from a Date).

  • Common date related operations, such as finding the start of a month, start of a quarter etc.

  • JSON marshal/unmarshal support.

  • SQL marshal/unmarshal support.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date int

Date represents a calendar day (and thus has day precision). It's stored as the number of days since the epoch date 1970-01-01. It can be negative, to represent dates before the epoch. Because it's a date, it doesn't exist within any particular timezone.

func FromString

func FromString(str string) (Date, error)

FromString creates a date from its ISO8601 (YYYY-MM-DD) representation.

func FromTime

func FromTime(t time.Time) Date

FromTime creates a Date by truncating away the time of day portion of a time.Time.

func Max

func Max(d1, d2 Date) Date

Max finds the maximum date (furthest in the direction of the future) out of the two given dates.

func Min

func Min(d1, d2 Date) Date

Min finds the minimum date (furthest in the direction of the past) out of the two given dates.

func MustFromString

func MustFromString(str string) Date

MustFromString creates a date from its ISO8601 (YYYY-MM-DD) representation. It panics if str is not in the right format.

func New

func New(year int, month time.Month, day int) Date

New creates a day given a year, month, and day.

func Today

func Today() Date

Today gives today's date.

func TodayIn

func TodayIn(loc *time.Location) Date

TodayIn gives today's date in given timezone.

func Tomorrow

func Tomorrow() Date

Tomorrow gives tomorrow's date.

func TomorrowIn

func TomorrowIn(loc *time.Location) Date

Tomorrow gives tomorrow's date in given timezone.

func Yesterday

func Yesterday() Date

Yesterday gives yesterday's date.

func YesterdayIn

func YesterdayIn(loc *time.Location) Date

Yesterday gives yesterday's date in given timezone.

func (Date) AddDays

func (d Date) AddDays(days int) Date

AddDays adds the number of specified days to create a new date. Since Dates are just integers representing the number of days since 1970-01-01, the usual `+` operator can be used instead.

func (Date) AddMonths

func (d Date) AddMonths(months int) Date

AddMonths adds the number of specified months to create a new date. Dates are normalized in the same way as `AddDate` in the `time` package.

func (Date) AddYears

func (d Date) AddYears(years int) Date

AddYears adds the number of specified years to create a new date. Dates are normalized in the same way as `AddDate` in the `time` package.

func (Date) Day

func (d Date) Day() int

Day gives the day of the month (1-31).

func (Date) DaysInMonth

func (d Date) DaysInMonth() int

DaysInMonth gives the number of days in the current month

func (Date) EndOfMonth

func (d Date) EndOfMonth() Date

EndOfMonth gives the date that is the last day of the current month.

func (Date) MarshalJSON

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

MarshalJSON marshals the date into a JSON string in ISO8601 format.

func (Date) Month

func (d Date) Month() time.Month

Month gives the month the date is in.

func (*Date) Scan

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

Scan implements the sql.Scanner interface, allowing the sql package to read sql dates into Date.

func (Date) StartOfMonth

func (d Date) StartOfMonth() Date

StartOfMonth gives the date that is the 1st day of the current month.

func (Date) StartOfNextQuarter

func (d Date) StartOfNextQuarter() Date

StartOfNextQuarter gives the date that is the 1st day of the next quarter (starting in Jan, Apr, Jul, or Oct).

func (Date) StartOfQuarter

func (d Date) StartOfQuarter() Date

StartOfQuarter gives the date that is the 1st day of the current quarter (starting in Jan, Apr, Jul, or Oct).

func (Date) String

func (d Date) String() string

String returns the ISO8601 representation (YYYY-MM-DD).

func (Date) Time

func (d Date) Time() time.Time

Time returns a time.Time at midnight at the start of the date in the UTC timezone.

func (Date) TimeIn

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

TimeIn returns a time.Time at midnight at the start of the date in the Location specified.

func (*Date) UnmarshalJSON

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

UnmarshalJSON unmarshals a JSON string in the ISO8601 format into a date.

func (Date) Value

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

Value implements the driver.Valuer interface, allowing sql drivers to send Dates to sql databases.

func (Date) Weekday

func (d Date) Weekday() time.Weekday

Weekday gives the day of the week that the date falls on.

func (Date) Year

func (d Date) Year() int

Year gives the year the date is in.

func (Date) YearDay

func (d Date) YearDay() int

YearDay gives how many days into the year the date is (1-365).

Jump to

Keyboard shortcuts

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