chaining-date
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -1,1 +0,1 @@ | ||
var ChainingDate=function(){var t={YYYY:"FullYear",MM:"Month",DD:"Date",D:"Day",hh:"Hours",mm:"Minutes",ss:"Seconds",sss:"Milliseconds"},n=Date;function e(t){this.date="number"==typeof t?new n(t):"string"==typeof t?new n(n.parse(t)):t||new n}var r=e.prototype;return r.add=function(){return this},r.set=function(n,e){return this.date["set"+t[n]](e),this},r.get=function(n,e){return this.date["get"+t[n]](e)},r.toString=function(t){var n=this.date;return t?n:n.toString()},e}(); | ||
var ChainingDate=function(){var t="MM",n={["YYYY"]:"FullYear",[t]:"Month",["DD"]:"Date",["D"]:"Day",["hh"]:"Hours",["mm"]:"Minutes",["ss"]:"Seconds",["sss"]:"Milliseconds"},e=Date;function r(t){this.date="number"==typeof t?new e(t):"string"==typeof t?new e(e.parse(t)):t||new e}var i=r.prototype;return i.add=function(){return this},i.set=function(e,r){return this.date["set"+n[e]](e===t?r-1:r),this},i.get=function(e){var r=this.date["get"+n[e]]();return e===t&&(r+=1),r},i.toString=function(t){var n=this.date;return t?n:n.toString()},r}(); |
/** | ||
* @author TroyTae | ||
* @version 0.4.1 | ||
* @version 0.4.2 | ||
* @name chaining-date | ||
@@ -9,12 +9,23 @@ */ | ||
var DateFormat = { | ||
YYYY: 'FullYear', | ||
MM: 'Month', | ||
DD: 'Date', | ||
D: 'Day', | ||
hh: 'Hours', | ||
mm: 'Minutes', | ||
ss: 'Seconds', | ||
sss: 'Milliseconds', | ||
year: 'YYYY', | ||
month: 'MM', | ||
date: 'DD', | ||
day: 'D', | ||
hour: 'hh', | ||
minute: 'mm', | ||
second: 'ss', | ||
millisecond: 'sss', | ||
}; | ||
var DateFormatMethod = { | ||
[DateFormat.year]: 'FullYear', | ||
[DateFormat.month]: 'Month', | ||
[DateFormat.date]: 'Date', | ||
[DateFormat.day]: 'Day', | ||
[DateFormat.hour]: 'Hours', | ||
[DateFormat.minute]: 'Minutes', | ||
[DateFormat.second]: 'Seconds', | ||
[DateFormat.millisecond]: 'Milliseconds', | ||
}; | ||
var D = Date; | ||
@@ -34,7 +45,12 @@ function ChainingDate(date) { | ||
P.set = function (format, value) { | ||
this.date['set' + DateFormat[format]](value); | ||
this.date['set' + DateFormatMethod[format]] | ||
(format === DateFormat.month ? value - 1 : value); | ||
return this; | ||
}; | ||
P.get = function (format, value) { | ||
return this.date['get' + DateFormat[format]](value); | ||
P.get = function (format) { | ||
var v = this.date['get' + DateFormatMethod[format]](); | ||
if (format === DateFormat.month) { | ||
v += 1; | ||
} | ||
return v; | ||
}; | ||
@@ -41,0 +57,0 @@ P.toString = function (pattern) { |
{ | ||
"name": "chaining-date", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "A tiny module for using Date with chaining ⏱", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,2 +0,2 @@ | ||
import { DateFormat } from './constants'; | ||
import { DateFormat, DateFormatMethod } from './constants'; | ||
@@ -17,7 +17,12 @@ var D = Date; | ||
P.set = function (format, value) { | ||
this.date['set' + DateFormat[format]](value); | ||
this.date['set' + DateFormatMethod[format]] | ||
(format === DateFormat.month ? value - 1 : value); | ||
return this; | ||
}; | ||
P.get = function (format, value) { | ||
return this.date['get' + DateFormat[format]](value); | ||
P.get = function (format) { | ||
var v = this.date['get' + DateFormatMethod[format]](); | ||
if (format === DateFormat.month) { | ||
v += 1; | ||
} | ||
return v; | ||
}; | ||
@@ -24,0 +29,0 @@ P.toString = function (pattern) { |
var DateFormat = { | ||
YYYY: 'FullYear', | ||
MM: 'Month', | ||
DD: 'Date', | ||
D: 'Day', | ||
hh: 'Hours', | ||
mm: 'Minutes', | ||
ss: 'Seconds', | ||
sss: 'Milliseconds', | ||
year: 'YYYY', | ||
month: 'MM', | ||
date: 'DD', | ||
day: 'D', | ||
hour: 'hh', | ||
minute: 'mm', | ||
second: 'ss', | ||
millisecond: 'sss', | ||
}; | ||
export { DateFormat }; | ||
var DateFormatMethod = { | ||
[DateFormat.year]: 'FullYear', | ||
[DateFormat.month]: 'Month', | ||
[DateFormat.date]: 'Date', | ||
[DateFormat.day]: 'Day', | ||
[DateFormat.hour]: 'Hours', | ||
[DateFormat.minute]: 'Minutes', | ||
[DateFormat.second]: 'Seconds', | ||
[DateFormat.millisecond]: 'Milliseconds', | ||
}; | ||
export { | ||
DateFormat, | ||
DateFormatMethod | ||
}; |
@@ -7,3 +7,3 @@ const ChainingDate = require('../dist/index'); | ||
expect(chainingDate.get('YYYY')).toBe(date.getFullYear()); | ||
expect(chainingDate.get('MM')).toBe(date.getMonth()); | ||
expect(chainingDate.get('MM')).toBe(date.getMonth() + 1); | ||
expect(chainingDate.get('DD')).toBe(date.getDate()); | ||
@@ -16,1 +16,11 @@ expect(chainingDate.get('D')).toBe(date.getDay()); | ||
}); | ||
test('setter', () => { | ||
const year = 1997; | ||
const month = 7; | ||
const date = 21; | ||
const chainingDate = new ChainingDate(); | ||
expect(chainingDate.set('YYYY', year).get('YYYY')).toBe(year); | ||
expect(chainingDate.set('MM', month).get('MM')).toBe(month); | ||
expect(chainingDate.set('DD', date).get('DD')).toBe(date); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14249
304