Git Product home page Git Product logo

date's Introduction

date

GoDoc Build Status Coverage Status Go Report Card Issues

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.
  • timespan.DateRange which expresses a period between two dates.
  • timespan.TimeSpan which expresses a duration of time between two instants (see RFC5545).
  • view.VDate which wraps Date for use in templates etc.

See package documentation for full documentation and examples.

See also period.Period, which implements periods corresponding to the ISO-8601 form (e.g. "PT30S").

Installation

go get github.com/rickb777/date/v2

Status

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

Version 2

Changes since v1:

  • The period.Period type has moved.
  • clock.Clock now has nanosecond resolution (formerly millisecond resolution).
  • date.Date is now an integer that holds the number of days since year zero. Previously, it was a struct based on year 1970.
  • date.Date time conversion methods have more explicit names - see table below.
  • date.Date arithmetic and comparison operations now rely on Go operators; the corresponding methods have been deleted - see table below.
  • date.Date zero value is now year 0 (Gregorian proleptic astronomical) so 1970 will no longer cause issues.
  • date.PeriodOfDays has been moved to timespan.PeriodOfDays
  • date.DateString has been deleted; the SQL driver.Valuer implementation is now pluggable and serves the same purpose more simply.

Renamed methods:

Was Use instead
date.Date.Local date.Date.Midnight
date.Date.UTC date.Date.MidnightUTC
date.Date.In date.Date.MidnightIn

Deleted methods and functions:

Was Use instead
date.Date.Add +
date.Date.Sub -
date.Date.IsZero == 0
date.Date.Equal ==
date.Date.Before <
date.Date.After >
date.IsLeap gregorian.IsLeap
date.DaysIn gregorian.DaysIn
timespan.DateRange.Normalise (not needed)

Any v1 dates persistently stored as integers will be incorrect; these can be corrected by adding 719162 (date.ZeroOffset) to them, which is the number of days between year zero (v2) and 1970 (v1). Dates stored as strings will be unaffected.

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.

date's People

Contributors

rickb777 avatar fxt avatar ali-ince avatar capnspacehook avatar tamalsaha avatar avalchev94 avatar magodo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.