Giter Site home page Giter Site logo

epoq's Introduction

Epoq

Epoq is two classes to help tame excess precision in the Date object.

DateWithoutTime implements a "whole date", keeping you from having to worry about javascript's implicit introduction of timezones. Create it however you want, it will not introduce an unwanted timezone or alter the date part...

const a = new DateWithoutTime("2022-12-25");
const b = new DateWithoutTime("2022-12-25T23:55:00");
const c = new DateWithoutTime("2022-12-25T23:55:00Z");
const d = new DateWithoutTime(new Date());
const e = new DateWithoutTime(19_180); // days since epoch

Use the familiar Date methods to serialize or access parts, you will never get a time or timezone, just the date you expect...

  toISOString()
  getDate()
  getDay()
  getFullYear()
  getMonth()
  getDaysSinceEpoch()
  setDate(date: number)
  setFullYear(year: number)
  setMonth(arg: number)
  addDays(days: number)
  toString()
  toLocaleDateString(locale?: string, options?: object): string 

Week implements the notion of an integer week since the epoch, easily convertible to a Date(), with methods to convert to and from week of year. Create one however you like...

a = new Week(2740);
b = new Week("1970-01-01")
c = new Week(new Date(1970,0,1))
d = new Week(2022,52)

Then use get at its parts

weekSinceEpoch: number
weekOfYear: number
year: number
monday: DateWithoutTime
friday: DateWithoutTime
sunday: DateWithoutTime
numberOfWeeksInYear: number
getNumberOfWeeksInYear(year: number): number
toString()
toLocaleStringFull({ locale }: IOptions)

As such, days and weeks can be sequential whole numbers in your application and in your database.

epoq's People

Contributors

bbsimonbb 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.