Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/xtgo/epochdate

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/xtgo/epochdate

  • v1.2.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

epochdate

epochdate is a small library for storing contemporary dates (without time-of-day information) in 2 bytes per date, instead of the 16-20 bytes that are used by a time.Time value from the Go standard library.

epochdate.Date is a uint16 value representing the number of days since Jan 1 1970, with each value representing a whole calendar day. The maximum representable Date is Jun 6 2149. epochdate.YearMonth is a uint16 value representing the number of whole months Jan 1 1970, with each value representing a whole calendar month. The maximum representable YearMonth is Apr 7431, though for interoperability with Date, values above May or June 2149 should not be used.

Arithmetical operations on these types react predictably, for example, incrementing a Date is equivalent to "the following day," while adding 12 to a YearMonth is equivalent to "same month of the following year."

YearMonth operations

YearMonth enables simple date or time-alignment around month boundaries, for example:

// first day of current month
TodayUTC().YearMonth().StartDate()

// last day of current month
TodayUTC().YearMonth().EndDate()

// first day of next month
TodayUTC().YearMonth().EndDate() + 1

// ... or equivalently
(TodayUTC().YearMonth() + 1).StartDate()

// last time instant of the current month
TodayUTC().YearMonth.EndTime()

Encoding/Decoding

Both Date and YearMonth can be encoded to and from JSON, XML, and other string inputs.

Date values can be encoded to or from RFC-3339 dates (i.e. "2020-01-26")

YearDate values encode to a partial RFC-3339 date (i.e. "2020-01"), and can be decoded from either that same partial format, or a full date (i.e. "2020-01-26"), in which case the day portion of the input will be validated and discarded.

FAQs

Package last updated on 21 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc