Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

easy-date

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-date - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

.flowconfig

211

easy-date-light.js

@@ -39,10 +39,30 @@ /******/ (function(modules) { // webpackBootstrap

/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules

@@ -63,172 +83,33 @@ /******/ __webpack_require__.n = function(module) {

/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ return __webpack_require__(__webpack_require__.s = "./src/easy-date.js");
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/******/ ({
/***/ "./src/date-format.js":
/*!****************************!*\
!*** ./src/date-format.js ***!
\****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n/*\n * Date Format 1.2.3\n * (c) 2007-2009 Steven Levithan <stevenlevithan.com>\n * MIT license\n *\n * Includes enhancements by Scott Trenda <scott.trenda.net>\n * and Kris Kowal <cixar.com/~kris.kowal/>\n *\n * Accepts a date, a mask, or a date and a mask.\n * Returns a formatted version of the given date.\n * The date defaults to the current date/time.\n * The mask defaults to dateFormat.masks.default.\n */\n\nvar dateFormat = function () {\n var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\\1?|[LloSZ]|\"[^\"]*\"|'[^']*'/g;\n var timezone = /\\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\\d{4})?)\\b/g;\n var timezoneClip = /[^-+\\dA-Z]/g;\n\n var pad = function pad(val, len) {\n val = String(val);\n len = len || 2;\n while (val.length < len) {\n val = '0' + val;\n }\n return val;\n };\n\n // Regexes and supporting functions are cached through closure\n return function (date, mask, utc) {\n var dF = dateFormat;\n // You can't provide utc if you skip other args (use the \"UTC:\" mask prefix)\n if (arguments.length === 1 && Object.prototype.toString.call(date) === '[object String]' && !/\\d/.test(date)) {\n mask = date;\n date = undefined;\n }\n // Passing date through Date applies Date.parse, if necessary\n date = date ? new Date(date) : new Date();\n if (isNaN(date)) {\n throw SyntaxError('invalid date');\n }\n mask = String(dF.masks[mask] || mask || dF.masks['default']);\n // Allow setting the utc argument via the mask\n if (mask.slice(0, 4) === 'UTC:') {\n mask = mask.slice(4);\n utc = true;\n }\n var _ = utc ? 'getUTC' : 'get';\n var d = date[_ + 'Date']();\n var D = date[_ + 'Day']();\n var m = date[_ + 'Month']();\n var y = date[_ + 'FullYear']();\n var H = date[_ + 'Hours']();\n var M = date[_ + 'Minutes']();\n var s = date[_ + 'Seconds']();\n var L = date[_ + 'Milliseconds']();\n var o = utc ? 0 : date.getTimezoneOffset();\n var flags = {\n d: d,\n dd: pad(d),\n ddd: dF.i18n.dayNames[D],\n dddd: dF.i18n.dayNames[D + 7],\n m: m + 1,\n mm: pad(m + 1),\n mmm: dF.i18n.monthNames[m],\n mmmm: dF.i18n.monthNames[m + 12],\n yy: String(y).slice(2),\n yyyy: y,\n h: H % 12 || 12,\n hh: pad(H % 12 || 12),\n H: H,\n HH: pad(H),\n M: M,\n MM: pad(M),\n s: s,\n ss: pad(s),\n l: pad(L, 3),\n L: pad(L > 99 ? Math.round(L / 10) : L),\n t: H < 12 ? 'a' : 'p',\n tt: H < 12 ? 'am' : 'pm',\n T: H < 12 ? 'A' : 'P',\n TT: H < 12 ? 'AM' : 'PM',\n Z: utc ? 'UTC' : (String(date).match(timezone) || ['']).pop().replace(timezoneClip, ''),\n o: (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),\n S: ['th', 'st', 'nd', 'rd'][d % 10 > 3 ? 0 : (d % 100 - d % 10 !== 10) * d % 10]\n };\n return mask.replace(token, function ($0) {\n if ($0 in flags) {\n return flags[$0];\n } else {\n return $0.slice(1, $0.length - 1);\n }\n });\n };\n}();\n// Some common format strings\ndateFormat.masks = {\n 'default': 'ddd mmm dd yyyy HH:MM:ss',\n shortDate: 'm/d/yy',\n mediumDate: 'mmm d, yyyy',\n longDate: 'mmmm d, yyyy',\n fullDate: 'dddd, mmmm d, yyyy',\n shortTime: 'h:MM TT',\n mediumTime: 'h:MM:ss TT',\n longTime: 'h:MM:ss TT Z',\n isoDate: 'yyyy-mm-dd',\n isoTime: 'HH:MM:ss',\n isoDateTime: 'yyyy-mm-dd\\'T\\'HH:MM:ss',\n isoUtcDateTime: 'UTC:yyyy-mm-dd\\'T\\'HH:MM:ss\\'Z\\''\n};\n// Internationalization strings\ndateFormat.i18n = {\n dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']\n};\n\n// For convenience...\nif (Date.prototype.format === undefined) {\n Date.prototype.format = function (mask, utc) {\n return dateFormat(this, mask, utc);\n };\n}\n\nexports.default = dateFormat;\n\n//# sourceURL=webpack:///./src/date-format.js?");
/***/ }),
/*
* EasyDate
* is a Javascript extension for easy dates manipulations which is heavily inspired by Rails ActiveSupport::Duration class.
* Copyright (c) 2015 Melvin Sembrano (melvinsembrano@gmail.com)
* License: MIT
*/
var EasyDate = function EasyDate(value, type) {
var types = {
0: "day",
1: "week",
2: "month",
3: "year",
4: "hour"
};
/***/ "./src/easy-date.js":
/*!**************************!*\
!*** ./src/easy-date.js ***!
\**************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
this.value = parseInt(value);
this.type = types[type];
};
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.EasyDate = undefined;\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nexports.easyDate = easyDate;\nexports.backwardCompatibility = backwardCompatibility;\n\nvar _dateFormat = __webpack_require__(/*! ./date-format */ \"./src/date-format.js\");\n\nvar _dateFormat2 = _interopRequireDefault(_dateFormat);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar EasyDate = exports.EasyDate = function () {\n function EasyDate(value, conversionType) {\n _classCallCheck(this, EasyDate);\n\n _initialiseProps.call(this);\n\n this.value = parseInt(value);\n this.conversionType = conversionType;\n }\n\n _createClass(EasyDate, [{\n key: \"fromNow\",\n value: function fromNow(mask) {\n var processor = this.process(mask);\n if (processor) {\n return processor.fromNow();\n } else {\n return \"Processor not found.\";\n }\n }\n }, {\n key: \"ago\",\n value: function ago(mask) {\n var processor = this.process(mask);\n if (processor) {\n return processor.ago();\n } else {\n return \"Processor not found.\";\n }\n }\n }, {\n key: \"since\",\n value: function since(date, mask) {\n this.now = new Date(date.valueOf());\n return this.fromNow(mask);\n }\n }, {\n key: \"until\",\n value: function until(date, mask) {\n this.now = new Date(date.valueOf());\n return this.ago(mask);\n }\n }, {\n key: \"before\",\n value: function before(date, mask) {\n return this.until(date, mask);\n }\n }, {\n key: \"toString\",\n value: function toString() {\n return this.value + \" \" + this.conversionType + (this.value > 1 ? 's' : '');\n }\n }, {\n key: \"process\",\n value: function process(mask) {\n var conversionType = this.conversionType,\n timeProcessor = this.timeProcessor;\n\n var now = this.now || new Date();\n return {\n hour: function hour() {\n return timeProcessor(now, now.setHours, now.getHours, mask);\n },\n day: function day() {\n return timeProcessor(now, now.setDate, now.getDate, mask);\n },\n week: function week() {\n return null;\n },\n month: function month() {\n return timeProcessor(now, now.setMonth, now.getMonth, mask);\n },\n year: function year() {\n return timeProcessor(now, now.setFullYear, now.getFullYear, mask);\n }\n }[conversionType]();\n }\n }], [{\n key: \"formatDate\",\n value: function formatDate(date, mask) {\n if (!!mask) {\n return (0, _dateFormat2.default)(date, mask);\n } else {\n return date;\n }\n }\n }, {\n key: \"today\",\n value: function today(mask) {\n return EasyDate.formatDate(new Date(), mask);\n }\n }, {\n key: \"yesterday\",\n value: function yesterday(mask) {\n return new EasyDate(1, 'day').ago(mask);\n }\n }, {\n key: \"tomorrow\",\n value: function tomorrow(mask) {\n return new EasyDate(1, 'day').fromNow(mask);\n }\n }]);\n\n return EasyDate;\n}();\n\nvar _initialiseProps = function _initialiseProps() {\n var _this = this;\n\n this.timeProcessor = function (now, set, get, mask) {\n var value = _this.value;\n\n return {\n ago: function ago() {\n set.call(now, get.call(now) - value);\n return EasyDate.formatDate(now, mask);\n },\n fromNow: function fromNow() {\n set.call(now, get.call(now) + value);\n return EasyDate.formatDate(now, mask);\n }\n };\n };\n};\n\nfunction easyDate(value) {\n var days = function days() {\n return new EasyDate(value, 'day');\n };\n\n var months = function months() {\n return new EasyDate(value, 'month');\n };\n\n var years = function years() {\n return new EasyDate(value, 'year');\n };\n\n var hours = function hours() {\n return new EasyDate(value, 'hour');\n };\n\n return {\n hour: hours,\n hours: hours,\n day: days,\n days: days,\n month: months,\n months: months,\n year: years,\n years: years\n };\n}\n\nfunction backwardCompatibility() {\n\n var days = function days() {\n return new EasyDate(this, 'day');\n };\n\n var months = function months() {\n return new EasyDate(this, 'month');\n };\n\n var years = function years() {\n return new EasyDate(this, 'year');\n };\n\n var hours = function hours() {\n return new EasyDate(this, 'hour');\n };\n\n // $FlowFixMe\n Number.prototype.day = days;\n // $FlowFixMe\n Number.prototype.days = days;\n // $FlowFixMe\n Number.prototype.month = months;\n // $FlowFixMe\n Number.prototype.months = months;\n // $FlowFixMe\n Number.prototype.years = years;\n // $FlowFixMe\n Number.prototype.year = years;\n // $FlowFixMe\n Number.prototype.hours = hours;\n // $FlowFixMe\n Number.prototype.hour = hours;\n\n // $FlowFixMe\n Object.assign(Date, {\n today: function today(mask) {\n return EasyDate.today(mask);\n },\n yesterday: function yesterday(mask) {\n return EasyDate.yesterday(mask);\n },\n tomorrow: function tomorrow(mask) {\n return EasyDate.tomorrow(mask);\n },\n tommorrow: function tommorrow(mask) {\n return EasyDate.tomorrow(mask);\n }\n });\n}\n\nexports.default = {\n EasyDate: EasyDate,\n easyDate: easyDate,\n backwardCompatibility: backwardCompatibility\n};\n\n//# sourceURL=webpack:///./src/easy-date.js?");
EasyDate.prototype.toString = function () {
return this.value + " " + this.type + (this.value > 1 ? 's' : '');
};
/***/ })
EasyDate.prototype.fromNow = function (mask) {
switch (this.type) {
case "day":
return this._daysFromNow(mask);
case "month":
return this._monthsFromNow(mask);
case "year":
return this._yearsFromNow(mask);
case "hour":
return this._hoursFromNow(mask);
default:
return console.warn("EasyDate: " + this.type + "().fromNow() not yet implemented.");
}
};
EasyDate.prototype.ago = function (mask) {
switch (this.type) {
case "day":
return this._daysAgo(mask);
case "month":
return this._monthsAgo(mask);
case "year":
return this._yearsAgo(mask);
case "hour":
return this._hoursAgo(mask);
default:
return console.warn("EasyDate: " + this.type + "().ago() not yet implemented.");
}
};
EasyDate.prototype.since = function (date, mask) {
this.now = new Date(date.valueOf());
return this.fromNow(mask);
};
EasyDate.prototype.until = function (date, mask) {
this.now = new Date(date.valueOf());
return this.ago(mask);
};
EasyDate.prototype.before = function (date, mask) {
return this.until(date, mask);
};
EasyDate.prototype._daysFromNow = function (mask) {
var now = this.now || new Date();
now.setDate(now.getDate() + this.value);
return formatDate(now, mask);
};
EasyDate.prototype._daysAgo = function (mask) {
var now = this.now || new Date();
now.setDate(now.getDate() - this.value);
return formatDate(now, mask);
};
EasyDate.prototype._monthsFromNow = function (mask) {
var now = this.now || new Date();
now.setMonth(now.getMonth() + this.value);
return formatDate(now, mask);
};
EasyDate.prototype._monthsAgo = function (mask) {
var now = this.now || new Date();
now.setMonth(now.getMonth() - this.value);
return formatDate(now, mask);
};
EasyDate.prototype._yearsFromNow = function (mask) {
var now = this.now || new Date();
now.setFullYear(now.getFullYear() + this.value);
return formatDate(now, mask);
};
EasyDate.prototype._yearsAgo = function (mask) {
var now = this.now || new Date();
now.setFullYear(now.getFullYear() - this.value);
return formatDate(now, mask);
};
EasyDate.prototype._hoursFromNow = function (mask) {
var now = this.now || new Date();
now.setHours(now.getHours() + this.value);
return formatDate(now, mask);
};
EasyDate.prototype._hoursAgo = function (mask) {
var now = this.now || new Date();
now.setHours(now.getHours() - this.value);
return formatDate(now, mask);
};
var formatDate = function formatDate(date, mask) {
if (mask === undefined) {
return date;
} else {
return date.format(mask);
}
};
var days = function days() {
return new EasyDate(this, 0);
};
var months = function months() {
return new EasyDate(this, 2);
};
var years = function years() {
return new EasyDate(this, 3);
};
var hours = function hours() {
return new EasyDate(this, 4);
};
Number.prototype.day = days;
Number.prototype.days = days;
Number.prototype.month = months;
Number.prototype.months = months;
Number.prototype.years = years;
Number.prototype.year = years;
Number.prototype.hours = hours;
Number.prototype.hour = hours;
Date.today = function (mask) {
return formatDate(new this(), mask);
};
Date.yesterday = function (mask) {
return 1 .day().ago(mask);
};
Date.tommorrow = function (mask) {
return 1 .day().fromNow(mask);
};
/***/ })
/******/ ]);
/******/ });

@@ -1,1 +0,1 @@

!function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var r={};e.m=t,e.c=r,e.d=function(t,r,o){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,r){"use strict";var o=function(t,e){var r={0:"day",1:"week",2:"month",3:"year",4:"hour"};this.value=parseInt(t),this.type=r[e]};o.prototype.toString=function(){return this.value+" "+this.type+(this.value>1?"s":"")},o.prototype.fromNow=function(t){switch(this.type){case"day":return this._daysFromNow(t);case"month":return this._monthsFromNow(t);case"year":return this._yearsFromNow(t);case"hour":return this._hoursFromNow(t);default:return console.warn("EasyDate: "+this.type+"().fromNow() not yet implemented.")}},o.prototype.ago=function(t){switch(this.type){case"day":return this._daysAgo(t);case"month":return this._monthsAgo(t);case"year":return this._yearsAgo(t);case"hour":return this._hoursAgo(t);default:return console.warn("EasyDate: "+this.type+"().ago() not yet implemented.")}},o.prototype.since=function(t,e){return this.now=new Date(t.valueOf()),this.fromNow(e)},o.prototype.until=function(t,e){return this.now=new Date(t.valueOf()),this.ago(e)},o.prototype.before=function(t,e){return this.until(t,e)},o.prototype._daysFromNow=function(t){var e=this.now||new Date;return e.setDate(e.getDate()+this.value),n(e,t)},o.prototype._daysAgo=function(t){var e=this.now||new Date;return e.setDate(e.getDate()-this.value),n(e,t)},o.prototype._monthsFromNow=function(t){var e=this.now||new Date;return e.setMonth(e.getMonth()+this.value),n(e,t)},o.prototype._monthsAgo=function(t){var e=this.now||new Date;return e.setMonth(e.getMonth()-this.value),n(e,t)},o.prototype._yearsFromNow=function(t){var e=this.now||new Date;return e.setFullYear(e.getFullYear()+this.value),n(e,t)},o.prototype._yearsAgo=function(t){var e=this.now||new Date;return e.setFullYear(e.getFullYear()-this.value),n(e,t)},o.prototype._hoursFromNow=function(t){var e=this.now||new Date;return e.setHours(e.getHours()+this.value),n(e,t)},o.prototype._hoursAgo=function(t){var e=this.now||new Date;return e.setHours(e.getHours()-this.value),n(e,t)};var n=function(t,e){return void 0===e?t:t.format(e)},u=function(){return new o(this,0)},s=function(){return new o(this,2)},a=function(){return new o(this,3)},i=function(){return new o(this,4)};Number.prototype.day=u,Number.prototype.days=u,Number.prototype.month=s,Number.prototype.months=s,Number.prototype.years=a,Number.prototype.year=a,Number.prototype.hours=i,Number.prototype.hour=i,Date.today=function(t){return n(new this,t)},Date.yesterday=function(t){return 1..day().ago(t)},Date.tommorrow=function(t){return 1..day().fromNow(t)}}]);
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){var e=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,t=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,n=/[^-+\dA-Z]/g,o=function(e,t){for(e=String(e),t=t||2;e.length<t;)e="0"+e;return e};return function(a,u,i){var s=r;if(1!==arguments.length||"[object String]"!==Object.prototype.toString.call(a)||/\d/.test(a)||(u=a,a=void 0),a=a?new Date(a):new Date,isNaN(a))throw SyntaxError("invalid date");"UTC:"===(u=String(s.masks[u]||u||s.masks.default)).slice(0,4)&&(u=u.slice(4),i=!0);var y=i?"getUTC":"get",c=a[y+"Date"](),l=a[y+"Day"](),f=a[y+"Month"](),d=a[y+"FullYear"](),m=a[y+"Hours"](),h=a[y+"Minutes"](),p=a[y+"Seconds"](),v=a[y+"Milliseconds"](),b=i?0:a.getTimezoneOffset(),M={d:c,dd:o(c),ddd:s.i18n.dayNames[l],dddd:s.i18n.dayNames[l+7],m:f+1,mm:o(f+1),mmm:s.i18n.monthNames[f],mmmm:s.i18n.monthNames[f+12],yy:String(d).slice(2),yyyy:d,h:m%12||12,hh:o(m%12||12),H:m,HH:o(m),M:h,MM:o(h),s:p,ss:o(p),l:o(v,3),L:o(v>99?Math.round(v/10):v),t:m<12?"a":"p",tt:m<12?"am":"pm",T:m<12?"A":"P",TT:m<12?"AM":"PM",Z:i?"UTC":(String(a).match(t)||[""]).pop().replace(n,""),o:(b>0?"-":"+")+o(100*Math.floor(Math.abs(b)/60)+Math.abs(b)%60,4),S:["th","st","nd","rd"][c%10>3?0:(c%100-c%10!=10)*c%10]};return u.replace(e,function(e){return e in M?M[e]:e.slice(1,e.length-1)})}}();r.masks={default:"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"},r.i18n={dayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]},void 0===Date.prototype.format&&(Date.prototype.format=function(e,t){return r(this,e,t)}),t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EasyDate=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.easyDate=i,t.backwardCompatibility=s;var o=function(e){return e&&e.__esModule?e:{default:e}}(n(0)),a=t.EasyDate=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),u.call(this),this.value=parseInt(t),this.conversionType=n}return r(e,[{key:"fromNow",value:function(e){var t=this.process(e);return t?t.fromNow():"Processor not found."}},{key:"ago",value:function(e){var t=this.process(e);return t?t.ago():"Processor not found."}},{key:"since",value:function(e,t){return this.now=new Date(e.valueOf()),this.fromNow(t)}},{key:"until",value:function(e,t){return this.now=new Date(e.valueOf()),this.ago(t)}},{key:"before",value:function(e,t){return this.until(e,t)}},{key:"toString",value:function(){return this.value+" "+this.conversionType+(this.value>1?"s":"")}},{key:"process",value:function(e){var t=this.conversionType,n=this.timeProcessor,r=this.now||new Date;return{hour:function(){return n(r,r.setHours,r.getHours,e)},day:function(){return n(r,r.setDate,r.getDate,e)},week:function(){return null},month:function(){return n(r,r.setMonth,r.getMonth,e)},year:function(){return n(r,r.setFullYear,r.getFullYear,e)}}[t]()}}],[{key:"formatDate",value:function(e,t){return t?(0,o.default)(e,t):e}},{key:"today",value:function(t){return e.formatDate(new Date,t)}},{key:"yesterday",value:function(t){return new e(1,"day").ago(t)}},{key:"tomorrow",value:function(t){return new e(1,"day").fromNow(t)}}]),e}(),u=function(){var e=this;this.timeProcessor=function(t,n,r,o){var u=e.value;return{ago:function(){return n.call(t,r.call(t)-u),a.formatDate(t,o)},fromNow:function(){return n.call(t,r.call(t)+u),a.formatDate(t,o)}}}};function i(e){var t=function(){return new a(e,"day")},n=function(){return new a(e,"month")},r=function(){return new a(e,"year")},o=function(){return new a(e,"hour")};return{hour:o,hours:o,day:t,days:t,month:n,months:n,year:r,years:r}}function s(){var e=function(){return new a(this,"day")},t=function(){return new a(this,"month")},n=function(){return new a(this,"year")},r=function(){return new a(this,"hour")};Number.prototype.day=e,Number.prototype.days=e,Number.prototype.month=t,Number.prototype.months=t,Number.prototype.years=n,Number.prototype.year=n,Number.prototype.hours=r,Number.prototype.hour=r,Object.assign(Date,{today:function(e){return a.today(e)},yesterday:function(e){return a.yesterday(e)},tomorrow:function(e){return a.tomorrow(e)},tommorrow:function(e){return a.tomorrow(e)}})}t.default={EasyDate:a,easyDate:i,backwardCompatibility:s}}]);

@@ -39,10 +39,30 @@ /******/ (function(modules) { // webpackBootstrap

/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules

@@ -63,313 +83,45 @@ /******/ __webpack_require__.n = function(module) {

/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ return __webpack_require__(__webpack_require__.s = "./src/bundled.js");
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/******/ ({
/***/ "./src/bundled.js":
/*!************************!*\
!*** ./src/bundled.js ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _easyDate = __webpack_require__(/*! ./easy-date */ \"./src/easy-date.js\");\n\nObject.keys(_easyDate).forEach(function (key) {\n if (key === \"default\" || key === \"__esModule\") return;\n Object.defineProperty(exports, key, {\n enumerable: true,\n get: function get() {\n return _easyDate[key];\n }\n });\n});\n\nvar _dateFormat = __webpack_require__(/*! ./date-format */ \"./src/date-format.js\");\n\nObject.keys(_dateFormat).forEach(function (key) {\n if (key === \"default\" || key === \"__esModule\") return;\n Object.defineProperty(exports, key, {\n enumerable: true,\n get: function get() {\n return _dateFormat[key];\n }\n });\n});\n\n//# sourceURL=webpack:///./src/bundled.js?");
/***/ }),
/*
* EasyDate
* is a Javascript extension for easy dates manipulations which is heavily inspired by Rails ActiveSupport::Duration class.
* Copyright (c) 2015 Melvin Sembrano (melvinsembrano@gmail.com)
* License: MIT
*/
var EasyDate = function EasyDate(value, type) {
var types = {
0: "day",
1: "week",
2: "month",
3: "year",
4: "hour"
};
this.value = parseInt(value);
this.type = types[type];
};
EasyDate.prototype.toString = function () {
return this.value + " " + this.type + (this.value > 1 ? 's' : '');
};
EasyDate.prototype.fromNow = function (mask) {
switch (this.type) {
case "day":
return this._daysFromNow(mask);
case "month":
return this._monthsFromNow(mask);
case "year":
return this._yearsFromNow(mask);
case "hour":
return this._hoursFromNow(mask);
default:
return console.warn("EasyDate: " + this.type + "().fromNow() not yet implemented.");
}
};
EasyDate.prototype.ago = function (mask) {
switch (this.type) {
case "day":
return this._daysAgo(mask);
case "month":
return this._monthsAgo(mask);
case "year":
return this._yearsAgo(mask);
case "hour":
return this._hoursAgo(mask);
default:
return console.warn("EasyDate: " + this.type + "().ago() not yet implemented.");
}
};
EasyDate.prototype.since = function (date, mask) {
this.now = new Date(date.valueOf());
return this.fromNow(mask);
};
EasyDate.prototype.until = function (date, mask) {
this.now = new Date(date.valueOf());
return this.ago(mask);
};
EasyDate.prototype.before = function (date, mask) {
return this.until(date, mask);
};
EasyDate.prototype._daysFromNow = function (mask) {
var now = this.now || new Date();
now.setDate(now.getDate() + this.value);
return formatDate(now, mask);
};
EasyDate.prototype._daysAgo = function (mask) {
var now = this.now || new Date();
now.setDate(now.getDate() - this.value);
return formatDate(now, mask);
};
EasyDate.prototype._monthsFromNow = function (mask) {
var now = this.now || new Date();
now.setMonth(now.getMonth() + this.value);
return formatDate(now, mask);
};
EasyDate.prototype._monthsAgo = function (mask) {
var now = this.now || new Date();
now.setMonth(now.getMonth() - this.value);
return formatDate(now, mask);
};
EasyDate.prototype._yearsFromNow = function (mask) {
var now = this.now || new Date();
now.setFullYear(now.getFullYear() + this.value);
return formatDate(now, mask);
};
EasyDate.prototype._yearsAgo = function (mask) {
var now = this.now || new Date();
now.setFullYear(now.getFullYear() - this.value);
return formatDate(now, mask);
};
EasyDate.prototype._hoursFromNow = function (mask) {
var now = this.now || new Date();
now.setHours(now.getHours() + this.value);
return formatDate(now, mask);
};
EasyDate.prototype._hoursAgo = function (mask) {
var now = this.now || new Date();
now.setHours(now.getHours() - this.value);
return formatDate(now, mask);
};
var formatDate = function formatDate(date, mask) {
if (mask === undefined) {
return date;
} else {
return date.format(mask);
}
};
var days = function days() {
return new EasyDate(this, 0);
};
var months = function months() {
return new EasyDate(this, 2);
};
var years = function years() {
return new EasyDate(this, 3);
};
var hours = function hours() {
return new EasyDate(this, 4);
};
Number.prototype.day = days;
Number.prototype.days = days;
Number.prototype.month = months;
Number.prototype.months = months;
Number.prototype.years = years;
Number.prototype.year = years;
Number.prototype.hours = hours;
Number.prototype.hour = hours;
Date.today = function (mask) {
return formatDate(new this(), mask);
};
Date.yesterday = function (mask) {
return 1 .day().ago(mask);
};
Date.tommorrow = function (mask) {
return 1 .day().fromNow(mask);
};
/***/ }),
/* 1 */
/***/ "./src/date-format.js":
/*!****************************!*\
!*** ./src/date-format.js ***!
\****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n/*\n * Date Format 1.2.3\n * (c) 2007-2009 Steven Levithan <stevenlevithan.com>\n * MIT license\n *\n * Includes enhancements by Scott Trenda <scott.trenda.net>\n * and Kris Kowal <cixar.com/~kris.kowal/>\n *\n * Accepts a date, a mask, or a date and a mask.\n * Returns a formatted version of the given date.\n * The date defaults to the current date/time.\n * The mask defaults to dateFormat.masks.default.\n */\n\nvar dateFormat = function () {\n var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\\1?|[LloSZ]|\"[^\"]*\"|'[^']*'/g;\n var timezone = /\\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\\d{4})?)\\b/g;\n var timezoneClip = /[^-+\\dA-Z]/g;\n\n var pad = function pad(val, len) {\n val = String(val);\n len = len || 2;\n while (val.length < len) {\n val = '0' + val;\n }\n return val;\n };\n\n // Regexes and supporting functions are cached through closure\n return function (date, mask, utc) {\n var dF = dateFormat;\n // You can't provide utc if you skip other args (use the \"UTC:\" mask prefix)\n if (arguments.length === 1 && Object.prototype.toString.call(date) === '[object String]' && !/\\d/.test(date)) {\n mask = date;\n date = undefined;\n }\n // Passing date through Date applies Date.parse, if necessary\n date = date ? new Date(date) : new Date();\n if (isNaN(date)) {\n throw SyntaxError('invalid date');\n }\n mask = String(dF.masks[mask] || mask || dF.masks['default']);\n // Allow setting the utc argument via the mask\n if (mask.slice(0, 4) === 'UTC:') {\n mask = mask.slice(4);\n utc = true;\n }\n var _ = utc ? 'getUTC' : 'get';\n var d = date[_ + 'Date']();\n var D = date[_ + 'Day']();\n var m = date[_ + 'Month']();\n var y = date[_ + 'FullYear']();\n var H = date[_ + 'Hours']();\n var M = date[_ + 'Minutes']();\n var s = date[_ + 'Seconds']();\n var L = date[_ + 'Milliseconds']();\n var o = utc ? 0 : date.getTimezoneOffset();\n var flags = {\n d: d,\n dd: pad(d),\n ddd: dF.i18n.dayNames[D],\n dddd: dF.i18n.dayNames[D + 7],\n m: m + 1,\n mm: pad(m + 1),\n mmm: dF.i18n.monthNames[m],\n mmmm: dF.i18n.monthNames[m + 12],\n yy: String(y).slice(2),\n yyyy: y,\n h: H % 12 || 12,\n hh: pad(H % 12 || 12),\n H: H,\n HH: pad(H),\n M: M,\n MM: pad(M),\n s: s,\n ss: pad(s),\n l: pad(L, 3),\n L: pad(L > 99 ? Math.round(L / 10) : L),\n t: H < 12 ? 'a' : 'p',\n tt: H < 12 ? 'am' : 'pm',\n T: H < 12 ? 'A' : 'P',\n TT: H < 12 ? 'AM' : 'PM',\n Z: utc ? 'UTC' : (String(date).match(timezone) || ['']).pop().replace(timezoneClip, ''),\n o: (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),\n S: ['th', 'st', 'nd', 'rd'][d % 10 > 3 ? 0 : (d % 100 - d % 10 !== 10) * d % 10]\n };\n return mask.replace(token, function ($0) {\n if ($0 in flags) {\n return flags[$0];\n } else {\n return $0.slice(1, $0.length - 1);\n }\n });\n };\n}();\n// Some common format strings\ndateFormat.masks = {\n 'default': 'ddd mmm dd yyyy HH:MM:ss',\n shortDate: 'm/d/yy',\n mediumDate: 'mmm d, yyyy',\n longDate: 'mmmm d, yyyy',\n fullDate: 'dddd, mmmm d, yyyy',\n shortTime: 'h:MM TT',\n mediumTime: 'h:MM:ss TT',\n longTime: 'h:MM:ss TT Z',\n isoDate: 'yyyy-mm-dd',\n isoTime: 'HH:MM:ss',\n isoDateTime: 'yyyy-mm-dd\\'T\\'HH:MM:ss',\n isoUtcDateTime: 'UTC:yyyy-mm-dd\\'T\\'HH:MM:ss\\'Z\\''\n};\n// Internationalization strings\ndateFormat.i18n = {\n dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']\n};\n\n// For convenience...\nif (Date.prototype.format === undefined) {\n Date.prototype.format = function (mask, utc) {\n return dateFormat(this, mask, utc);\n };\n}\n\nexports.default = dateFormat;\n\n//# sourceURL=webpack:///./src/date-format.js?");
/***/ }),
__webpack_require__(0);
__webpack_require__(2);
/***/ }),
/* 2 */
/***/ "./src/easy-date.js":
/*!**************************!*\
!*** ./src/easy-date.js ***!
\**************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.EasyDate = undefined;\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nexports.easyDate = easyDate;\nexports.backwardCompatibility = backwardCompatibility;\n\nvar _dateFormat = __webpack_require__(/*! ./date-format */ \"./src/date-format.js\");\n\nvar _dateFormat2 = _interopRequireDefault(_dateFormat);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar EasyDate = exports.EasyDate = function () {\n function EasyDate(value, conversionType) {\n _classCallCheck(this, EasyDate);\n\n _initialiseProps.call(this);\n\n this.value = parseInt(value);\n this.conversionType = conversionType;\n }\n\n _createClass(EasyDate, [{\n key: \"fromNow\",\n value: function fromNow(mask) {\n var processor = this.process(mask);\n if (processor) {\n return processor.fromNow();\n } else {\n return \"Processor not found.\";\n }\n }\n }, {\n key: \"ago\",\n value: function ago(mask) {\n var processor = this.process(mask);\n if (processor) {\n return processor.ago();\n } else {\n return \"Processor not found.\";\n }\n }\n }, {\n key: \"since\",\n value: function since(date, mask) {\n this.now = new Date(date.valueOf());\n return this.fromNow(mask);\n }\n }, {\n key: \"until\",\n value: function until(date, mask) {\n this.now = new Date(date.valueOf());\n return this.ago(mask);\n }\n }, {\n key: \"before\",\n value: function before(date, mask) {\n return this.until(date, mask);\n }\n }, {\n key: \"toString\",\n value: function toString() {\n return this.value + \" \" + this.conversionType + (this.value > 1 ? 's' : '');\n }\n }, {\n key: \"process\",\n value: function process(mask) {\n var conversionType = this.conversionType,\n timeProcessor = this.timeProcessor;\n\n var now = this.now || new Date();\n return {\n hour: function hour() {\n return timeProcessor(now, now.setHours, now.getHours, mask);\n },\n day: function day() {\n return timeProcessor(now, now.setDate, now.getDate, mask);\n },\n week: function week() {\n return null;\n },\n month: function month() {\n return timeProcessor(now, now.setMonth, now.getMonth, mask);\n },\n year: function year() {\n return timeProcessor(now, now.setFullYear, now.getFullYear, mask);\n }\n }[conversionType]();\n }\n }], [{\n key: \"formatDate\",\n value: function formatDate(date, mask) {\n if (!!mask) {\n return (0, _dateFormat2.default)(date, mask);\n } else {\n return date;\n }\n }\n }, {\n key: \"today\",\n value: function today(mask) {\n return EasyDate.formatDate(new Date(), mask);\n }\n }, {\n key: \"yesterday\",\n value: function yesterday(mask) {\n return new EasyDate(1, 'day').ago(mask);\n }\n }, {\n key: \"tomorrow\",\n value: function tomorrow(mask) {\n return new EasyDate(1, 'day').fromNow(mask);\n }\n }]);\n\n return EasyDate;\n}();\n\nvar _initialiseProps = function _initialiseProps() {\n var _this = this;\n\n this.timeProcessor = function (now, set, get, mask) {\n var value = _this.value;\n\n return {\n ago: function ago() {\n set.call(now, get.call(now) - value);\n return EasyDate.formatDate(now, mask);\n },\n fromNow: function fromNow() {\n set.call(now, get.call(now) + value);\n return EasyDate.formatDate(now, mask);\n }\n };\n };\n};\n\nfunction easyDate(value) {\n var days = function days() {\n return new EasyDate(value, 'day');\n };\n\n var months = function months() {\n return new EasyDate(value, 'month');\n };\n\n var years = function years() {\n return new EasyDate(value, 'year');\n };\n\n var hours = function hours() {\n return new EasyDate(value, 'hour');\n };\n\n return {\n hour: hours,\n hours: hours,\n day: days,\n days: days,\n month: months,\n months: months,\n year: years,\n years: years\n };\n}\n\nfunction backwardCompatibility() {\n\n var days = function days() {\n return new EasyDate(this, 'day');\n };\n\n var months = function months() {\n return new EasyDate(this, 'month');\n };\n\n var years = function years() {\n return new EasyDate(this, 'year');\n };\n\n var hours = function hours() {\n return new EasyDate(this, 'hour');\n };\n\n // $FlowFixMe\n Number.prototype.day = days;\n // $FlowFixMe\n Number.prototype.days = days;\n // $FlowFixMe\n Number.prototype.month = months;\n // $FlowFixMe\n Number.prototype.months = months;\n // $FlowFixMe\n Number.prototype.years = years;\n // $FlowFixMe\n Number.prototype.year = years;\n // $FlowFixMe\n Number.prototype.hours = hours;\n // $FlowFixMe\n Number.prototype.hour = hours;\n\n // $FlowFixMe\n Object.assign(Date, {\n today: function today(mask) {\n return EasyDate.today(mask);\n },\n yesterday: function yesterday(mask) {\n return EasyDate.yesterday(mask);\n },\n tomorrow: function tomorrow(mask) {\n return EasyDate.tomorrow(mask);\n },\n tommorrow: function tommorrow(mask) {\n return EasyDate.tomorrow(mask);\n }\n });\n}\n\nexports.default = {\n EasyDate: EasyDate,\n easyDate: easyDate,\n backwardCompatibility: backwardCompatibility\n};\n\n//# sourceURL=webpack:///./src/easy-date.js?");
/***/ })
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
* The date defaults to the current date/time.
* The mask defaults to dateFormat.masks.default.
*/
var dateFormat = function () {
var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g;
var timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g;
var timezoneClip = /[^-+\dA-Z]/g;
var pad = function pad(val, len) {
val = String(val);
len = len || 2;
while (val.length < len) {
val = '0' + val;
}
return val;
};
// Regexes and supporting functions are cached through closure
return function (date, mask, utc) {
var dF = dateFormat;
// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
if (arguments.length === 1 && Object.prototype.toString.call(date) === '[object String]' && !/\d/.test(date)) {
mask = date;
date = undefined;
}
// Passing date through Date applies Date.parse, if necessary
date = date ? new Date(date) : new Date();
if (isNaN(date)) {
throw SyntaxError('invalid date');
}
mask = String(dF.masks[mask] || mask || dF.masks['default']);
// Allow setting the utc argument via the mask
if (mask.slice(0, 4) === 'UTC:') {
mask = mask.slice(4);
utc = true;
}
var _ = utc ? 'getUTC' : 'get';
var d = date[_ + 'Date']();
var D = date[_ + 'Day']();
var m = date[_ + 'Month']();
var y = date[_ + 'FullYear']();
var H = date[_ + 'Hours']();
var M = date[_ + 'Minutes']();
var s = date[_ + 'Seconds']();
var L = date[_ + 'Milliseconds']();
var o = utc ? 0 : date.getTimezoneOffset();
var flags = {
d: d,
dd: pad(d),
ddd: dF.i18n.dayNames[D],
dddd: dF.i18n.dayNames[D + 7],
m: m + 1,
mm: pad(m + 1),
mmm: dF.i18n.monthNames[m],
mmmm: dF.i18n.monthNames[m + 12],
yy: String(y).slice(2),
yyyy: y,
h: H % 12 || 12,
hh: pad(H % 12 || 12),
H: H,
HH: pad(H),
M: M,
MM: pad(M),
s: s,
ss: pad(s),
l: pad(L, 3),
L: pad(L > 99 ? Math.round(L / 10) : L),
t: H < 12 ? 'a' : 'p',
tt: H < 12 ? 'am' : 'pm',
T: H < 12 ? 'A' : 'P',
TT: H < 12 ? 'AM' : 'PM',
Z: utc ? 'UTC' : (String(date).match(timezone) || ['']).pop().replace(timezoneClip, ''),
o: (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
S: ['th', 'st', 'nd', 'rd'][d % 10 > 3 ? 0 : (d % 100 - d % 10 !== 10) * d % 10]
};
return mask.replace(token, function ($0) {
if ($0 in flags) {
return flags[$0];
} else {
return $0.slice(1, $0.length - 1);
}
});
};
}();
// Some common format strings
dateFormat.masks = {
'default': 'ddd mmm dd yyyy HH:MM:ss',
shortDate: 'm/d/yy',
mediumDate: 'mmm d, yyyy',
longDate: 'mmmm d, yyyy',
fullDate: 'dddd, mmmm d, yyyy',
shortTime: 'h:MM TT',
mediumTime: 'h:MM:ss TT',
longTime: 'h:MM:ss TT Z',
isoDate: 'yyyy-mm-dd',
isoTime: 'HH:MM:ss',
isoDateTime: 'yyyy-mm-dd\'T\'HH:MM:ss',
isoUtcDateTime: 'UTC:yyyy-mm-dd\'T\'HH:MM:ss\'Z\''
};
// Internationalization strings
dateFormat.i18n = {
dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
};
// For convenience...
if (Date.prototype.format === undefined) {
Date.prototype.format = function (mask, utc) {
return dateFormat(this, mask, utc);
};
}
/***/ })
/******/ ]);
/******/ });

@@ -1,1 +0,1 @@

!function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var r={};e.m=t,e.c=r,e.d=function(t,r,o){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=1)}([function(t,e,r){"use strict";var o=function(t,e){var r={0:"day",1:"week",2:"month",3:"year",4:"hour"};this.value=parseInt(t),this.type=r[e]};o.prototype.toString=function(){return this.value+" "+this.type+(this.value>1?"s":"")},o.prototype.fromNow=function(t){switch(this.type){case"day":return this._daysFromNow(t);case"month":return this._monthsFromNow(t);case"year":return this._yearsFromNow(t);case"hour":return this._hoursFromNow(t);default:return console.warn("EasyDate: "+this.type+"().fromNow() not yet implemented.")}},o.prototype.ago=function(t){switch(this.type){case"day":return this._daysAgo(t);case"month":return this._monthsAgo(t);case"year":return this._yearsAgo(t);case"hour":return this._hoursAgo(t);default:return console.warn("EasyDate: "+this.type+"().ago() not yet implemented.")}},o.prototype.since=function(t,e){return this.now=new Date(t.valueOf()),this.fromNow(e)},o.prototype.until=function(t,e){return this.now=new Date(t.valueOf()),this.ago(e)},o.prototype.before=function(t,e){return this.until(t,e)},o.prototype._daysFromNow=function(t){var e=this.now||new Date;return e.setDate(e.getDate()+this.value),n(e,t)},o.prototype._daysAgo=function(t){var e=this.now||new Date;return e.setDate(e.getDate()-this.value),n(e,t)},o.prototype._monthsFromNow=function(t){var e=this.now||new Date;return e.setMonth(e.getMonth()+this.value),n(e,t)},o.prototype._monthsAgo=function(t){var e=this.now||new Date;return e.setMonth(e.getMonth()-this.value),n(e,t)},o.prototype._yearsFromNow=function(t){var e=this.now||new Date;return e.setFullYear(e.getFullYear()+this.value),n(e,t)},o.prototype._yearsAgo=function(t){var e=this.now||new Date;return e.setFullYear(e.getFullYear()-this.value),n(e,t)},o.prototype._hoursFromNow=function(t){var e=this.now||new Date;return e.setHours(e.getHours()+this.value),n(e,t)},o.prototype._hoursAgo=function(t){var e=this.now||new Date;return e.setHours(e.getHours()-this.value),n(e,t)};var n=function(t,e){return void 0===e?t:t.format(e)},a=function(){return new o(this,0)},s=function(){return new o(this,2)},u=function(){return new o(this,3)},i=function(){return new o(this,4)};Number.prototype.day=a,Number.prototype.days=a,Number.prototype.month=s,Number.prototype.months=s,Number.prototype.years=u,Number.prototype.year=u,Number.prototype.hours=i,Number.prototype.hour=i,Date.today=function(t){return n(new this,t)},Date.yesterday=function(t){return 1..day().ago(t)},Date.tommorrow=function(t){return 1..day().fromNow(t)}},function(t,e,r){"use strict";r(0),r(2)},function(t,e,r){"use strict";var o=function(){var t=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,e=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,r=/[^-+\dA-Z]/g,n=function(t,e){for(t=String(t),e=e||2;t.length<e;)t="0"+t;return t};return function(a,s,u){var i=o;if(1!==arguments.length||"[object String]"!==Object.prototype.toString.call(a)||/\d/.test(a)||(s=a,a=void 0),a=a?new Date(a):new Date,isNaN(a))throw SyntaxError("invalid date");s=String(i.masks[s]||s||i.masks.default),"UTC:"===s.slice(0,4)&&(s=s.slice(4),u=!0);var y=u?"getUTC":"get",m=a[y+"Date"](),h=a[y+"Day"](),d=a[y+"Month"](),c=a[y+"FullYear"](),p=a[y+"Hours"](),l=a[y+"Minutes"](),f=a[y+"Seconds"](),w=a[y+"Milliseconds"](),g=u?0:a.getTimezoneOffset(),M={d:m,dd:n(m),ddd:i.i18n.dayNames[h],dddd:i.i18n.dayNames[h+7],m:d+1,mm:n(d+1),mmm:i.i18n.monthNames[d],mmmm:i.i18n.monthNames[d+12],yy:String(c).slice(2),yyyy:c,h:p%12||12,hh:n(p%12||12),H:p,HH:n(p),M:l,MM:n(l),s:f,ss:n(f),l:n(w,3),L:n(w>99?Math.round(w/10):w),t:p<12?"a":"p",tt:p<12?"am":"pm",T:p<12?"A":"P",TT:p<12?"AM":"PM",Z:u?"UTC":(String(a).match(e)||[""]).pop().replace(r,""),o:(g>0?"-":"+")+n(100*Math.floor(Math.abs(g)/60)+Math.abs(g)%60,4),S:["th","st","nd","rd"][m%10>3?0:(m%100-m%10!=10)*m%10]};return s.replace(t,function(t){return t in M?M[t]:t.slice(1,t.length-1)})}}();o.masks={default:"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"},o.i18n={dayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]},void 0===Date.prototype.format&&(Date.prototype.format=function(t,e){return o(this,t,e)})}]);
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){var e=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,t=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,n=/[^-+\dA-Z]/g,o=function(e,t){for(e=String(e),t=t||2;e.length<t;)e="0"+e;return e};return function(u,a,i){var s=r;if(1!==arguments.length||"[object String]"!==Object.prototype.toString.call(u)||/\d/.test(u)||(a=u,u=void 0),u=u?new Date(u):new Date,isNaN(u))throw SyntaxError("invalid date");"UTC:"===(a=String(s.masks[a]||a||s.masks.default)).slice(0,4)&&(a=a.slice(4),i=!0);var y=i?"getUTC":"get",c=u[y+"Date"](),f=u[y+"Day"](),l=u[y+"Month"](),d=u[y+"FullYear"](),m=u[y+"Hours"](),h=u[y+"Minutes"](),p=u[y+"Seconds"](),v=u[y+"Milliseconds"](),b=i?0:u.getTimezoneOffset(),M={d:c,dd:o(c),ddd:s.i18n.dayNames[f],dddd:s.i18n.dayNames[f+7],m:l+1,mm:o(l+1),mmm:s.i18n.monthNames[l],mmmm:s.i18n.monthNames[l+12],yy:String(d).slice(2),yyyy:d,h:m%12||12,hh:o(m%12||12),H:m,HH:o(m),M:h,MM:o(h),s:p,ss:o(p),l:o(v,3),L:o(v>99?Math.round(v/10):v),t:m<12?"a":"p",tt:m<12?"am":"pm",T:m<12?"A":"P",TT:m<12?"AM":"PM",Z:i?"UTC":(String(u).match(t)||[""]).pop().replace(n,""),o:(b>0?"-":"+")+o(100*Math.floor(Math.abs(b)/60)+Math.abs(b)%60,4),S:["th","st","nd","rd"][c%10>3?0:(c%100-c%10!=10)*c%10]};return a.replace(e,function(e){return e in M?M[e]:e.slice(1,e.length-1)})}}();r.masks={default:"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"},r.i18n={dayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]},void 0===Date.prototype.format&&(Date.prototype.format=function(e,t){return r(this,e,t)}),t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EasyDate=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.easyDate=i,t.backwardCompatibility=s;var o=function(e){return e&&e.__esModule?e:{default:e}}(n(0)),u=t.EasyDate=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),a.call(this),this.value=parseInt(t),this.conversionType=n}return r(e,[{key:"fromNow",value:function(e){var t=this.process(e);return t?t.fromNow():"Processor not found."}},{key:"ago",value:function(e){var t=this.process(e);return t?t.ago():"Processor not found."}},{key:"since",value:function(e,t){return this.now=new Date(e.valueOf()),this.fromNow(t)}},{key:"until",value:function(e,t){return this.now=new Date(e.valueOf()),this.ago(t)}},{key:"before",value:function(e,t){return this.until(e,t)}},{key:"toString",value:function(){return this.value+" "+this.conversionType+(this.value>1?"s":"")}},{key:"process",value:function(e){var t=this.conversionType,n=this.timeProcessor,r=this.now||new Date;return{hour:function(){return n(r,r.setHours,r.getHours,e)},day:function(){return n(r,r.setDate,r.getDate,e)},week:function(){return null},month:function(){return n(r,r.setMonth,r.getMonth,e)},year:function(){return n(r,r.setFullYear,r.getFullYear,e)}}[t]()}}],[{key:"formatDate",value:function(e,t){return t?(0,o.default)(e,t):e}},{key:"today",value:function(t){return e.formatDate(new Date,t)}},{key:"yesterday",value:function(t){return new e(1,"day").ago(t)}},{key:"tomorrow",value:function(t){return new e(1,"day").fromNow(t)}}]),e}(),a=function(){var e=this;this.timeProcessor=function(t,n,r,o){var a=e.value;return{ago:function(){return n.call(t,r.call(t)-a),u.formatDate(t,o)},fromNow:function(){return n.call(t,r.call(t)+a),u.formatDate(t,o)}}}};function i(e){var t=function(){return new u(e,"day")},n=function(){return new u(e,"month")},r=function(){return new u(e,"year")},o=function(){return new u(e,"hour")};return{hour:o,hours:o,day:t,days:t,month:n,months:n,year:r,years:r}}function s(){var e=function(){return new u(this,"day")},t=function(){return new u(this,"month")},n=function(){return new u(this,"year")},r=function(){return new u(this,"hour")};Number.prototype.day=e,Number.prototype.days=e,Number.prototype.month=t,Number.prototype.months=t,Number.prototype.years=n,Number.prototype.year=n,Number.prototype.hours=r,Number.prototype.hour=r,Object.assign(Date,{today:function(e){return u.today(e)},yesterday:function(e){return u.yesterday(e)},tomorrow:function(e){return u.tomorrow(e)},tommorrow:function(e){return u.tomorrow(e)}})}t.default={EasyDate:u,easyDate:i,backwardCompatibility:s}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1);Object.keys(r).forEach(function(e){"default"!==e&&"__esModule"!==e&&Object.defineProperty(t,e,{enumerable:!0,get:function(){return r[e]}})});var o=n(0);Object.keys(o).forEach(function(e){"default"!==e&&"__esModule"!==e&&Object.defineProperty(t,e,{enumerable:!0,get:function(){return o[e]}})})}]);

@@ -5,3 +5,3 @@ {

"description": "EasyDate is a Javascript extension for easy dates manipulations which is heavily inspired by Rails ActiveSupport::Duration class.",
"version": "1.1.3",
"version": "1.2.0",
"keywords": [

@@ -25,13 +25,22 @@ "EasyDate",

"devDependencies": {
"babel-cli": "^6.24.1",
"babel-loader": "^7.1.1",
"babel-preset-env": "^1.6.0",
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"jest": "^20.0.4",
"webpack": "^3.0.0"
"babel-preset-flow": "^6.23.0",
"flow": "^0.2.3",
"flow-bin": "^0.75.0",
"flow-typed": "^2.4.0",
"jest": "^23.2.0",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.12.2",
"webpack-cli": "^3.0.8",
"webpack-merge": "^4.1.3"
},
"scripts": {
"build": "webpack",
"minify": "NODE_ENV=production webpack -p --config webpack.config.production.js",
"test": "jest",
"build": "webpack --config webpack.config.dev.js",
"build:min": "NODE_ENV=production webpack -p --config webpack.config.prod.js",
"build:all": "yarn build && yarn build:min",
"test": "flow && jest",
"tagRelease": "PKGV=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag v$PKGV",

@@ -42,3 +51,3 @@ "publishRelease": "git push origin master && git push --tags && npm publish",

"dependencies": {
"easy-date": "^1.1.1"
"easy-date": "^1.1.3"
},

@@ -45,0 +54,0 @@ "jest": {

@@ -15,12 +15,33 @@ [![Build Status](https://travis-ci.org/melvinsembrano/easy-date.svg?branch=master)](https://travis-ci.org/melvinsembrano/easy-date)

### Usage
**Node.js**
```
require('easy-date');
var easyDate = require('easy-date').easyDate;
// or
import { easyDate, backwardCompatibility } from 'easy-date'
// this will expose the number extension methods
// which was a default before version 1.2
backwardCompatibility();
```
**In Browser**
**Basic usage:**
```
<script src="easy-date.js"></script>
import { easyDate } from 'easy-date';
let date1 = easyDate(3).days().ago();
const date2 = easyDate(10).months().fromNow();
const date3 = easyDate(5).years().ago();
const date4 = easyDate(10).days().since(date2);
const date5 = easyDate(1).year().before(date1);
var yesterday = easyDate(24).hours().ago();
```
**Quickstart usage:**
**Legacy syntax usage:**
```
import { backwardCompatibility } from 'easy-date';
backwardCompatibility();
```
by adding the codes above, new methods are now available on all numbers:

@@ -27,0 +48,0 @@ * day(), days()

@@ -1,2 +0,2 @@

import './easy-date'
import './date-format'
export * from './easy-date'
export * from './date-format'

@@ -164,1 +164,3 @@ /*

}
export default dateFormat

@@ -1,146 +0,206 @@

/*
* EasyDate
* is a Javascript extension for easy dates manipulations which is heavily inspired by Rails ActiveSupport::Duration class.
* Copyright (c) 2015 Melvin Sembrano (melvinsembrano@gmail.com)
* License: MIT
*/
let EasyDate = function(value, type) {
let types = {
0: "day",
1: "week",
2: "month",
3: "year",
4: "hour"
};
// @flow
import dateFormat from './date-format'
export type ConversionType = "day" | "week" | "month" | "year" | "hour"
this.value = parseInt(value);
this.type = types[type];
export type TypeProcessor = {
ago: () => Date | string,
fromNow: () => Date | string,
}
};
export class EasyDate {
now: ?Date
value: number
conversionType: ConversionType
EasyDate.prototype.toString = function() {
return `${ this.value } ${ this.type }${ this.value > 1 ? 's' : '' }`;
};
constructor(value: any, conversionType: ConversionType) {
this.value = parseInt(value)
this.conversionType = conversionType
}
fromNow(mask?: string): Date | string {
const processor = this.process(mask)
if (processor) {
return processor.fromNow()
} else {
return `Processor not found.`
}
}
EasyDate.prototype.fromNow = function(mask) {
switch (this.type) {
case "day": return this._daysFromNow(mask);
case "month": return this._monthsFromNow(mask);
case "year": return this._yearsFromNow(mask);
case "hour": return this._hoursFromNow(mask);
default: return console.warn(`EasyDate: ${ this.type }().fromNow() not yet implemented.`);
ago(mask?: string): Date | string {
const processor = this.process(mask)
if (processor) {
return processor.ago()
} else {
return `Processor not found.`
}
}
};
EasyDate.prototype.ago = function(mask) {
switch (this.type) {
case "day": return this._daysAgo(mask);
case "month": return this._monthsAgo(mask);
case "year": return this._yearsAgo(mask);
case "hour": return this._hoursAgo(mask);
default: return console.warn(`EasyDate: ${ this.type }().ago() not yet implemented.`);
since(date: Date, mask?: string): Date | string {
this.now = new Date(date.valueOf())
return this.fromNow(mask)
}
};
until(date: Date, mask?: string): Date | string {
this.now = new Date(date.valueOf());
return this.ago(mask)
}
EasyDate.prototype.since = function(date, mask) {
this.now = new Date(date.valueOf());
return this.fromNow(mask);
};
before(date: Date, mask?: string): Date | string {
return this.until(date, mask)
}
EasyDate.prototype.until = function(date, mask) {
this.now = new Date(date.valueOf());
return this.ago(mask);
};
toString(): string {
return `${ this.value } ${ this.conversionType }${ this.value > 1 ? 's' : '' }`;
}
EasyDate.prototype.before = function(date, mask) {
return this.until(date, mask);
};
process(mask?: string): ?TypeProcessor {
const { conversionType, timeProcessor } = this
let now = this.now || new Date()
return {
hour(): ?TypeProcessor {
return timeProcessor(now, now.setHours, now.getHours, mask)
},
day(): TypeProcessor {
return timeProcessor(now, now.setDate, now.getDate, mask)
},
week(): ?TypeProcessor {
return null
},
month(): ?TypeProcessor {
return timeProcessor(now, now.setMonth, now.getMonth, mask)
},
year(): ?TypeProcessor {
return timeProcessor(now, now.setFullYear, now.getFullYear, mask)
},
}[conversionType]()
}
EasyDate.prototype._daysFromNow = function(mask) {
let now = this.now || new Date();
now.setDate(now.getDate() + this.value);
return formatDate(now, mask);
};
timeProcessor = (now: Date, set: any, get: any, mask?: string): TypeProcessor => {
const { value } = this
return {
ago(): Date | string {
set.call(now, get.call(now) - value)
return EasyDate.formatDate(now, mask);
},
EasyDate.prototype._daysAgo = function(mask) {
let now = this.now || new Date();
now.setDate(now.getDate() - this.value);
return formatDate(now, mask);
};
fromNow(): Date | string {
set.call(now, get.call(now) + value)
return EasyDate.formatDate(now, mask);
}
}
}
EasyDate.prototype._monthsFromNow = function(mask) {
let now = this.now || new Date();
now.setMonth(now.getMonth() + this.value);
return formatDate(now, mask);
};
static formatDate(date: Date, mask?: string): Date | string {
if (!!mask) {
return dateFormat(date, mask)
} else {
return date
}
}
EasyDate.prototype._monthsAgo = function(mask) {
let now = this.now || new Date();
now.setMonth(now.getMonth() - this.value);
return formatDate(now, mask);
};
static today(mask?: string) {
return EasyDate.formatDate(new Date(), mask)
}
EasyDate.prototype._yearsFromNow = function(mask) {
let now = this.now || new Date();
now.setFullYear(now.getFullYear() + this.value);
return formatDate(now, mask);
};
static yesterday(mask?: string) {
return new EasyDate(1, 'day').ago(mask)
}
EasyDate.prototype._yearsAgo = function(mask) {
let now = this.now || new Date();
now.setFullYear(now.getFullYear() - this.value);
return formatDate(now, mask);
};
static tomorrow(mask?: string) {
return new EasyDate(1, 'day').fromNow(mask)
}
}
EasyDate.prototype._hoursFromNow = function(mask) {
let now = this.now || new Date();
now.setHours(now.getHours() + this.value);
return formatDate(now, mask);
};
export function easyDate(value: Number) {
const days = function() {
return new EasyDate(value, 'day')
}
EasyDate.prototype._hoursAgo = function(mask) {
let now = this.now || new Date();
now.setHours(now.getHours() - this.value);
return formatDate(now, mask);
};
const months = function() {
return new EasyDate(value, 'month')
}
var formatDate = function(date, mask) {
if (mask === undefined) {
return date;
} else {
return date.format(mask);
const years = function() {
return new EasyDate(value, 'year')
}
};
let days = function() {
return new EasyDate(this, 0);
};
let months = function() {
return new EasyDate(this, 2);
};
let years = function() {
return new EasyDate(this, 3);
};
const hours = function() {
return new EasyDate(value, 'hour')
}
let hours = function() {
return new EasyDate(this, 4);
};
return {
hour: hours,
hours,
day: days,
days,
month: months,
months,
year: years,
years,
}
}
Number.prototype.day = days;
Number.prototype.days = days;
Number.prototype.month = months;
Number.prototype.months = months;
Number.prototype.years = years;
Number.prototype.year = years;
Number.prototype.hours = hours;
Number.prototype.hour = hours;
export function backwardCompatibility() {
Date.today = function(mask) {
return formatDate((new (this)()), mask);
};
const days = function() {
return new EasyDate(this, 'day')
}
Date.yesterday = mask => (1).day().ago(mask);
const months = function() {
return new EasyDate(this, 'month')
}
Date.tommorrow = mask => (1).day().fromNow(mask);
const years = function() {
return new EasyDate(this, 'year')
}
const hours = function() {
return new EasyDate(this, 'hour')
}
// $FlowFixMe
Number.prototype.day = days;
// $FlowFixMe
Number.prototype.days = days;
// $FlowFixMe
Number.prototype.month = months;
// $FlowFixMe
Number.prototype.months = months;
// $FlowFixMe
Number.prototype.years = years;
// $FlowFixMe
Number.prototype.year = years;
// $FlowFixMe
Number.prototype.hours = hours;
// $FlowFixMe
Number.prototype.hour = hours;
// $FlowFixMe
Object.assign(Date, {
today(mask?: string) {
return EasyDate.today(mask);
},
yesterday(mask?: string) {
return EasyDate.yesterday(mask)
},
tomorrow(mask?: string) {
return EasyDate.tomorrow(mask)
},
tommorrow(mask?: string) {
return EasyDate.tomorrow(mask)
},
})
}
export default {
EasyDate,
easyDate,
backwardCompatibility,
}

@@ -1,2 +0,2 @@

import '../easy-date-light'
import { easyDate, EasyDate } from '../src/easy-date'

@@ -6,3 +6,3 @@ describe('Date', function() {

var now = new Date();
var today = Date.today();
var today = EasyDate.today();
expect(today.getDate()).toBe(now.getDate());

@@ -14,4 +14,4 @@ expect(today.getFullYear()).toBe(now.getFullYear());

it('will get the date tommorrow', function() {
var now = 1..day().fromNow()
var today = Date.tommorrow();
var now = easyDate(1).day().fromNow()
var today = EasyDate.tomorrow();
expect(today.getDate()).toBe(now.getDate());

@@ -23,4 +23,4 @@ expect(today.getFullYear()).toBe(now.getFullYear());

it('will get the date yesterday', function() {
var now = 1..day().ago()
var today = Date.yesterday();
var now = easyDate(1).day().ago()
var today = EasyDate.yesterday();
expect(today.getDate()).toBe(now.getDate());

@@ -27,0 +27,0 @@ expect(today.getFullYear()).toBe(now.getFullYear());

@@ -1,2 +0,2 @@

import '../easy-date'
import { easyDate, EasyDate } from '../src/bundled'

@@ -11,8 +11,8 @@ describe('EasyDate Formats', function() {

it('will return formatted date string if mask is passed', function () {
var now = 2..days().fromNow();
expect(2..days().fromNow("yyyy")).toBe(now.getFullYear().toString());
var now = easyDate(2).days().fromNow();
expect(easyDate(2).days().fromNow("yyyy")).toBe(now.getFullYear().toString());
});
it('will return the actual date object if now masked is passed', function() {
var now = 2..days().fromNow();
expect(2..days().fromNow() instanceof Date).toBe(true);
var now = easyDate(2).days().fromNow();
expect(easyDate(2).days().fromNow() instanceof Date).toBe(true);
});

@@ -23,8 +23,8 @@ });

it('will return formatted date string if mask is passed', function () {
var now = 2..days().since(Date.now());
expect(2..days().since(Date.now(), "yyyy")).toBe(now.getFullYear().toString());
var now = easyDate(2).days().since(Date.now());
expect(easyDate(2).days().since(Date.now(), "yyyy")).toBe(now.getFullYear().toString());
});
it('will return the actual date object if now masked is passed', function() {
var now = 2..days().since(Date.now());
expect(2..days().since(Date.now()) instanceof Date).toBe(true);
var now = easyDate(2).days().since(Date.now());
expect(easyDate(2).days().since(Date.now()) instanceof Date).toBe(true);
});

@@ -35,8 +35,8 @@ });

it('will return formatted date string if mask is passed', function () {
var now = 2..days().ago();
expect(2..days().ago("yyyy")).toBe(now.getFullYear().toString());
var now = easyDate(2).days().ago();
expect(easyDate(2).days().ago("yyyy")).toBe(now.getFullYear().toString());
});
it('will return the actual date object if now masked is passed', function() {
var now = 2..days().ago();
expect(2..days().ago() instanceof Date).toBe(true);
var now = easyDate(2).days().ago();
expect(easyDate(2).days().ago() instanceof Date).toBe(true);
});

@@ -47,8 +47,9 @@ });

it('will return formatted date string if mask is passed', function () {
var now = 2..days().until(Date.today());
expect(2..days().until(Date.today(), "yyyy")).toBe(now.getFullYear().toString());
var now = easyDate(2).days().until(EasyDate.today());
expect(easyDate(2).days().until(EasyDate.today(), "yyyy")).toBe(now.getFullYear().toString());
});
it('will return the actual date object if now masked is passed', function() {
var now = 2..days().until(Date.today());
expect(2..days().until(Date.today()) instanceof Date).toBe(true);
var now = easyDate(2).days().until(EasyDate.today());
expect(easyDate(2).days().until(EasyDate.today()) instanceof Date).toBe(true);
});

@@ -55,0 +56,0 @@ });

@@ -1,2 +0,2 @@

import '../easy-date-light'
import { easyDate } from '../src/easy-date'

@@ -8,3 +8,3 @@ describe('EasyDate', function() {

now.setDate(now.getDate() + 5);
var newDate = 5..days().fromNow();
var newDate = easyDate(5).days().fromNow();

@@ -19,3 +19,3 @@ expect(newDate.getYear()).toBe(newDate.getYear())

now.setDate(now.getDate() - 5);
var newDate = 5..days().ago();
var newDate = easyDate(5).days().ago();

@@ -30,3 +30,3 @@ expect(newDate.getYear()).toBe(newDate.getYear())

now.setMonth(now.getMonth() + 5);
var newDate = 5..months().fromNow();
var newDate = easyDate(5).months().fromNow();

@@ -41,3 +41,3 @@ expect(newDate.getYear()).toBe(newDate.getYear())

now.setMonth(now.getMonth() - 5);
var newDate = 5..months().ago();
var newDate = easyDate(5).months().ago();

@@ -52,3 +52,3 @@ expect(newDate.getYear()).toBe(newDate.getYear())

now.setFullYear(now.getFullYear() + 5);
var newDate = 5..years().fromNow();
var newDate = easyDate(5).years().fromNow();

@@ -63,3 +63,3 @@ expect(newDate.getYear()).toBe(newDate.getYear())

now.setFullYear(now.getFullYear() - 5);
var newDate = 5..years().ago();
var newDate = easyDate(5).years().ago();

@@ -75,10 +75,10 @@ expect(newDate.getYear()).toBe(newDate.getYear())

it('can get the number of days', function() {
expect(2..days().value).toBe(2);
expect(1..day().type).toBe("day");
expect(easyDate(2).days().value).toBe(2);
expect(easyDate(1).day().conversionType).toBe("day");
});
it('will get the correct grammar', function() {
expect(1..day().toString()).toBe("1 day");
expect(3..days().toString()).toBe("3 days");
expect(5..days().toString()).toBe("5 days");
expect(easyDate(1).day().toString()).toBe("1 day");
expect(easyDate(3).days().toString()).toBe("3 days");
expect(easyDate(5).days().toString()).toBe("5 days");
});

@@ -88,3 +88,3 @@

var now = new Date();
expect(3..days().fromNow().getDate()).toBe(now.getDate() + 3);
expect(easyDate(3).days().fromNow().getDate()).toBe(now.getDate() + 3);
});

@@ -95,3 +95,3 @@

now.setDate(now.getDate() - 3);
expect(3..days().ago().getDate()).toBe(now.getDate());
expect(easyDate(3).days().ago().getDate()).toBe(now.getDate());
});

@@ -101,3 +101,3 @@

var now = new Date(2015, 3, 10);
expect(3..days().since(now).getDate()).toBe(13);
expect(easyDate(3).days().since(now).getDate()).toBe(13);
});

@@ -108,3 +108,3 @@

var newDate = now.getDate() - 3;
expect(3..days().until(now).getDate()).toBe(newDate);
expect(easyDate(3).days().until(now).getDate()).toBe(newDate);
});

@@ -115,3 +115,3 @@

var newDate = now.getDate() - 3;
expect(3..days().before(now).getDate()).toBe(newDate);
expect(easyDate(3).days().before(now).getDate()).toBe(newDate);
});

@@ -123,10 +123,10 @@ });

it('can get the number of months', function() {
expect(2..months().value).toBe(2);
expect(1..month().type).toBe("month");
expect(easyDate(2).months().value).toBe(2);
expect(easyDate(1).month().conversionType).toBe("month");
});
it('will get the correct grammar', function() {
expect(1..month().toString()).toBe("1 month");
expect(3..months().toString()).toBe("3 months");
expect(5..months().toString()).toBe("5 months");
expect(easyDate(1).month().toString()).toBe("1 month");
expect(easyDate(3).months().toString()).toBe("3 months");
expect(easyDate(5).months().toString()).toBe("5 months");
});

@@ -140,3 +140,3 @@

}
expect(3..months().fromNow().getMonth()).toBe(res);
expect(easyDate(3).months().fromNow().getMonth()).toBe(res);
});

@@ -150,3 +150,3 @@

}
expect(3..months().ago().getMonth()).toBe(res);
expect(easyDate(3).months().ago().getMonth()).toBe(res);
});

@@ -156,3 +156,3 @@

var now = new Date(2015, 3, 10);
expect(3..months().since(now).getMonth()).toBe(6);
expect(easyDate(3).months().since(now).getMonth()).toBe(6);
});

@@ -162,3 +162,3 @@

var now = new Date(2015, 9, 10);
expect(3..months().until(now).getMonth()).toBe(6);
expect(easyDate(3).months().until(now).getMonth()).toBe(6);
});

@@ -168,3 +168,3 @@

var now = new Date(2015, 9, 10);
expect(3..months().before(now).getMonth()).toBe(6);
expect(easyDate(3).months().before(now).getMonth()).toBe(6);
});

@@ -175,10 +175,10 @@ });

it('can get the number of years', function() {
expect(2..years().value).toBe(2);
expect(1..year().type).toBe("year");
expect(easyDate(2).years().value).toBe(2);
expect(easyDate(1).year().conversionType).toBe("year");
});
it('will get the correct grammar', function() {
expect(1..year().toString()).toBe("1 year");
expect(3..years().toString()).toBe("3 years");
expect(5..years().toString()).toBe("5 years");
expect(easyDate(1).year().toString()).toBe("1 year");
expect(easyDate(3).years().toString()).toBe("3 years");
expect(easyDate(5).years().toString()).toBe("5 years");
});

@@ -188,3 +188,3 @@

var now = new Date();
expect(3..years().fromNow().getFullYear()).toBe(now.getFullYear() + 3);
expect(easyDate(3).years().fromNow().getFullYear()).toBe(now.getFullYear() + 3);
});

@@ -194,3 +194,3 @@

var now = new Date();
expect(3..years().ago().getFullYear()).toBe(now.getFullYear() - 3);
expect(easyDate(3).years().ago().getFullYear()).toBe(now.getFullYear() - 3);
});

@@ -200,3 +200,3 @@

var now = new Date(2015, 3, 10);
expect(3..years().since(now).getFullYear()).toBe(2018);
expect(easyDate(3).years().since(now).getFullYear()).toBe(2018);
});

@@ -206,3 +206,3 @@

var now = new Date(2015, 9, 10);
expect(3..years().until(now).getFullYear()).toBe(2012);
expect(easyDate(3).years().until(now).getFullYear()).toBe(2012);
});

@@ -212,3 +212,3 @@

var now = new Date(2015, 9, 10);
expect(3..years().before(now).getFullYear()).toBe(2012);
expect(easyDate(3).years().before(now).getFullYear()).toBe(2012);
});

@@ -219,10 +219,10 @@ });

it('can get the number of hours', function() {
expect(2..hours().value).toBe(2);
expect(1..hour().type).toBe("hour");
expect(easyDate(2).hours().value).toBe(2);
expect(easyDate(1).hour().conversionType).toBe("hour");
});
it('will get the correct grammar', function() {
expect(1..hour().toString()).toBe("1 hour");
expect(3..hours().toString()).toBe("3 hours");
expect(5..hours().toString()).toBe("5 hours");
expect(easyDate(1).hour().toString()).toBe("1 hour");
expect(easyDate(3).hours().toString()).toBe("3 hours");
expect(easyDate(5).hours().toString()).toBe("5 hours");
});

@@ -233,3 +233,3 @@

now.setHours(now.getHours() + 3);
expect(3..hours().fromNow().getHours()).toBe(now.getHours());
expect(easyDate(3).hours().fromNow().getHours()).toBe(now.getHours());
});

@@ -240,3 +240,3 @@

now.setHours(now.getHours() - 3);
expect(3..hours().ago().getHours()).toBe(now.getHours());
expect(easyDate(3).hours().ago().getHours()).toBe(now.getHours());
});

@@ -246,3 +246,3 @@

var now = new Date(2015, 3, 10, 12);
expect(3..hours().since(now).getHours()).toBe(15);
expect(easyDate(3).hours().since(now).getHours()).toBe(15);
});

@@ -252,3 +252,3 @@

var now = new Date(2015, 9, 10, 12);
expect(3..hours().until(now).getHours()).toBe(9);
expect(easyDate(3).hours().until(now).getHours()).toBe(9);
});

@@ -258,5 +258,5 @@

var now = new Date(2015, 9, 10, 12);
expect(3..hours().before(now).getHours()).toBe(9);
expect(easyDate(3).hours().before(now).getHours()).toBe(9);
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc