Comparing version 0.0.2 to 0.1.0
15
index.js
@@ -7,3 +7,3 @@ const addDays = require('date-fns/add_days') | ||
class Dateism { | ||
constructor(format, seed) { | ||
constructor({format, seed} = {}) { | ||
this.formatPattern = format | ||
@@ -39,11 +39,14 @@ this.seed = seed || new Date() | ||
format (value) { | ||
return formatDate(value, this.formatPattern) | ||
if (this.formatPattern) { | ||
return formatDate(value, this.formatPattern) | ||
} | ||
return value.toISOString() | ||
} | ||
startOfDay () { | ||
return new Dateism(this.formatPattern, startOfDay(this.seed)) | ||
return new Dateism({format: this.formatPattern, seed: startOfDay(this.seed)}) | ||
} | ||
endOfDay () { | ||
return new Dateism(this.formatPattern, endOfDay(this.seed)) | ||
return new Dateism({format: this.formatPattern, seed: endOfDay(this.seed)}) | ||
} | ||
@@ -53,5 +56,5 @@ } | ||
module.exports = (format, seed) => { | ||
return new Dateism(format, seed) | ||
module.exports = ({format, seed} = {}) => { | ||
return new Dateism({format, seed}) | ||
} | ||
{ | ||
"name": "dateism", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Yesterday today and tomorrow", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,3 +20,3 @@ # dateism [](https://www.npmjs.com/package/dateism) [](https://www.npmjs.com/package/dateism) [](https://travis-ci.org/featurist/dateism) | ||
const dateism = require('dateism') | ||
const dates = dateism('DD MMM YYYY', new Date('1947-02-15')) | ||
const dates = dateism({format: 'DD MMM YYYY', seed: new Date('1947-02-15')}) | ||
@@ -23,0 +23,0 @@ dates.addDays(-5) // -> '10 Feb 1947' |
@@ -6,7 +6,7 @@ const expect = require('chai').expect | ||
it('returns date in x days in the specified format', () => { | ||
const dates = dateism('YYYY-MM-DD', new Date('2017-05-13')) | ||
const dates = dateism({format: 'YYYY-MM-DD', seed: new Date('2017-05-13')}) | ||
expect(dates.addDays(2)).to.eql('2017-05-15') | ||
}) | ||
it('returns todays date in the specified format', () => { | ||
const dates = dateism('YYYY-MM-DD', new Date('2017-05-13')) | ||
const dates = dateism({format: 'YYYY-MM-DD', seed: new Date('2017-05-13')}) | ||
expect(dates.today()).to.eql('2017-05-13') | ||
@@ -16,3 +16,3 @@ }) | ||
it('returns yesterdays date in the specified format', () => { | ||
const dates = dateism('YYYY-MM-DD', new Date('2017-05-13')) | ||
const dates = dateism({format: 'YYYY-MM-DD', seed: new Date('2017-05-13')}) | ||
expect(dates.yesterday()).to.eql('2017-05-12') | ||
@@ -22,3 +22,3 @@ }) | ||
it('returns the date from two days ago in the specified format', () => { | ||
const dates = dateism('YYYY-MM-DD', new Date('2017-05-13')) | ||
const dates = dateism({format: 'YYYY-MM-DD', seed: new Date('2017-05-13')}) | ||
expect(dates.twoDaysAgo()).to.eql('2017-05-11') | ||
@@ -28,3 +28,3 @@ }) | ||
it('returns the date from three days ago in the specified format', () => { | ||
const dates = dateism('YYYY-MM-DD', new Date('2017-05-13')) | ||
const dates = dateism({format: 'YYYY-MM-DD', seed: new Date('2017-05-13')}) | ||
expect(dates.threeDaysAgo()).to.eql('2017-05-10') | ||
@@ -34,3 +34,3 @@ }) | ||
it('returns tomorrows date in the specified format', () => { | ||
const dates = dateism('YYYY-MM-DD', new Date('2017-05-13')) | ||
const dates = dateism({format: 'YYYY-MM-DD', seed: new Date('2017-05-13')}) | ||
expect(dates.tomorrow()).to.eql('2017-05-14') | ||
@@ -40,3 +40,3 @@ }) | ||
it('returns the days date at the start of the day', () => { | ||
const dates = dateism('YYYY-MM-DDTHH:mm:ss', new Date('2017-05-13T13:56:12')) | ||
const dates = dateism({format: 'YYYY-MM-DDTHH:mm:ss', seed: new Date('2017-05-13T13:56:12')}) | ||
expect(dates.startOfDay().today()).to.eql('2017-05-13T00:00:00') | ||
@@ -46,5 +46,10 @@ }) | ||
it('returns the days date at the end of the day', () => { | ||
const dates = dateism('YYYY-MM-DDTHH:mm:ss', new Date('2017-05-13T13:56:12')) | ||
const dates = dateism({format: 'YYYY-MM-DDTHH:mm:ss', seed: new Date('2017-05-13T13:56:12')}) | ||
expect(dates.endOfDay().today()).to.eql('2017-05-13T23:59:59') | ||
}) | ||
it('specifying no format defaults to UTC ISO string', () => { | ||
const dates = dateism({seed: new Date('2017-05-13T13:00:00Z')}) | ||
expect(dates.addDays(1)).to.eql('2017-05-14T13:00:00.000Z') | ||
}) | ||
}) |
5075
84