Skip to content

Latest commit

 

History

History
230 lines (151 loc) · 4.94 KB

README.md

File metadata and controls

230 lines (151 loc) · 4.94 KB

Better Times

CircleCI

Better times is a small .js file that makes dates (in JavaScript) fun again.

Table of Content

Goal

The goal of Better Times is to make date manipulation in JavaScript easier and safer.

Functions

The following functions are added to the Date.prototype

Date.prototype.add

Add to the date the relevant time unit.

Usages

let date = new Date('2010-01-01T00:00:00.000Z');
date.add('years', 1); // change date to: 2011-01-01T00:00:00.000Z

Date.prototype.subtract

Subtract to the date the relevant time unit.

Usages

let date = new Date('2011-01-01T00:00:00.000Z');
date.subtract('years', 1); // change date to: 2010-01-01T00:00:00.000Z

Date.prototype.nextDay

Change date to the next day

Usages

let date = new Date('2010-01-01T00:00:00.000Z');
date.nextDay(); // change date to: 2010-01-02T00:00:00.000Z

Date.prototype.nextWeek

Change date to the next week

Usages

let date = new Date('2010-01-01T00:00:00.000Z');
date.nextWeek(); // change date to: 2010-01-08T00:00:00.000Z

Date.prototype.nextMonth

Change date to the next month

Usages

let date = new Date('2010-01-01T00:00:00.000Z');
date.nextMonth(); // change date to: 2010-02-01T00:00:00.000Z

Date.prototype.nextYear

Change date to the next year

Usages

let date = new Date('2010-01-01T00:00:00.000Z');
date.nextYear(); // change date to: 2011-01-01T00:00:00.000Z

Date.prototype.prevDay

Change date to the previous day

Usages

let date = new Date('2010-01-02T00:00:00.000Z');
date.prevDay(); // change date to: 2010-01-01T00:00:00.000Z

Date.prototype.prevWeek

Change date to the previous week

Usages

let date = new Date('2010-01-08T00:00:00.000Z');
date.prevWeek(); // change date to: 2010-01-01T00:00:00.000Z

Date.prototype.prevMonth

Change date to the previous month

Usages

let date = new Date('2010-02-01T00:00:00.000Z');
date.prevMonth(); // change date to: 2010-01-01T00:00:00.000Z

Date.prototype.prevYear

Change date to the previous year

Usages

let date = new Date('2010-02-01T00:00:00.000Z');
date.prevYear(); // change date to: 2010-01-01T00:00:00.000Z

Date.prototype.endOf

Date.prototype.endOfDay

Change date to the end of the day.

Usages

let date = new Date('2010-01-01T00:00:00.000Z');
date.endOfDay(); // change date to: 2010-01-01T23:59:59.000Z

Date.prototype.endOfMonth

Change date to the end of the month and day.

Usages

let date = new Date('2010-01-01T00:00:00.000Z');
date.endOfMonth(); // change date to: 2010-01-31T23:59:59.000Z

Date.prototype.endOfYear

Change date to the end of the year and day.

Usages

let date = new Date('2010-01-01T00:00:00.000Z');
date.endOfYear(); // change date to: 2010-12-31T23:59:59.000Z

Date.prototype.startOf

Date.prototype.startOfDay

Change date to the start of the day.

Usages

let date = new Date('2010-01-01T23:59:59.000Z');
date.startOfDay(); // change date to: 2010-01-01T00:00:00.000Z

Date.prototype.startOfMonth

Change date to the start of the month and the day.

Usages

let date = new Date('2010-01-31T23:59:59.000Z');
date.startOfMonth(); // change date to: 2010-01-01T00:00:00.000Z

Date.prototype.startOfYear

Change date to the start of the year and the day.

Usages

let date = new Date('2010-12-31T23:59:59.000Z');
date.startOfYear(); // change date to: 2010-01-01T00:00:00.000Z

Time unit

Note: All time units should end with an 's', if not, the 's' is added automatically

  • seconds
  • minutes
  • hours
  • days
  • weeks
  • months
  • years

Contribute

PRs and issues are more then welcome.