index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. module.exports = (function () {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function (modId, func, req) {
  4. var m = {
  5. exports: {}
  6. };
  7. __MODS__[modId] = {
  8. status: 0,
  9. func: func,
  10. req: req,
  11. m: m
  12. };
  13. };
  14. var __REQUIRE__ = function (modId, source) {
  15. if (!__MODS__[modId]) {
  16. return require(source);
  17. }
  18. if (!__MODS__[modId].status) {
  19. var m = {
  20. exports: {}
  21. };
  22. __MODS__[modId].status = 1;
  23. __MODS__[modId].func(__MODS__[modId].req, m, m.exports);
  24. if (typeof m.exports === 'object') {
  25. Object.keys(m.exports).forEach(function (k) {
  26. __MODS__[modId].m.exports[k] = m.exports[k];
  27. });
  28. if (m.exports.__esModule) {
  29. Object.defineProperty(__MODS__[modId].m.exports, '__esModule', {
  30. value: true
  31. });
  32. }
  33. } else {
  34. __MODS__[modId].m.exports = m.exports;
  35. }
  36. }
  37. return __MODS__[modId].m.exports;
  38. };
  39. __DEFINE__(
  40. 1558102466021,
  41. function (require, module, exports) {
  42. (function (main) {
  43. /**
  44. * Parse or format dates
  45. * @class fecha
  46. */
  47. var fecha = {};
  48. var token = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
  49. var twoDigits = /\d\d?/;
  50. var threeDigits = /\d{3}/;
  51. var fourDigits = /\d{4}/;
  52. var word = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
  53. var literal = /\[([^]*?)\]/gm;
  54. var noop = function () {};
  55. function shorten(arr, sLen) {
  56. var newArr = [];
  57. for (var i = 0, len = arr.length; i < len; i++) {
  58. newArr.push(arr[i].substr(0, sLen));
  59. }
  60. return newArr;
  61. }
  62. function monthUpdate(arrName) {
  63. return function (d, v, i18n) {
  64. var index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase());
  65. if (~index) {
  66. d.month = index;
  67. }
  68. };
  69. }
  70. function pad(val, len) {
  71. val = String(val);
  72. len = len || 2;
  73. while (val.length < len) {
  74. val = '0' + val;
  75. }
  76. return val;
  77. }
  78. var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  79. var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  80. var monthNamesShort = shorten(monthNames, 3);
  81. var dayNamesShort = shorten(dayNames, 3);
  82. fecha.i18n = {
  83. dayNamesShort: dayNamesShort,
  84. dayNames: dayNames,
  85. monthNamesShort: monthNamesShort,
  86. monthNames: monthNames,
  87. amPm: ['am', 'pm'],
  88. DoFn: function DoFn(D) {
  89. return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : ((D - (D % 10) !== 10) * D) % 10];
  90. }
  91. };
  92. var formatFlags = {
  93. D: function (dateObj) {
  94. return dateObj.getDate();
  95. },
  96. DD: function (dateObj) {
  97. return pad(dateObj.getDate());
  98. },
  99. Do: function (dateObj, i18n) {
  100. return i18n.DoFn(dateObj.getDate());
  101. },
  102. d: function (dateObj) {
  103. return dateObj.getDay();
  104. },
  105. dd: function (dateObj) {
  106. return pad(dateObj.getDay());
  107. },
  108. ddd: function (dateObj, i18n) {
  109. return i18n.dayNamesShort[dateObj.getDay()];
  110. },
  111. dddd: function (dateObj, i18n) {
  112. return i18n.dayNames[dateObj.getDay()];
  113. },
  114. M: function (dateObj) {
  115. return dateObj.getMonth() + 1;
  116. },
  117. MM: function (dateObj) {
  118. return pad(dateObj.getMonth() + 1);
  119. },
  120. MMM: function (dateObj, i18n) {
  121. return i18n.monthNamesShort[dateObj.getMonth()];
  122. },
  123. MMMM: function (dateObj, i18n) {
  124. return i18n.monthNames[dateObj.getMonth()];
  125. },
  126. YY: function (dateObj) {
  127. return String(dateObj.getFullYear()).substr(2);
  128. },
  129. YYYY: function (dateObj) {
  130. return pad(dateObj.getFullYear(), 4);
  131. },
  132. h: function (dateObj) {
  133. return dateObj.getHours() % 12 || 12;
  134. },
  135. hh: function (dateObj) {
  136. return pad(dateObj.getHours() % 12 || 12);
  137. },
  138. H: function (dateObj) {
  139. return dateObj.getHours();
  140. },
  141. HH: function (dateObj) {
  142. return pad(dateObj.getHours());
  143. },
  144. m: function (dateObj) {
  145. return dateObj.getMinutes();
  146. },
  147. mm: function (dateObj) {
  148. return pad(dateObj.getMinutes());
  149. },
  150. s: function (dateObj) {
  151. return dateObj.getSeconds();
  152. },
  153. ss: function (dateObj) {
  154. return pad(dateObj.getSeconds());
  155. },
  156. S: function (dateObj) {
  157. return Math.round(dateObj.getMilliseconds() / 100);
  158. },
  159. SS: function (dateObj) {
  160. return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
  161. },
  162. SSS: function (dateObj) {
  163. return pad(dateObj.getMilliseconds(), 3);
  164. },
  165. a: function (dateObj, i18n) {
  166. return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
  167. },
  168. A: function (dateObj, i18n) {
  169. return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
  170. },
  171. ZZ: function (dateObj) {
  172. var o = dateObj.getTimezoneOffset();
  173. return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + (Math.abs(o) % 60), 4);
  174. }
  175. };
  176. var parseFlags = {
  177. D: [
  178. twoDigits,
  179. function (d, v) {
  180. d.day = v;
  181. }
  182. ],
  183. Do: [
  184. new RegExp(twoDigits.source + word.source),
  185. function (d, v) {
  186. d.day = parseInt(v, 10);
  187. }
  188. ],
  189. M: [
  190. twoDigits,
  191. function (d, v) {
  192. d.month = v - 1;
  193. }
  194. ],
  195. YY: [
  196. twoDigits,
  197. function (d, v) {
  198. var da = new Date();
  199. var cent = +('' + da.getFullYear()).substr(0, 2);
  200. d.year = '' + (v > 68 ? cent - 1 : cent) + v;
  201. }
  202. ],
  203. h: [
  204. twoDigits,
  205. function (d, v) {
  206. d.hour = v;
  207. }
  208. ],
  209. m: [
  210. twoDigits,
  211. function (d, v) {
  212. d.minute = v;
  213. }
  214. ],
  215. s: [
  216. twoDigits,
  217. function (d, v) {
  218. d.second = v;
  219. }
  220. ],
  221. YYYY: [
  222. fourDigits,
  223. function (d, v) {
  224. d.year = v;
  225. }
  226. ],
  227. S: [
  228. /\d/,
  229. function (d, v) {
  230. d.millisecond = v * 100;
  231. }
  232. ],
  233. SS: [
  234. /\d{2}/,
  235. function (d, v) {
  236. d.millisecond = v * 10;
  237. }
  238. ],
  239. SSS: [
  240. threeDigits,
  241. function (d, v) {
  242. d.millisecond = v;
  243. }
  244. ],
  245. d: [twoDigits, noop],
  246. ddd: [word, noop],
  247. MMM: [word, monthUpdate('monthNamesShort')],
  248. MMMM: [word, monthUpdate('monthNames')],
  249. a: [
  250. word,
  251. function (d, v, i18n) {
  252. var val = v.toLowerCase();
  253. if (val === i18n.amPm[0]) {
  254. d.isPm = false;
  255. } else if (val === i18n.amPm[1]) {
  256. d.isPm = true;
  257. }
  258. }
  259. ],
  260. ZZ: [
  261. /([\+\-]\d\d:?\d\d|Z)/,
  262. function (d, v) {
  263. if (v === 'Z') {
  264. v = '+00:00';
  265. }
  266. var parts = (v + '').match(/([\+\-]|\d\d)/gi);
  267. var minutes;
  268. if (parts) {
  269. minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
  270. d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
  271. }
  272. }
  273. ]
  274. };
  275. parseFlags.dd = parseFlags.d;
  276. parseFlags.dddd = parseFlags.ddd;
  277. parseFlags.DD = parseFlags.D;
  278. parseFlags.mm = parseFlags.m;
  279. parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
  280. parseFlags.MM = parseFlags.M;
  281. parseFlags.ss = parseFlags.s;
  282. parseFlags.A = parseFlags.a;
  283. // Some common format strings
  284. fecha.masks = {
  285. default: 'ddd MMM DD YYYY HH:mm:ss',
  286. shortDate: 'M/D/YY',
  287. mediumDate: 'MMM D, YYYY',
  288. longDate: 'MMMM D, YYYY',
  289. fullDate: 'dddd, MMMM D, YYYY',
  290. shortTime: 'HH:mm',
  291. mediumTime: 'HH:mm:ss',
  292. longTime: 'HH:mm:ss.SSS'
  293. };
  294. /***
  295. * Format a date
  296. * @method format
  297. * @param {Date|number} dateObj
  298. * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
  299. */
  300. fecha.format = function (dateObj, mask, i18nSettings) {
  301. var i18n = i18nSettings || fecha.i18n;
  302. if (typeof dateObj === 'number') {
  303. dateObj = new Date(dateObj);
  304. }
  305. if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
  306. throw new Error('Invalid Date in fecha.format');
  307. }
  308. mask = fecha.masks[mask] || mask || fecha.masks['default'];
  309. var literals = [];
  310. // Make literals inactive by replacing them with ??
  311. mask = mask.replace(literal, function ($0, $1) {
  312. literals.push($1);
  313. return '??';
  314. });
  315. // Apply formatting rules
  316. mask = mask.replace(token, function ($0) {
  317. return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
  318. });
  319. // Inline literal values back into the formatted value
  320. return mask.replace(/\?\?/g, function () {
  321. return literals.shift();
  322. });
  323. };
  324. /**
  325. * Parse a date string into an object, changes - into /
  326. * @method parse
  327. * @param {string} dateStr Date string
  328. * @param {string} format Date parse format
  329. * @returns {Date|boolean}
  330. */
  331. fecha.parse = function (dateStr, format, i18nSettings) {
  332. var i18n = i18nSettings || fecha.i18n;
  333. if (typeof format !== 'string') {
  334. throw new Error('Invalid format in fecha.parse');
  335. }
  336. format = fecha.masks[format] || format;
  337. // Avoid regular expression denial of service, fail early for really long strings
  338. // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
  339. if (dateStr.length > 1000) {
  340. return false;
  341. }
  342. var isValid = true;
  343. var dateInfo = {};
  344. format.replace(token, function ($0) {
  345. if (parseFlags[$0]) {
  346. var info = parseFlags[$0];
  347. var index = dateStr.search(info[0]);
  348. if (!~index) {
  349. isValid = false;
  350. } else {
  351. dateStr.replace(info[0], function (result) {
  352. info[1](dateInfo, result, i18n);
  353. dateStr = dateStr.substr(index + result.length);
  354. return result;
  355. });
  356. }
  357. }
  358. return parseFlags[$0] ? '' : $0.slice(1, $0.length - 1);
  359. });
  360. if (!isValid) {
  361. return false;
  362. }
  363. var today = new Date();
  364. if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
  365. dateInfo.hour = +dateInfo.hour + 12;
  366. } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
  367. dateInfo.hour = 0;
  368. }
  369. var date;
  370. if (dateInfo.timezoneOffset != null) {
  371. dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
  372. date = new Date(
  373. Date.UTC(
  374. dateInfo.year || today.getFullYear(),
  375. dateInfo.month || 0,
  376. dateInfo.day || 1,
  377. dateInfo.hour || 0,
  378. dateInfo.minute || 0,
  379. dateInfo.second || 0,
  380. dateInfo.millisecond || 0
  381. )
  382. );
  383. } else {
  384. date = new Date(
  385. dateInfo.year || today.getFullYear(),
  386. dateInfo.month || 0,
  387. dateInfo.day || 1,
  388. dateInfo.hour || 0,
  389. dateInfo.minute || 0,
  390. dateInfo.second || 0,
  391. dateInfo.millisecond || 0
  392. );
  393. }
  394. return date;
  395. };
  396. /* istanbul ignore next */
  397. if (typeof module !== 'undefined' && module.exports) {
  398. module.exports = fecha;
  399. } else if (typeof define === 'function' && define.amd) {
  400. define(function () {
  401. return fecha;
  402. });
  403. } else {
  404. main.fecha = fecha;
  405. }
  406. })(this);
  407. },
  408. function (modId) {
  409. var map = {};
  410. return __REQUIRE__(map[modId], modId);
  411. }
  412. );
  413. return __REQUIRE__(1558102466021);
  414. })();
  415. //# sourceMappingURL=index.js.map