New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

betterdate

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

betterdate

A 'BetterDate' is essentially a 'Date' that is easier and more intuitive to use than the built-in 'Date' class.

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

BetterDate

BetterDate is a JavaScript class just like the built-in Date, except:

  • Numeric month values are one-indexed like year and date (there is no year, month, or day zero), instead of zero-indexed.
  • Values can be modified with relative values using add* functions, instead of being absolute requiring both a set* and get* to be called to modify by a delta.
  • The time zone offset is modifiable, instead of being unmodifiable without modifying the interpretor's environment.
  • The time zone name is accessible as a separate property and is modifiable, instead of being, inaccessible and unmodifiable without modifying the interpretor's environment.
  • Week of the year information is accessible (as a fractional week, Math.floor the result for whole weeks or Math.ceil the result for ordinal/partial weeks).
  • Leap year information is available on instances for the year represented and on the class for any year in question.
  • Day of the week is still zero-indexed.
let betterDate = new BetterDate();

The '1' is one-indexed to intuitively mean 'January', not zero-indexed to mean 'February'.

betterDate = new BetterDate( 2017, 1, 26 );
new Date( betterDate );
// Thu Jan 26 2017 00:00:00 GMT-0600 (Central Standard Time)

Remove 10 hours from a 'BetterDate':

let epoch_ms = betterDate.addHours( -10 );
// 1485374400000
betterDate.toString();
// Wed Jan 25 2017 14:00:00 GMT-0600 (Central Standard Time)

Change the time zone offset (and name) without affecting the represented time.

betterDate.setTimezoneOffset( 480 );
betterDate.setTimezoneName( 'America/Los_Angeles' );
betterDate.toString();
// Wed Jan 25 2017 12:00:00 GMT-0800 (America/Los_Angeles)
new Date( betterDate );
// Wed Jan 25 2017 14:00:00 GMT-0600 (Central Standard Time)

Get week of year.

Math.ceil( betterDate.getWeeksOfYear());
// 4

Keywords

date

FAQs

Package last updated on 19 Feb 2019

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