dayjs.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. 'undefined' != typeof globalThis
  2. ? globalThis
  3. : 'undefined' != typeof window
  4. ? window
  5. : 'undefined' != typeof global
  6. ? global
  7. : 'undefined' != typeof self && self;
  8. var t = { exports: {} },
  9. e = (t.exports = (function () {
  10. var t = 1e3,
  11. e = 6e4,
  12. n = 36e5,
  13. r = 'millisecond',
  14. s = 'second',
  15. i = 'minute',
  16. u = 'hour',
  17. a = 'day',
  18. o = 'week',
  19. c = 'month',
  20. f = 'quarter',
  21. h = 'year',
  22. d = 'date',
  23. l = 'Invalid Date',
  24. $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,
  25. y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,
  26. M = {
  27. name: 'en',
  28. weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
  29. months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
  30. ordinal: function (t) {
  31. var e = ['th', 'st', 'nd', 'rd'],
  32. n = t % 100;
  33. return '[' + t + (e[(n - 20) % 10] || e[n] || e[0]) + ']';
  34. }
  35. },
  36. g = function (t, e, n) {
  37. var r = String(t);
  38. return !r || r.length >= e ? t : '' + Array(e + 1 - r.length).join(n) + t;
  39. },
  40. v = {
  41. s: g,
  42. z: function (t) {
  43. var e = -t.utcOffset(),
  44. n = Math.abs(e),
  45. r = Math.floor(n / 60),
  46. s = n % 60;
  47. return (e <= 0 ? '+' : '-') + g(r, 2, '0') + ':' + g(s, 2, '0');
  48. },
  49. m: function t(e, n) {
  50. if (e.date() < n.date()) return -t(n, e);
  51. var r = 12 * (n.year() - e.year()) + (n.month() - e.month()),
  52. s = e.clone().add(r, c),
  53. i = n - s < 0,
  54. u = e.clone().add(r + (i ? -1 : 1), c);
  55. return +(-(r + (n - s) / (i ? s - u : u - s)) || 0);
  56. },
  57. a: function (t) {
  58. return t < 0 ? Math.ceil(t) || 0 : Math.floor(t);
  59. },
  60. p: function (t) {
  61. return (
  62. { M: c, y: h, w: o, d: a, D: d, h: u, m: i, s: s, ms: r, Q: f }[t] ||
  63. String(t || '')
  64. .toLowerCase()
  65. .replace(/s$/, '')
  66. );
  67. },
  68. u: function (t) {
  69. return void 0 === t;
  70. }
  71. },
  72. m = 'en',
  73. D = {};
  74. D[m] = M;
  75. var p = '$isDayjsObject',
  76. S = function (t) {
  77. return t instanceof _ || !(!t || !t[p]);
  78. },
  79. w = function t(e, n, r) {
  80. var s;
  81. if (!e) return m;
  82. if ('string' == typeof e) {
  83. var i = e.toLowerCase();
  84. D[i] && (s = i), n && ((D[i] = n), (s = i));
  85. var u = e.split('-');
  86. if (!s && u.length > 1) return t(u[0]);
  87. } else {
  88. var a = e.name;
  89. (D[a] = e), (s = a);
  90. }
  91. return !r && s && (m = s), s || (!r && m);
  92. },
  93. b = function (t, e) {
  94. if (S(t)) return t.clone();
  95. var n = 'object' == typeof e ? e : {};
  96. return (n.date = t), (n.args = arguments), new _(n);
  97. },
  98. O = v;
  99. (O.l = w),
  100. (O.i = S),
  101. (O.w = function (t, e) {
  102. return b(t, { locale: e.$L, utc: e.$u, x: e.$x, $offset: e.$offset });
  103. });
  104. var _ = (function () {
  105. function M(t) {
  106. (this.$L = w(t.locale, null, !0)), this.parse(t), (this.$x = this.$x || t.x || {}), (this[p] = !0);
  107. }
  108. var g = M.prototype;
  109. return (
  110. (g.parse = function (t) {
  111. (this.$d = (function (t) {
  112. var e = t.date,
  113. n = t.utc;
  114. if (null === e) return new Date(NaN);
  115. if (O.u(e)) return new Date();
  116. if (e instanceof Date) return new Date(e);
  117. if ('string' == typeof e && !/Z$/i.test(e)) {
  118. var r = e.match($);
  119. if (r) {
  120. var s = r[2] - 1 || 0,
  121. i = (r[7] || '0').substring(0, 3);
  122. return n
  123. ? new Date(Date.UTC(r[1], s, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, i))
  124. : new Date(r[1], s, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, i);
  125. }
  126. }
  127. return new Date(e);
  128. })(t)),
  129. this.init();
  130. }),
  131. (g.init = function () {
  132. var t = this.$d;
  133. (this.$y = t.getFullYear()),
  134. (this.$M = t.getMonth()),
  135. (this.$D = t.getDate()),
  136. (this.$W = t.getDay()),
  137. (this.$H = t.getHours()),
  138. (this.$m = t.getMinutes()),
  139. (this.$s = t.getSeconds()),
  140. (this.$ms = t.getMilliseconds());
  141. }),
  142. (g.$utils = function () {
  143. return O;
  144. }),
  145. (g.isValid = function () {
  146. return !(this.$d.toString() === l);
  147. }),
  148. (g.isSame = function (t, e) {
  149. var n = b(t);
  150. return this.startOf(e) <= n && n <= this.endOf(e);
  151. }),
  152. (g.isAfter = function (t, e) {
  153. return b(t) < this.startOf(e);
  154. }),
  155. (g.isBefore = function (t, e) {
  156. return this.endOf(e) < b(t);
  157. }),
  158. (g.$g = function (t, e, n) {
  159. return O.u(t) ? this[e] : this.set(n, t);
  160. }),
  161. (g.unix = function () {
  162. return Math.floor(this.valueOf() / 1e3);
  163. }),
  164. (g.valueOf = function () {
  165. return this.$d.getTime();
  166. }),
  167. (g.startOf = function (t, e) {
  168. var n = this,
  169. r = !!O.u(e) || e,
  170. f = O.p(t),
  171. l = function (t, e) {
  172. var s = O.w(n.$u ? Date.UTC(n.$y, e, t) : new Date(n.$y, e, t), n);
  173. return r ? s : s.endOf(a);
  174. },
  175. $ = function (t, e) {
  176. return O.w(n.toDate()[t].apply(n.toDate('s'), (r ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e)), n);
  177. },
  178. y = this.$W,
  179. M = this.$M,
  180. g = this.$D,
  181. v = 'set' + (this.$u ? 'UTC' : '');
  182. switch (f) {
  183. case h:
  184. return r ? l(1, 0) : l(31, 11);
  185. case c:
  186. return r ? l(1, M) : l(0, M + 1);
  187. case o:
  188. var m = this.$locale().weekStart || 0,
  189. D = (y < m ? y + 7 : y) - m;
  190. return l(r ? g - D : g + (6 - D), M);
  191. case a:
  192. case d:
  193. return $(v + 'Hours', 0);
  194. case u:
  195. return $(v + 'Minutes', 1);
  196. case i:
  197. return $(v + 'Seconds', 2);
  198. case s:
  199. return $(v + 'Milliseconds', 3);
  200. default:
  201. return this.clone();
  202. }
  203. }),
  204. (g.endOf = function (t) {
  205. return this.startOf(t, !1);
  206. }),
  207. (g.$set = function (t, e) {
  208. var n,
  209. o = O.p(t),
  210. f = 'set' + (this.$u ? 'UTC' : ''),
  211. l = ((n = {}),
  212. (n[a] = f + 'Date'),
  213. (n[d] = f + 'Date'),
  214. (n[c] = f + 'Month'),
  215. (n[h] = f + 'FullYear'),
  216. (n[u] = f + 'Hours'),
  217. (n[i] = f + 'Minutes'),
  218. (n[s] = f + 'Seconds'),
  219. (n[r] = f + 'Milliseconds'),
  220. n)[o],
  221. $ = o === a ? this.$D + (e - this.$W) : e;
  222. if (o === c || o === h) {
  223. var y = this.clone().set(d, 1);
  224. y.$d[l]($), y.init(), (this.$d = y.set(d, Math.min(this.$D, y.daysInMonth())).$d);
  225. } else l && this.$d[l]($);
  226. return this.init(), this;
  227. }),
  228. (g.set = function (t, e) {
  229. return this.clone().$set(t, e);
  230. }),
  231. (g.get = function (t) {
  232. return this[O.p(t)]();
  233. }),
  234. (g.add = function (r, f) {
  235. var d,
  236. l = this;
  237. r = Number(r);
  238. var $ = O.p(f),
  239. y = function (t) {
  240. var e = b(l);
  241. return O.w(e.date(e.date() + Math.round(t * r)), l);
  242. };
  243. if ($ === c) return this.set(c, this.$M + r);
  244. if ($ === h) return this.set(h, this.$y + r);
  245. if ($ === a) return y(1);
  246. if ($ === o) return y(7);
  247. var M = ((d = {}), (d[i] = e), (d[u] = n), (d[s] = t), d)[$] || 1,
  248. g = this.$d.getTime() + r * M;
  249. return O.w(g, this);
  250. }),
  251. (g.subtract = function (t, e) {
  252. return this.add(-1 * t, e);
  253. }),
  254. (g.format = function (t) {
  255. var e = this,
  256. n = this.$locale();
  257. if (!this.isValid()) return n.invalidDate || l;
  258. var r = t || 'YYYY-MM-DDTHH:mm:ssZ',
  259. s = O.z(this),
  260. i = this.$H,
  261. u = this.$m,
  262. a = this.$M,
  263. o = n.weekdays,
  264. c = n.months,
  265. f = n.meridiem,
  266. h = function (t, n, s, i) {
  267. return (t && (t[n] || t(e, r))) || s[n].slice(0, i);
  268. },
  269. d = function (t) {
  270. return O.s(i % 12 || 12, t, '0');
  271. },
  272. $ =
  273. f ||
  274. function (t, e, n) {
  275. var r = t < 12 ? 'AM' : 'PM';
  276. return n ? r.toLowerCase() : r;
  277. };
  278. return r.replace(y, function (t, r) {
  279. return (
  280. r ||
  281. (function (t) {
  282. switch (t) {
  283. case 'YY':
  284. return String(e.$y).slice(-2);
  285. case 'YYYY':
  286. return O.s(e.$y, 4, '0');
  287. case 'M':
  288. return a + 1;
  289. case 'MM':
  290. return O.s(a + 1, 2, '0');
  291. case 'MMM':
  292. return h(n.monthsShort, a, c, 3);
  293. case 'MMMM':
  294. return h(c, a);
  295. case 'D':
  296. return e.$D;
  297. case 'DD':
  298. return O.s(e.$D, 2, '0');
  299. case 'd':
  300. return String(e.$W);
  301. case 'dd':
  302. return h(n.weekdaysMin, e.$W, o, 2);
  303. case 'ddd':
  304. return h(n.weekdaysShort, e.$W, o, 3);
  305. case 'dddd':
  306. return o[e.$W];
  307. case 'H':
  308. return String(i);
  309. case 'HH':
  310. return O.s(i, 2, '0');
  311. case 'h':
  312. return d(1);
  313. case 'hh':
  314. return d(2);
  315. case 'a':
  316. return $(i, u, !0);
  317. case 'A':
  318. return $(i, u, !1);
  319. case 'm':
  320. return String(u);
  321. case 'mm':
  322. return O.s(u, 2, '0');
  323. case 's':
  324. return String(e.$s);
  325. case 'ss':
  326. return O.s(e.$s, 2, '0');
  327. case 'SSS':
  328. return O.s(e.$ms, 3, '0');
  329. case 'Z':
  330. return s;
  331. }
  332. return null;
  333. })(t) ||
  334. s.replace(':', '')
  335. );
  336. });
  337. }),
  338. (g.utcOffset = function () {
  339. return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
  340. }),
  341. (g.diff = function (r, d, l) {
  342. var $,
  343. y = this,
  344. M = O.p(d),
  345. g = b(r),
  346. v = (g.utcOffset() - this.utcOffset()) * e,
  347. m = this - g,
  348. D = function () {
  349. return O.m(y, g);
  350. };
  351. switch (M) {
  352. case h:
  353. $ = D() / 12;
  354. break;
  355. case c:
  356. $ = D();
  357. break;
  358. case f:
  359. $ = D() / 3;
  360. break;
  361. case o:
  362. $ = (m - v) / 6048e5;
  363. break;
  364. case a:
  365. $ = (m - v) / 864e5;
  366. break;
  367. case u:
  368. $ = m / n;
  369. break;
  370. case i:
  371. $ = m / e;
  372. break;
  373. case s:
  374. $ = m / t;
  375. break;
  376. default:
  377. $ = m;
  378. }
  379. return l ? $ : O.a($);
  380. }),
  381. (g.daysInMonth = function () {
  382. return this.endOf(c).$D;
  383. }),
  384. (g.$locale = function () {
  385. return D[this.$L];
  386. }),
  387. (g.locale = function (t, e) {
  388. if (!t) return this.$L;
  389. var n = this.clone(),
  390. r = w(t, e, !0);
  391. return r && (n.$L = r), n;
  392. }),
  393. (g.clone = function () {
  394. return O.w(this.$d, this);
  395. }),
  396. (g.toDate = function () {
  397. return new Date(this.valueOf());
  398. }),
  399. (g.toJSON = function () {
  400. return this.isValid() ? this.toISOString() : null;
  401. }),
  402. (g.toISOString = function () {
  403. return this.$d.toISOString();
  404. }),
  405. (g.toString = function () {
  406. return this.$d.toUTCString();
  407. }),
  408. M
  409. );
  410. })(),
  411. k = _.prototype;
  412. return (
  413. (b.prototype = k),
  414. [
  415. ['$ms', r],
  416. ['$s', s],
  417. ['$m', i],
  418. ['$H', u],
  419. ['$W', a],
  420. ['$M', c],
  421. ['$y', h],
  422. ['$D', d]
  423. ].forEach(function (t) {
  424. k[t[1]] = function (e) {
  425. return this.$g(e, t[0], t[1]);
  426. };
  427. }),
  428. (b.extend = function (t, e) {
  429. return t.$i || (t(e, _, b), (t.$i = !0)), b;
  430. }),
  431. (b.locale = w),
  432. (b.isDayjs = S),
  433. (b.unix = function (t) {
  434. return b(1e3 * t);
  435. }),
  436. (b.en = D[m]),
  437. (b.Ls = D),
  438. (b.p = {}),
  439. b
  440. );
  441. })());
  442. export { e as default };