Categorygithub.com/voltusdev/date
modulepackage
1.20.0
Repository: https://github.com/voltusdev/date.git
Documentation: pkg.go.dev

# README

date

This package is forked from https://github.com/rickb777/date. It is unmodified beyond using 32-bit integers to store Period components internally (instead of 16-bit components) to avoid integer overflows. The upstream package is itself being deprecated in favor of a replacement that addresses the overflow issue, but the replacement package is under active development and not yet ready for production use.

Package date provides functionality for working with dates.

This package introduces a light-weight Date type that is storage-efficient and convenient for calendrical calculations and date parsing and formatting (including years outside the [0,9999] interval).

It also provides

  • clock.Clock which expresses a wall-clock style hours-minutes-seconds with millisecond precision.
  • period.Period which expresses a period corresponding to the ISO-8601 form (e.g. "PT30S").
  • timespan.DateRange which expresses a period between two dates.
  • timespan.TimeSpan which expresses a duration of time between two instants.
  • view.VDate which wraps Date for use in templates etc.

See package documentation for full documentation and examples.

Installation

go get -u github.com/voltusdev/date

or

dep ensure -add github.com/voltusdev/date

Status

This library has been in reliable production use for some time. Versioning follows the well-known semantic version pattern.

Credits

This package follows very closely the design of package time in the standard library; many of the Date methods are implemented using the corresponding methods of the time.Time type and much of the documentation is copied directly from that package.

The original Good Work on which this was based was done by Filippo Tampieri at Fxtlabs.

# Packages

Package clock specifies a time of day with resolution to the nearest millisecond.
This tool prints equivalences between the string representation and the internal numerical representation for dates and clocks.
Package gregorian provides utility functions for the Gregorian calendar calculations.
Package period provides functionality for periods of time using ISO-8601 conventions.
Package timespan provides spans of time (TimeSpan), and ranges of dates (DateRange).
Package view provides a simple API for formatting dates as strings in a manner that is easy to use in view-models, especially when using Go templates.

# Functions

AutoParse is like ParseISO, except that it automatically adapts to a variety of date formats provided that they can be detected unambiguously.
DaysIn gives the number of days in a given month, according to the Gregorian calendar.
IsLeap simply tests whether a given year is a leap year, using the Gregorian calendar algorithm.
Max returns the largest representable date.
Min returns the smallest representable date.
MustAutoParse is as per AutoParse except that it panics if the string cannot be parsed.
MustParse is as per Parse except that it panics if the string cannot be parsed.
MustParseISO is as per ParseISO except that it panics if the string cannot be parsed.
New returns the Date value corresponding to the given year, month, and day.
NewAt returns the Date value corresponding to the given time.
NewOfDays returns the Date value corresponding to the given period since the epoch (1st January 1970), which may be negative.
Parse parses a formatted string of a known layout and returns the Date value it represents.
ParseISO parses an ISO 8601 formatted string and returns the date value it represents.
Today returns today's date according to the current local time.
TodayIn returns today's date according to the current time relative to the specified location.
TodayUTC returns today's date according to the current UTC time.

# Constants

ISO 8601 extended format.
ISO 8601 basic format.
These are predefined layouts for use in Date.Format and Date.Parse.
RFC1123 with day of the week.
These are predefined layouts for use in Date.Format and Date.Parse.
These are predefined layouts for use in Date.Format and Date.Parse.
RFC822 with day of the week.
These are predefined layouts for use in Date.Format and Date.Parse.
ZeroDays is the named zero value for PeriodOfDays.

# Variables

DaySuffixes is the default array of strings used as suffixes when a format string contains "nd" (as in "second").
DisableTextStorage reduces the Scan method so that only integers are handled.

# Structs

A Date represents a date under the (proleptic) Gregorian calendar as used by ISO 8601.

# Type aliases

DateString alters Date to make database storage use a string column, or a similar derived column such as SQL DATE.
PeriodOfDays describes a period of time measured in whole days.