chaining-date
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -1,1 +0,1 @@ | ||
var ChainingDate=function(){var t=function(t){return("0"+t).slice(-2)},n={YYYY:function(){return this.getYear()},YY:function(){return this.getYear()%100},MM:function(){return t(this.getMonth())},DD:function(){return t(this.getDate())},hh:function(){return t(this.getHours())},mm:function(){return t(this.getMinutes())},ss:function(){return t(this.getSeconds())}},e=["Time","Year","Month","Date","Day","Hours","Minutes","Seconds","Milliseconds"],i=Date,r=s.prototype,u=e.length;function s(t){this.date="number"==typeof t?new i(t):"string"==typeof t?new i(i.parse(t)):t||new i}for(s.setFormat=function(t,e){n[t]=e};u--;)!function(t){var n="add"+t,e="get"+t,i="set"+t;r[e]=function(){return this.date[e]()},r[i]=function(t){return this.date[i](t),this},r[n]=function(t){return this[i](this[e]()+t),this}}(e[u]);return r.getYear=function(){return this.date.getFullYear()},r.getMonth=function(){return this.date.getMonth()+1},r.setMonth=function(t){return this.date.setMonth(t-1),this},r.setDay=function(t){return this.addDate(t-this.getDay()),this},r.toString=function(t){var e=this;return t?t.replace(new RegExp(Object.keys(n).join("|"),"g"),(function(t){return n[t].call(e)})):this.date.toString()},s}(); | ||
var ChainingDate=function(){var t=function(t){return("0"+t).slice(-2)},n={YYYY:function(){return this.getYear()},YY:function(){return this.getYear()%100},MM:function(){return t(this.getMonth())},DD:function(){return t(this.getDate())},hh:function(){return t(this.getHours())},mm:function(){return t(this.getMinutes())},ss:function(){return t(this.getSeconds())}},e=["Year","Month","Date","Day","Hours","Minutes","Seconds","Milliseconds"],r=Date,i=s.prototype,u=e.length;function s(t){this.date="number"==typeof t?new r(t):"string"==typeof t?new r(r.parse(t)):t||new r}for(s.setFormat=function(t,e){n[t]=e};u--;)!function(t){var n="add"+t,e="get"+t,r="set"+t;i[e]=function(){return this.date[e]()},i[r]=function(t){return this.date[r](t),this},i[n]=function(t){return this[r](this[e]()+t),this}}(e[u]);return i.getYear=function(){return this.date.getFullYear()},i.getMonth=function(){return this.date.getMonth()+1},i.setMonth=function(t){return this.date.setMonth(t-1),this},i.setDay=function(t){return this.addDate(t-this.getDay()),this},i.toString=function(t){var e=this;return t?t.replace(new RegExp(Object.keys(n).join("|"),"g"),(function(t){return n[t].call(e)})):this.date.toString()},s}(); |
/** | ||
* @author TroyTae | ||
* @version 0.7.1 | ||
* @version 0.7.2 | ||
* @name chaining-date | ||
@@ -23,3 +23,2 @@ */ | ||
var DateMethods = [ | ||
'Time', | ||
'Year', | ||
@@ -26,0 +25,0 @@ 'Month', |
{ | ||
"name": "chaining-date", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"description": "A tiny module for using Date with chaining ⏱", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -16,3 +16,2 @@ var fillZero = function(number) { | ||
var DateMethods = [ | ||
'Time', | ||
'Year', | ||
@@ -19,0 +18,0 @@ 'Month', |
@@ -14,3 +14,2 @@ const ChainingDate = require('../dist/index'); | ||
const chainingDate = new ChainingDate(); | ||
expect(chainingDate.getTime()).toBe(today.getTime()); | ||
expect(chainingDate.getYear()).toBe(today.getFullYear()); | ||
@@ -27,5 +26,3 @@ expect(chainingDate.getMonth()).toBe(today.getMonth() + 1); | ||
test('setter', () => { | ||
const now = Date.now(); | ||
const chainingDate = new ChainingDate(); | ||
expect(chainingDate.setTime(now).getTime()).toBe(now); | ||
expect(chainingDate.setYear(year).getYear()).toBe(year); | ||
@@ -42,5 +39,3 @@ expect(chainingDate.setMonth(month).getMonth()).toBe(month); | ||
test('adder', () => { | ||
const today = new Date(); | ||
const chainingDate = new ChainingDate(); | ||
expect(chainingDate.setTime(today.getTime()).addTime(156473).getTime()).toBe(today.getTime() + 156473); | ||
expect(chainingDate.setYear(year).addYear(3).getYear()).toBe(year + 3); | ||
@@ -47,0 +42,0 @@ expect(chainingDate.setMonth(month).addMonth(1).getMonth()).toBe(month + 1); |
20222
428