eoss 0.1.0-alpha.39 → 0.1.0-alpha.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/lib/0.js +1 -1
  2. package/lib/1.js +1 -1
  3. package/lib/10.js +1 -1
  4. package/lib/11.js +1 -1
  5. package/lib/12.js +1 -1
  6. package/lib/13.js +1 -1
  7. package/lib/14.js +1 -1
  8. package/lib/15.js +1 -1
  9. package/lib/16.js +1 -1
  10. package/lib/17.js +1 -1
  11. package/lib/18.js +1 -1
  12. package/lib/19.js +1 -1
  13. package/lib/20.js +1 -1
  14. package/lib/21.js +1 -1
  15. package/lib/22.js +1 -1
  16. package/lib/23.js +1 -1
  17. package/lib/24.js +1 -1
  18. package/lib/25.js +1 -1
  19. package/lib/26.js +1 -1
  20. package/lib/27.js +1 -1
  21. package/lib/28.js +1 -1
  22. package/lib/29.js +1 -1
  23. package/lib/3.js +1 -1
  24. package/lib/30.js +1 -1
  25. package/lib/31.js +1 -1
  26. package/lib/32.js +1 -1
  27. package/lib/33.js +1 -1
  28. package/lib/34.js +1 -1
  29. package/lib/35.js +1 -1
  30. package/lib/36.js +1 -1
  31. package/lib/37.js +1 -1
  32. package/lib/38.js +1 -1
  33. package/lib/39.js +1 -1
  34. package/lib/4.js +1 -1
  35. package/lib/40.js +1 -1
  36. package/lib/41.js +1 -1
  37. package/lib/42.js +1 -1
  38. package/lib/43.js +1 -1
  39. package/lib/44.js +1 -1
  40. package/lib/45.js +1 -1
  41. package/lib/46.js +1 -1
  42. package/lib/47.js +1 -1
  43. package/lib/48.js +1 -1
  44. package/lib/49.js +1 -1
  45. package/lib/5.js +1 -1
  46. package/lib/50.js +1 -1
  47. package/lib/51.js +1 -1
  48. package/lib/52.js +1 -1
  49. package/lib/53.js +1 -1
  50. package/lib/54.js +1 -1
  51. package/lib/55.js +1 -1
  52. package/lib/56.js +1 -1
  53. package/lib/57.js +1 -1
  54. package/lib/58.js +1 -1
  55. package/lib/59.js +1 -1
  56. package/lib/6.js +1 -1
  57. package/lib/60.js +1 -1
  58. package/lib/61.js +1 -1
  59. package/lib/62.js +1 -1
  60. package/lib/63.js +1 -1
  61. package/lib/64.js +1 -1
  62. package/lib/65.js +1 -1
  63. package/lib/66.js +1 -1
  64. package/lib/67.js +1 -1
  65. package/lib/68.js +1 -1
  66. package/lib/69.js +1 -1
  67. package/lib/7.js +1 -1
  68. package/lib/70.js +1 -1
  69. package/lib/71.js +1 -1
  70. package/lib/72.js +1 -1
  71. package/lib/73.js +1 -1
  72. package/lib/74.js +1 -1
  73. package/lib/75.js +1 -1
  74. package/lib/76.js +1 -1
  75. package/lib/77.js +1 -1
  76. package/lib/78.js +1 -1
  77. package/lib/79.js +1 -1
  78. package/lib/8.js +1 -1
  79. package/lib/80.js +1 -1
  80. package/lib/81.js +1 -1
  81. package/lib/9.js +1 -1
  82. package/lib/account-login.js +837 -862
  83. package/lib/alert.js +2 -2
  84. package/lib/aside.js +2 -2
  85. package/lib/audit-trajectory.js +4 -4
  86. package/lib/autocomplete.js +1813 -1988
  87. package/lib/avatar.js +2 -2
  88. package/lib/backtop.js +2 -2
  89. package/lib/badge.js +2 -2
  90. package/lib/breadcrumb-item.js +4 -4
  91. package/lib/breadcrumb.js +4 -4
  92. package/lib/button-group.js +4 -4
  93. package/lib/button.js +2 -2
  94. package/lib/ca-login.js +837 -862
  95. package/lib/calendar.js +839 -864
  96. package/lib/card.js +2 -2
  97. package/lib/carousel-item.js +846 -871
  98. package/lib/carousel.js +839 -864
  99. package/lib/cascader-panel.js +852 -877
  100. package/lib/cascader.js +2048 -2223
  101. package/lib/checkbox-button.js +4 -4
  102. package/lib/checkbox-group.js +859 -884
  103. package/lib/checkbox.js +4 -4
  104. package/lib/col.js +2 -2
  105. package/lib/collapse-item.js +1040 -1065
  106. package/lib/collapse.js +1040 -1065
  107. package/lib/color-picker.js +972 -1122
  108. package/lib/container.js +2 -2
  109. package/lib/cron.js +12 -12
  110. package/lib/data-table.js +843 -868
  111. package/lib/date-picker.js +10520 -10695
  112. package/lib/descriptions-item.js +4 -4
  113. package/lib/descriptions.js +4 -4
  114. package/lib/dialog.js +837 -862
  115. package/lib/divider.js +2 -2
  116. package/lib/drawer.js +2 -2
  117. package/lib/dropdown-item.js +4 -4
  118. package/lib/dropdown-menu.js +974 -1124
  119. package/lib/dropdown.js +841 -866
  120. package/lib/email-login.js +837 -862
  121. package/lib/empty.js +2 -2
  122. package/lib/eoss.common.js +4023 -2668
  123. package/lib/flip.js +2 -2
  124. package/lib/flow-group.js +853 -878
  125. package/lib/flow.js +868 -893
  126. package/lib/flows.js +854 -879
  127. package/lib/footer.js +2 -2
  128. package/lib/form-item.js +860 -885
  129. package/lib/form.js +933 -950
  130. package/lib/guide.js +2 -2
  131. package/lib/header.js +2 -2
  132. package/lib/icon.js +837 -862
  133. package/lib/icons.js +2 -2
  134. package/lib/image-viewer.js +837 -862
  135. package/lib/image.js +4 -4
  136. package/lib/index.js +1 -1
  137. package/lib/infinite-scroll.js +2 -2
  138. package/lib/input-number.js +6 -6
  139. package/lib/input.js +839 -864
  140. package/lib/link.js +2 -2
  141. package/lib/loading.js +2 -2
  142. package/lib/login.js +867 -891
  143. package/lib/lowcode-view.js +1843 -1185
  144. package/lib/lowcode.js +3050 -1569
  145. package/lib/main.js +970 -988
  146. package/lib/marquee.js +837 -862
  147. package/lib/menu-item-group.js +15 -15
  148. package/lib/menu-item.js +6 -6
  149. package/lib/menu.js +2227 -2368
  150. package/lib/message-box.js +843 -868
  151. package/lib/message.js +839 -864
  152. package/lib/notification.js +861 -886
  153. package/lib/option-group.js +4 -4
  154. package/lib/option.js +839 -864
  155. package/lib/page-header.js +2 -2
  156. package/lib/pagination.js +839 -864
  157. package/lib/phone-login.js +847 -866
  158. package/lib/popconfirm.js +4 -4
  159. package/lib/popover.js +1831 -2006
  160. package/lib/process-config.js +839 -864
  161. package/lib/process-module.js +846 -871
  162. package/lib/process-rule.js +905 -930
  163. package/lib/progress.js +2 -2
  164. package/lib/qr-code.js +4 -4
  165. package/lib/qrcode-login.js +839 -864
  166. package/lib/radio-button.js +4 -4
  167. package/lib/radio-group.js +850 -875
  168. package/lib/radio.js +4 -4
  169. package/lib/rate.js +837 -862
  170. package/lib/retrial-auth.js +837 -862
  171. package/lib/row.js +2 -2
  172. package/lib/scrollbar.js +839 -864
  173. package/lib/select.js +2139 -2314
  174. package/lib/selector-panel.js +940 -965
  175. package/lib/selector.js +852 -877
  176. package/lib/slider.js +4 -4
  177. package/lib/step.js +32 -32
  178. package/lib/steps.js +874 -899
  179. package/lib/submenu.js +1269 -1385
  180. package/lib/switch.js +839 -864
  181. package/lib/tab-pane.js +4 -4
  182. package/lib/table-column.js +840 -865
  183. package/lib/table.js +1825 -2000
  184. package/lib/tabs.js +846 -871
  185. package/lib/tag.js +2 -2
  186. package/lib/theme-chalk/fonts/iconfont.ttf +0 -0
  187. package/lib/theme-chalk/fonts/iconfont.woff +0 -0
  188. package/lib/theme-chalk/index.css +1 -1
  189. package/lib/theme-chalk/lowcode.css +1 -1
  190. package/lib/time-picker.js +6471 -6646
  191. package/lib/time-select.js +5039 -5214
  192. package/lib/timeline-item.js +2 -2
  193. package/lib/timeline.js +2 -2
  194. package/lib/tips.js +837 -862
  195. package/lib/toolbar.js +4 -4
  196. package/lib/tooltip.js +1813 -1988
  197. package/lib/transfer.js +837 -862
  198. package/lib/tree-group.js +853 -878
  199. package/lib/tree.js +1026 -1051
  200. package/lib/update-history.js +4 -4
  201. package/lib/upload.js +859 -884
  202. package/lib/wujie.js +841 -866
  203. package/package.json +1 -1
  204. package/packages/flow-group/src/main.vue +2 -2
  205. package/packages/form/src/form-item-render.vue +1 -0
  206. package/packages/form/src/form-item.vue +12 -6
  207. package/packages/form/src/form.vue +5 -5
  208. package/packages/login/src/login.vue +1 -0
  209. package/packages/lowcode/src/attribute/function.vue +28 -9
  210. package/packages/lowcode/src/attribute/props.vue +202 -0
  211. package/packages/lowcode/src/attribute/styles.vue +79 -5
  212. package/packages/lowcode/src/attribute.vue +61 -4
  213. package/packages/lowcode/src/canvas.vue +159 -2
  214. package/packages/lowcode/src/form-render.vue +305 -0
  215. package/packages/lowcode/src/lowcode.vue +33 -13
  216. package/packages/lowcode/src/modules.vue +53 -37
  217. package/packages/lowcode/src/render.vue +80 -25
  218. package/packages/lowcode/src/util/components.js +100 -0
  219. package/packages/lowcode/src/util/props-util.js +67 -0
  220. package/packages/lowcode/src/util/source-generator.js +69 -9
  221. package/packages/lowcode/src/util/source-parser.js +64 -10
  222. package/packages/lowcode-view/src/render.vue +48 -18
  223. package/packages/main/src/components/userinfo.vue +0 -1
  224. package/packages/menu/src/menu-item-group.vue +1 -1
  225. package/packages/menu/src/mixins.js +8 -4
  226. package/packages/menu/src/submenu.vue +35 -5
  227. package/packages/phone-login/src/phone-login.vue +5 -2
  228. package/packages/theme-chalk/dist/fonts/iconfont.ttf +0 -0
  229. package/packages/theme-chalk/dist/fonts/iconfont.woff +0 -0
  230. package/packages/theme-chalk/src/fonts/iconfont.ttf +0 -0
  231. package/packages/theme-chalk/src/fonts/iconfont.woff +0 -0
  232. package/packages/theme-chalk/src/lowcode.scss +21 -2
  233. package/src/index.js +336 -336
package/lib/switch.js CHANGED
@@ -82,7 +82,7 @@ module.exports =
82
82
  /******/
83
83
  /******/
84
84
  /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 259);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 266);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3561,7 +3561,7 @@ module.exports = require("vue");
3561
3561
 
3562
3562
  /***/ }),
3563
3563
 
3564
- /***/ 259:
3564
+ /***/ 266:
3565
3565
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3566
3566
 
3567
3567
  "use strict";
@@ -3688,7 +3688,7 @@ render._withStripped = true
3688
3688
  var emitter = __webpack_require__(15);
3689
3689
 
3690
3690
  // EXTERNAL MODULE: ./src/mixins/focus.js
3691
- var mixins_focus = __webpack_require__(84);
3691
+ var mixins_focus = __webpack_require__(86);
3692
3692
 
3693
3693
  // EXTERNAL MODULE: ./src/mixins/migrating.js
3694
3694
  var migrating = __webpack_require__(46);
@@ -4375,759 +4375,736 @@ function normalizeComponent(
4375
4375
  /* unused harmony export getSecond */
4376
4376
  /* unused harmony export getWeekday */
4377
4377
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
4378
- /* Modified from https://github.com/taylorhakes/fecha
4379
- *
4380
- * The MIT License (MIT)
4381
- *
4382
- * Copyright (c) 2015 Taylor Hakes
4383
- *
4384
- * Permission is hereby granted, free of charge, to any person obtaining a copy
4385
- * of this software and associated documentation files (the "Software"), to deal
4386
- * in the Software without restriction, including without limitation the rights
4387
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4388
- * copies of the Software, and to permit persons to whom the Software is
4389
- * furnished to do so, subject to the following conditions:
4390
- *
4391
- * The above copyright notice and this permission notice shall be included in all
4392
- * copies or substantial portions of the Software.
4393
- *
4394
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4395
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4396
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4397
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4398
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4399
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4400
- * SOFTWARE.
4401
- */
4402
-
4403
- /*eslint-disable*/
4404
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
4405
-
4406
-
4378
+
4379
+
4407
4380
  /**
4408
4381
  * Parse or format dates
4409
4382
  * @class fecha
4410
- */
4411
- const fecha = {};
4412
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4413
- const twoDigits = '\\d\\d?';
4414
- const threeDigits = '\\d{3}';
4415
- const fourDigits = '\\d{4}';
4416
- const word = '[^\\s]+';
4417
- const literal = /\[([^]*?)\]/gm;
4418
- const noop = function () {};
4419
-
4420
- function regexEscape(str) {
4421
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
4422
- }
4423
-
4424
- function shorten(arr, sLen) {
4425
- const newArr = [];
4426
- for (let i = 0, len = arr.length; i < len; i++) {
4427
- newArr.push(arr[i].substr(0, sLen));
4428
- }
4429
- return newArr;
4430
- }
4431
-
4432
- function monthUpdate() {
4433
- return function (d, v) {
4434
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
4435
- if (~index) {
4436
- d.month = index;
4437
- }
4438
- };
4439
- }
4440
-
4441
- function pad(val, len) {
4442
- val = String(val);
4443
- len = len || 2;
4444
- while (val.length < len) {
4445
- val = '0' + val;
4446
- }
4447
- return val;
4448
- }
4449
-
4450
- // 直接使用中文日期名称常量
4451
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
4452
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
4453
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
4454
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
4455
- const amPm = ['上午', '下午'];
4456
- const DoFn = function DoFn(D) {
4457
- return D + '日';
4458
- };
4459
-
4460
- const formatFlags = {
4461
- D: function(dateObj) {
4462
- return dateObj.getDay();
4463
- },
4464
- DD: function(dateObj) {
4465
- return pad(dateObj.getDay());
4466
- },
4467
- Do: function(dateObj) {
4468
- return DoFn(dateObj.getDate());
4469
- },
4470
- d: function(dateObj) {
4471
- return dateObj.getDate();
4472
- },
4473
- dd: function(dateObj) {
4474
- return pad(dateObj.getDate());
4475
- },
4476
- ddd: function(dateObj) {
4477
- return dayNamesShort[dateObj.getDay()];
4478
- },
4479
- dddd: function(dateObj) {
4480
- return dayNames[dateObj.getDay()];
4481
- },
4482
- M: function(dateObj) {
4483
- return dateObj.getMonth() + 1;
4484
- },
4485
- MM: function(dateObj) {
4486
- return pad(dateObj.getMonth() + 1);
4487
- },
4488
- MMM: function(dateObj) {
4489
- return monthNamesShort[dateObj.getMonth()];
4490
- },
4491
- MMMM: function(dateObj) {
4492
- return monthNames[dateObj.getMonth()];
4493
- },
4494
- yy: function(dateObj) {
4495
- return pad(String(dateObj.getFullYear()), 4).substr(2);
4496
- },
4497
- yyyy: function(dateObj) {
4498
- return pad(dateObj.getFullYear(), 4);
4499
- },
4500
- h: function(dateObj) {
4501
- return dateObj.getHours() % 12 || 12;
4502
- },
4503
- hh: function(dateObj) {
4504
- return pad(dateObj.getHours() % 12 || 12);
4505
- },
4506
- H: function(dateObj) {
4507
- return dateObj.getHours();
4508
- },
4509
- HH: function(dateObj) {
4510
- return pad(dateObj.getHours());
4511
- },
4512
- m: function(dateObj) {
4513
- return dateObj.getMinutes();
4514
- },
4515
- mm: function(dateObj) {
4516
- return pad(dateObj.getMinutes());
4517
- },
4518
- s: function(dateObj) {
4519
- return dateObj.getSeconds();
4520
- },
4521
- ss: function(dateObj) {
4522
- return pad(dateObj.getSeconds());
4523
- },
4524
- S: function(dateObj) {
4525
- return Math.round(dateObj.getMilliseconds() / 100);
4526
- },
4527
- SS: function(dateObj) {
4528
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
4529
- },
4530
- SSS: function(dateObj) {
4531
- return pad(dateObj.getMilliseconds(), 3);
4532
- },
4533
- a: function(dateObj) {
4534
- return dateObj.getHours() < 12 ? '上午' : '下午';
4535
- },
4536
- A: function(dateObj) {
4537
- return dateObj.getHours() < 12 ? '上午' : '下午';
4538
- },
4539
- ZZ: function(dateObj) {
4540
- const o = dateObj.getTimezoneOffset();
4541
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
4542
- }
4543
- };
4544
-
4545
- const parseFlags = {
4546
- d: [twoDigits, function (d, v) {
4547
- d.day = v;
4548
- }],
4549
- Do: [twoDigits + word, function (d, v) {
4550
- d.day = parseInt(v, 10);
4551
- }],
4552
- M: [twoDigits, function (d, v) {
4553
- d.month = v - 1;
4554
- }],
4555
- yy: [twoDigits, function (d, v) {
4556
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
4557
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
4558
- }],
4559
- h: [twoDigits, function (d, v) {
4560
- d.hour = v;
4561
- }],
4562
- m: [twoDigits, function (d, v) {
4563
- d.minute = v;
4564
- }],
4565
- s: [twoDigits, function (d, v) {
4566
- d.second = v;
4567
- }],
4568
- yyyy: [fourDigits, function (d, v) {
4569
- d.year = v;
4570
- }],
4571
- S: ['\\d', function (d, v) {
4572
- d.millisecond = v * 100;
4573
- }],
4574
- SS: ['\\d{2}', function (d, v) {
4575
- d.millisecond = v * 10;
4576
- }],
4577
- SSS: [threeDigits, function (d, v) {
4578
- d.millisecond = v;
4579
- }],
4580
- D: [twoDigits, noop],
4581
- ddd: [word, noop],
4582
- MMM: [word, monthUpdate('monthNamesShort')],
4583
- MMMM: [word, monthUpdate('monthNames')],
4584
- a: [word, function (d, v) {
4585
- const val = v.toLowerCase();
4586
- if (val === '上午') {
4587
- d.isPm = false;
4588
- } else if (val === '下午') {
4589
- d.isPm = true;
4590
- }
4591
- }],
4592
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
4593
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
4594
-
4595
- if (parts) {
4596
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
4597
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
4598
- }
4599
- }]
4600
- };
4601
- parseFlags.dd = parseFlags.d;
4602
- parseFlags.dddd = parseFlags.ddd;
4603
- parseFlags.DD = parseFlags.D;
4604
- parseFlags.mm = parseFlags.m;
4605
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
4606
- parseFlags.MM = parseFlags.M;
4607
- parseFlags.ss = parseFlags.s;
4608
- parseFlags.A = parseFlags.a;
4609
-
4610
-
4611
- // Some common format strings
4612
- fecha.masks = {
4613
- default: 'ddd MMM dd yyyy HH:mm:ss',
4614
- shortDate: 'M/D/yy',
4615
- mediumDate: 'MMM d, yyyy',
4616
- longDate: 'MMMM d, yyyy',
4617
- fullDate: 'dddd, MMMM d, yyyy',
4618
- shortTime: 'HH:mm',
4619
- mediumTime: 'HH:mm:ss',
4620
- longTime: 'HH:mm:ss.SSS'
4621
- };
4622
-
4383
+ */
4384
+ var fecha = {};
4385
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4386
+ var twoDigits = '\\d\\d?';
4387
+ var threeDigits = '\\d{3}';
4388
+ var fourDigits = '\\d{4}';
4389
+ var word = '[^\\s]+';
4390
+ var literal = /\[([^]*?)\]/gm;
4391
+ var noop = function noop() {};
4392
+
4393
+ function regexEscape(str) {
4394
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
4395
+ }
4396
+
4397
+ function shorten(arr, sLen) {
4398
+ var newArr = [];
4399
+ for (var i = 0, len = arr.length; i < len; i++) {
4400
+ newArr.push(arr[i].substr(0, sLen));
4401
+ }
4402
+ return newArr;
4403
+ }
4404
+
4405
+ function monthUpdate() {
4406
+ return function (d, v) {
4407
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
4408
+ if (~index) {
4409
+ d.month = index;
4410
+ }
4411
+ };
4412
+ }
4413
+
4414
+ function pad(val, len) {
4415
+ val = String(val);
4416
+ len = len || 2;
4417
+ while (val.length < len) {
4418
+ val = '0' + val;
4419
+ }
4420
+ return val;
4421
+ }
4422
+
4423
+ // 直接使用中文日期名称常量
4424
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
4425
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
4426
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
4427
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
4428
+ var amPm = ['上午', '下午'];
4429
+ var DoFn = function DoFn(D) {
4430
+ return D + '日';
4431
+ };
4432
+
4433
+ var formatFlags = {
4434
+ D: function D(dateObj) {
4435
+ return dateObj.getDay();
4436
+ },
4437
+ DD: function DD(dateObj) {
4438
+ return pad(dateObj.getDay());
4439
+ },
4440
+ Do: function Do(dateObj) {
4441
+ return DoFn(dateObj.getDate());
4442
+ },
4443
+ d: function d(dateObj) {
4444
+ return dateObj.getDate();
4445
+ },
4446
+ dd: function dd(dateObj) {
4447
+ return pad(dateObj.getDate());
4448
+ },
4449
+ ddd: function ddd(dateObj) {
4450
+ return dayNamesShort[dateObj.getDay()];
4451
+ },
4452
+ dddd: function dddd(dateObj) {
4453
+ return dayNames[dateObj.getDay()];
4454
+ },
4455
+ M: function M(dateObj) {
4456
+ return dateObj.getMonth() + 1;
4457
+ },
4458
+ MM: function MM(dateObj) {
4459
+ return pad(dateObj.getMonth() + 1);
4460
+ },
4461
+ MMM: function MMM(dateObj) {
4462
+ return monthNamesShort[dateObj.getMonth()];
4463
+ },
4464
+ MMMM: function MMMM(dateObj) {
4465
+ return monthNames[dateObj.getMonth()];
4466
+ },
4467
+ yy: function yy(dateObj) {
4468
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
4469
+ },
4470
+ yyyy: function yyyy(dateObj) {
4471
+ return pad(dateObj.getFullYear(), 4);
4472
+ },
4473
+ h: function h(dateObj) {
4474
+ return dateObj.getHours() % 12 || 12;
4475
+ },
4476
+ hh: function hh(dateObj) {
4477
+ return pad(dateObj.getHours() % 12 || 12);
4478
+ },
4479
+ H: function H(dateObj) {
4480
+ return dateObj.getHours();
4481
+ },
4482
+ HH: function HH(dateObj) {
4483
+ return pad(dateObj.getHours());
4484
+ },
4485
+ m: function m(dateObj) {
4486
+ return dateObj.getMinutes();
4487
+ },
4488
+ mm: function mm(dateObj) {
4489
+ return pad(dateObj.getMinutes());
4490
+ },
4491
+ s: function s(dateObj) {
4492
+ return dateObj.getSeconds();
4493
+ },
4494
+ ss: function ss(dateObj) {
4495
+ return pad(dateObj.getSeconds());
4496
+ },
4497
+ S: function S(dateObj) {
4498
+ return Math.round(dateObj.getMilliseconds() / 100);
4499
+ },
4500
+ SS: function SS(dateObj) {
4501
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
4502
+ },
4503
+ SSS: function SSS(dateObj) {
4504
+ return pad(dateObj.getMilliseconds(), 3);
4505
+ },
4506
+ a: function a(dateObj) {
4507
+ return dateObj.getHours() < 12 ? '上午' : '下午';
4508
+ },
4509
+ A: function A(dateObj) {
4510
+ return dateObj.getHours() < 12 ? '上午' : '下午';
4511
+ },
4512
+ ZZ: function ZZ(dateObj) {
4513
+ var o = dateObj.getTimezoneOffset();
4514
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
4515
+ }
4516
+ };
4517
+
4518
+ var parseFlags = {
4519
+ d: [twoDigits, function (d, v) {
4520
+ d.day = v;
4521
+ }],
4522
+ Do: [twoDigits + word, function (d, v) {
4523
+ d.day = parseInt(v, 10);
4524
+ }],
4525
+ M: [twoDigits, function (d, v) {
4526
+ d.month = v - 1;
4527
+ }],
4528
+ yy: [twoDigits, function (d, v) {
4529
+ var da = new Date(),
4530
+ cent = +('' + da.getFullYear()).substr(0, 2);
4531
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
4532
+ }],
4533
+ h: [twoDigits, function (d, v) {
4534
+ d.hour = v;
4535
+ }],
4536
+ m: [twoDigits, function (d, v) {
4537
+ d.minute = v;
4538
+ }],
4539
+ s: [twoDigits, function (d, v) {
4540
+ d.second = v;
4541
+ }],
4542
+ yyyy: [fourDigits, function (d, v) {
4543
+ d.year = v;
4544
+ }],
4545
+ S: ['\\d', function (d, v) {
4546
+ d.millisecond = v * 100;
4547
+ }],
4548
+ SS: ['\\d{2}', function (d, v) {
4549
+ d.millisecond = v * 10;
4550
+ }],
4551
+ SSS: [threeDigits, function (d, v) {
4552
+ d.millisecond = v;
4553
+ }],
4554
+ D: [twoDigits, noop],
4555
+ ddd: [word, noop],
4556
+ MMM: [word, monthUpdate('monthNamesShort')],
4557
+ MMMM: [word, monthUpdate('monthNames')],
4558
+ a: [word, function (d, v) {
4559
+ var val = v.toLowerCase();
4560
+ if (val === '上午') {
4561
+ d.isPm = false;
4562
+ } else if (val === '下午') {
4563
+ d.isPm = true;
4564
+ }
4565
+ }],
4566
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
4567
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
4568
+ minutes = void 0;
4569
+
4570
+ if (parts) {
4571
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
4572
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
4573
+ }
4574
+ }]
4575
+ };
4576
+ parseFlags.dd = parseFlags.d;
4577
+ parseFlags.dddd = parseFlags.ddd;
4578
+ parseFlags.DD = parseFlags.D;
4579
+ parseFlags.mm = parseFlags.m;
4580
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
4581
+ parseFlags.MM = parseFlags.M;
4582
+ parseFlags.ss = parseFlags.s;
4583
+ parseFlags.A = parseFlags.a;
4584
+
4585
+ // Some common format strings
4586
+ fecha.masks = {
4587
+ default: 'ddd MMM dd yyyy HH:mm:ss',
4588
+ shortDate: 'M/D/yy',
4589
+ mediumDate: 'MMM d, yyyy',
4590
+ longDate: 'MMMM d, yyyy',
4591
+ fullDate: 'dddd, MMMM d, yyyy',
4592
+ shortTime: 'HH:mm',
4593
+ mediumTime: 'HH:mm:ss',
4594
+ longTime: 'HH:mm:ss.SSS'
4595
+ };
4596
+
4623
4597
  /***
4624
4598
  * Format a date
4625
4599
  * @method format
4626
4600
  * @param {Date|number} dateObj
4627
4601
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
4628
- */
4629
- fecha.format = function (dateObj, mask) {
4630
- if (typeof dateObj === 'number') {
4631
- dateObj = new Date(dateObj);
4632
- }
4633
-
4634
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
4635
- throw new Error('Invalid Date in fecha.format');
4636
- }
4637
-
4638
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
4639
-
4640
- const literals = [];
4641
-
4642
- // Make literals inactive by replacing them with ??
4643
- mask = mask.replace(literal, function($0, $1) {
4644
- literals.push($1);
4645
- return '@@@';
4646
- });
4647
- // Apply formatting rules
4648
- mask = mask.replace(token, function ($0) {
4649
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
4650
- });
4651
- // Inline literal values back into the formatted value
4652
- return mask.replace(/@@@/g, function() {
4653
- return literals.shift();
4654
- });
4655
- };
4656
-
4602
+ */
4603
+ fecha.format = function (dateObj, mask) {
4604
+ if (typeof dateObj === 'number') {
4605
+ dateObj = new Date(dateObj);
4606
+ }
4607
+
4608
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
4609
+ throw new Error('Invalid Date in fecha.format');
4610
+ }
4611
+
4612
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
4613
+
4614
+ var literals = [];
4615
+
4616
+ // Make literals inactive by replacing them with ??
4617
+ mask = mask.replace(literal, function ($0, $1) {
4618
+ literals.push($1);
4619
+ return '@@@';
4620
+ });
4621
+ // Apply formatting rules
4622
+ mask = mask.replace(token, function ($0) {
4623
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
4624
+ });
4625
+ // Inline literal values back into the formatted value
4626
+ return mask.replace(/@@@/g, function () {
4627
+ return literals.shift();
4628
+ });
4629
+ };
4630
+
4657
4631
  /**
4658
4632
  * Parse a date string into an object, changes - into /
4659
4633
  * @method parse
4660
4634
  * @param {string} dateStr Date string
4661
4635
  * @param {string} format Date parse format
4662
4636
  * @returns {Date|boolean}
4663
- */
4664
- fecha.parse = function (dateStr, format) {
4665
- if (typeof format !== 'string') {
4666
- throw new Error('Invalid format in fecha.parse');
4667
- }
4668
-
4669
- format = fecha.masks[format] || format;
4670
-
4671
- // Avoid regular expression denial of service, fail early for really long strings
4672
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
4673
- if (dateStr.length > 1000) {
4674
- return null;
4675
- }
4676
-
4677
- const dateInfo = {};
4678
- const parseInfo = [];
4679
- const literals = [];
4680
- format = format.replace(literal, function($0, $1) {
4681
- literals.push($1);
4682
- return '@@@';
4683
- });
4684
- let newFormat = regexEscape(format).replace(token, function ($0) {
4685
- if (parseFlags[$0]) {
4686
- const info = parseFlags[$0];
4687
- parseInfo.push(info[1]);
4688
- return '(' + info[0] + ')';
4689
- }
4690
-
4691
- return $0;
4692
- });
4693
- newFormat = newFormat.replace(/@@@/g, function() {
4694
- return literals.shift();
4695
- });
4696
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
4697
- if (!matches) {
4698
- return null;
4699
- }
4700
-
4701
- for (let i = 1; i < matches.length; i++) {
4702
- parseInfo[i - 1](dateInfo, matches[i]);
4703
- }
4704
-
4705
- const today = new Date();
4706
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
4707
- dateInfo.hour = +dateInfo.hour + 12;
4708
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
4709
- dateInfo.hour = 0;
4710
- }
4711
-
4712
- let date;
4713
- if (dateInfo.timezoneOffset != null) {
4714
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
4715
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
4716
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
4717
- } else {
4718
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
4719
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
4720
- }
4721
- return date;
4722
- };
4723
-
4724
- // 导出fecha对象
4725
-
4726
-
4727
- // 以下是从date-util.js合并的函数
4728
- const newArray = function(start, end) {
4729
- let result = [];
4730
- for (let i = start; i <= end; i++) {
4731
- result.push(i);
4732
- }
4733
- return result;
4734
- };
4735
-
4736
- const getSettings = () => {
4737
- return {
4738
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
4739
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
4740
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
4741
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
4742
- amPm: ['上午', '下午']
4743
- };
4744
- };
4745
-
4746
- const toDate = function(date) {
4747
- return isDate(date) ? new Date(date) : null;
4748
- };
4749
-
4750
- const isDate = function(date) {
4751
- if (date === null || date === undefined) return false;
4752
- if (isNaN(new Date(date).getTime())) return false;
4753
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
4754
- return true;
4755
- };
4756
-
4757
- const isDateObject = function(val) {
4758
- return val instanceof Date;
4759
- };
4760
-
4761
- const formatDate = function (date, format = 'yyyy-MM-dd') {
4762
- // 处理多种输入类型
4763
- if (!date) return '';
4764
-
4765
- // 如果是时间戳,转成日期对象
4766
- if (typeof date === 'number') {
4767
- date = new Date(date);
4768
- }
4769
- // 如果是字符串,转成日期对象
4770
- if (typeof date === 'string') {
4771
- date = new Date(date);
4772
- }
4773
-
4774
- // 调用toDate进一步验证和转换
4775
- date = toDate(date);
4776
- if (!date) return '';
4777
-
4778
- // 兼容大写和小写的格式标记
4779
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
4780
- const lowercaseFormat = format
4781
- .replace(/YYYY/g, 'yyyy')
4782
- .replace(/D/g, 'd')
4783
-
4784
- // 使用fecha库进行格式化,支持中文配置
4785
- const str = fecha.format(date, lowercaseFormat, getSettings());
4786
- return str;
4787
- };
4788
-
4789
- const parseDate = function(string, format) {
4790
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
4791
- };
4792
-
4793
- const getDayCountOfMonth = function(year, month) {
4794
- if (month === 3 || month === 5 || month === 8 || month === 10) {
4795
- return 30;
4796
- }
4797
-
4798
- if (month === 1) {
4799
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
4800
- return 29;
4801
- } else {
4802
- return 28;
4803
- }
4804
- }
4805
-
4806
- return 31;
4807
- };
4808
-
4809
- const getDayCountOfYear = function(year) {
4810
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
4811
- return isLeapYear ? 366 : 365;
4812
- };
4813
-
4814
- const getFirstDayOfMonth = function(date) {
4815
- const temp = new Date(date.getTime());
4816
- temp.setDate(1);
4817
- return temp.getDay();
4818
- };
4819
-
4820
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
4821
- // {prev, next} Date should work for Daylight Saving Time
4822
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
4823
- const prevDate = function(date, amount = 1) {
4824
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
4825
- };
4826
-
4827
- const nextDate = function(date, amount = 1) {
4828
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
4829
- };
4830
-
4831
- const getStartDateOfMonth = function(year, month) {
4832
- const result = new Date(year, month, 1);
4833
- const day = result.getDay();
4834
-
4835
- if (day === 0) {
4836
- return prevDate(result, 7);
4837
- } else {
4838
- return prevDate(result, day);
4839
- }
4840
- };
4841
-
4842
- const getWeekNumber = function(date) {
4843
- // 支持多种输入类型
4844
- if (!date||!isDate(date)) {
4845
- date = new Date();
4846
- }
4847
- if (typeof date === 'string') {
4848
- date = new Date(date);
4849
- }
4850
-
4851
- // 验证日期有效性
4852
- if (!isDate(date)) return null;
4853
-
4854
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
4855
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
4856
- // 将星期日的星期数设为7
4857
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
4858
- // 获取当年的第一天
4859
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
4860
- // 计算到最近的星期四的完整周数
4861
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
4862
- // 返回周数
4863
- return weekNo;
4864
- };
4865
-
4866
- const getRangeHours = function(ranges) {
4867
- const hours = [];
4868
- let disabledHours = [];
4869
-
4870
- (ranges || []).forEach(range => {
4871
- const value = range.map(date => date.getHours());
4872
-
4873
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
4874
- });
4875
-
4876
- if (disabledHours.length) {
4877
- for (let i = 0; i < 24; i++) {
4878
- hours[i] = disabledHours.indexOf(i) === -1;
4879
- }
4880
- } else {
4881
- for (let i = 0; i < 24; i++) {
4882
- hours[i] = false;
4883
- }
4884
- }
4885
-
4886
- return hours;
4887
- };
4888
-
4889
- const getPrevMonthLastDays = (date, amount) => {
4890
- if (amount <= 0) return [];
4891
- const temp = new Date(date.getTime());
4892
- temp.setDate(0);
4893
- const lastDay = temp.getDate();
4894
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
4895
- };
4896
-
4897
- const getMonthDays = (date) => {
4898
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
4899
- const days = temp.getDate();
4900
- return range(days).map((_, index) => index + 1);
4901
- };
4902
-
4903
- function setRangeData(arr, start, end, value) {
4904
- for (let i = start; i < end; i++) {
4905
- arr[i] = value;
4906
- }
4907
- }
4908
-
4909
- const getRangeMinutes = function(ranges, hour) {
4910
- const minutes = new Array(60);
4911
-
4912
- if (ranges.length > 0) {
4913
- ranges.forEach(range => {
4914
- const start = range[0];
4915
- const end = range[1];
4916
- const startHour = start.getHours();
4917
- const startMinute = start.getMinutes();
4918
- const endHour = end.getHours();
4919
- const endMinute = end.getMinutes();
4920
- if (startHour === hour && endHour !== hour) {
4921
- setRangeData(minutes, startMinute, 60, true);
4922
- } else if (startHour === hour && endHour === hour) {
4923
- setRangeData(minutes, startMinute, endMinute + 1, true);
4924
- } else if (startHour !== hour && endHour === hour) {
4925
- setRangeData(minutes, 0, endMinute + 1, true);
4926
- } else if (startHour < hour && endHour > hour) {
4927
- setRangeData(minutes, 0, 60, true);
4928
- }
4929
- });
4930
- } else {
4931
- setRangeData(minutes, 0, 60, true);
4932
- }
4933
- return minutes;
4934
- };
4935
-
4936
- const range = function(n) {
4937
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
4938
- return Array.apply(null, {length: n}).map((_, n) => n);
4939
- };
4940
-
4941
- const modifyDate = function(date, y, m, d) {
4942
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
4943
- };
4944
-
4945
- const modifyTime = function(date, h, m, s) {
4946
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
4947
- };
4948
-
4949
- const modifyWithTimeString = (date, time) => {
4950
- if (date == null || !time) {
4951
- return date;
4952
- }
4953
- time = parseDate(time, 'HH:mm:ss');
4954
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
4955
- };
4956
-
4957
- const clearTime = function(date) {
4958
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
4959
- };
4960
-
4961
- const clearMilliseconds = function(date) {
4962
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
4963
- };
4964
-
4965
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
4966
- // TODO: refactory a more elegant solution
4967
- if (ranges.length === 0) return date;
4968
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
4969
- const ndate = normalizeDate(date);
4970
- const nranges = ranges.map(range => range.map(normalizeDate));
4971
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
4972
-
4973
- let minDate = nranges[0][0];
4974
- let maxDate = nranges[0][0];
4975
-
4976
- nranges.forEach(nrange => {
4977
- minDate = new Date(Math.min(nrange[0], minDate));
4978
- maxDate = new Date(Math.max(nrange[1], minDate));
4979
- });
4980
-
4981
- const ret = ndate < minDate ? minDate : maxDate;
4982
- // preserve Year/Month/Date
4983
- return modifyDate(
4984
- ret,
4985
- date.getFullYear(),
4986
- date.getMonth(),
4987
- date.getDate()
4988
- );
4989
- };
4990
-
4991
- const timeWithinRange = function(date, selectableRange, format) {
4992
- const limitedDate = limitTimeRange(date, selectableRange, format);
4993
- return limitedDate.getTime() === date.getTime();
4994
- };
4995
-
4996
- const changeYearMonthAndClampDate = function(date, year, month) {
4997
- // clamp date to the number of days in `year`, `month`
4998
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
4999
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5000
- return modifyDate(date, year, month, monthDate);
5001
- };
5002
-
5003
- const prevMonth = function(date) {
5004
- const year = date.getFullYear();
5005
- const month = date.getMonth();
5006
- return month === 0
5007
- ? changeYearMonthAndClampDate(date, year - 1, 11)
5008
- : changeYearMonthAndClampDate(date, year, month - 1);
5009
- };
5010
-
5011
- const nextMonth = function(date) {
5012
- const year = date.getFullYear();
5013
- const month = date.getMonth();
5014
- return month === 11
5015
- ? changeYearMonthAndClampDate(date, year + 1, 0)
5016
- : changeYearMonthAndClampDate(date, year, month + 1);
5017
- };
5018
-
5019
- const prevYear = function(date, amount = 1) {
5020
- const year = date.getFullYear();
5021
- const month = date.getMonth();
5022
- return changeYearMonthAndClampDate(date, year - amount, month);
5023
- };
5024
-
5025
- const nextYear = function(date, amount = 1) {
5026
- const year = date.getFullYear();
5027
- const month = date.getMonth();
5028
- return changeYearMonthAndClampDate(date, year + amount, month);
5029
- };
5030
-
5031
- const extractDateFormat = function(format) {
5032
- return format
5033
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
5034
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
5035
- .trim();
5036
- };
5037
-
5038
- const extractTimeFormat = function(format) {
5039
- return format
5040
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
5041
- .trim();
5042
- };
5043
-
5044
- const validateRangeInOneMonth = function(start, end) {
5045
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
5046
- };
5047
-
4637
+ */
4638
+ fecha.parse = function (dateStr, format) {
4639
+ if (typeof format !== 'string') {
4640
+ throw new Error('Invalid format in fecha.parse');
4641
+ }
4642
+
4643
+ format = fecha.masks[format] || format;
4644
+
4645
+ // Avoid regular expression denial of service, fail early for really long strings
4646
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
4647
+ if (dateStr.length > 1000) {
4648
+ return null;
4649
+ }
4650
+
4651
+ var dateInfo = {};
4652
+ var parseInfo = [];
4653
+ var literals = [];
4654
+ format = format.replace(literal, function ($0, $1) {
4655
+ literals.push($1);
4656
+ return '@@@';
4657
+ });
4658
+ var newFormat = regexEscape(format).replace(token, function ($0) {
4659
+ if (parseFlags[$0]) {
4660
+ var info = parseFlags[$0];
4661
+ parseInfo.push(info[1]);
4662
+ return '(' + info[0] + ')';
4663
+ }
4664
+
4665
+ return $0;
4666
+ });
4667
+ newFormat = newFormat.replace(/@@@/g, function () {
4668
+ return literals.shift();
4669
+ });
4670
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
4671
+ if (!matches) {
4672
+ return null;
4673
+ }
4674
+
4675
+ for (var i = 1; i < matches.length; i++) {
4676
+ parseInfo[i - 1](dateInfo, matches[i]);
4677
+ }
4678
+
4679
+ var today = new Date();
4680
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
4681
+ dateInfo.hour = +dateInfo.hour + 12;
4682
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
4683
+ dateInfo.hour = 0;
4684
+ }
4685
+
4686
+ var date = void 0;
4687
+ if (dateInfo.timezoneOffset != null) {
4688
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
4689
+ date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
4690
+ } else {
4691
+ date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
4692
+ }
4693
+ return date;
4694
+ };
4695
+
4696
+ // 导出fecha对象
4697
+
4698
+
4699
+ // 以下是从date-util.js合并的函数
4700
+ var newArray = function newArray(start, end) {
4701
+ var result = [];
4702
+ for (var i = start; i <= end; i++) {
4703
+ result.push(i);
4704
+ }
4705
+ return result;
4706
+ };
4707
+
4708
+ var getSettings = function getSettings() {
4709
+ return {
4710
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
4711
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
4712
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
4713
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
4714
+ amPm: ['上午', '下午']
4715
+ };
4716
+ };
4717
+
4718
+ var toDate = function toDate(date) {
4719
+ return isDate(date) ? new Date(date) : null;
4720
+ };
4721
+
4722
+ var isDate = function isDate(date) {
4723
+ if (date === null || date === undefined) return false;
4724
+ if (isNaN(new Date(date).getTime())) return false;
4725
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
4726
+ return true;
4727
+ };
4728
+
4729
+ var isDateObject = function isDateObject(val) {
4730
+ return val instanceof Date;
4731
+ };
4732
+
4733
+ var formatDate = function formatDate(date) {
4734
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
4735
+
4736
+ // 处理多种输入类型
4737
+ if (!date) return '';
4738
+
4739
+ // 如果是时间戳,转成日期对象
4740
+ if (typeof date === 'number') {
4741
+ date = new Date(date);
4742
+ }
4743
+ // 如果是字符串,转成日期对象
4744
+ if (typeof date === 'string') {
4745
+ date = new Date(date);
4746
+ }
4747
+
4748
+ // 调用toDate进一步验证和转换
4749
+ date = toDate(date);
4750
+ if (!date) return '';
4751
+
4752
+ // 兼容大写和小写的格式标记
4753
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
4754
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
4755
+
4756
+ // 使用fecha库进行格式化,支持中文配置
4757
+ var str = fecha.format(date, lowercaseFormat, getSettings());
4758
+ return str;
4759
+ };
4760
+
4761
+ var parseDate = function parseDate(string, format) {
4762
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
4763
+ };
4764
+
4765
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
4766
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
4767
+ return 30;
4768
+ }
4769
+
4770
+ if (month === 1) {
4771
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
4772
+ return 29;
4773
+ } else {
4774
+ return 28;
4775
+ }
4776
+ }
4777
+
4778
+ return 31;
4779
+ };
4780
+
4781
+ var getDayCountOfYear = function getDayCountOfYear(year) {
4782
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
4783
+ return isLeapYear ? 366 : 365;
4784
+ };
4785
+
4786
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
4787
+ var temp = new Date(date.getTime());
4788
+ temp.setDate(1);
4789
+ return temp.getDay();
4790
+ };
4791
+
4792
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
4793
+ // {prev, next} Date should work for Daylight Saving Time
4794
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
4795
+ var prevDate = function prevDate(date) {
4796
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
4797
+
4798
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
4799
+ };
4800
+
4801
+ var nextDate = function nextDate(date) {
4802
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
4803
+
4804
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
4805
+ };
4806
+
4807
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
4808
+ var result = new Date(year, month, 1);
4809
+ var day = result.getDay();
4810
+
4811
+ if (day === 0) {
4812
+ return prevDate(result, 7);
4813
+ } else {
4814
+ return prevDate(result, day);
4815
+ }
4816
+ };
4817
+
4818
+ var getWeekNumber = function getWeekNumber(date) {
4819
+ // 支持多种输入类型
4820
+ if (!date || !isDate(date)) {
4821
+ date = new Date();
4822
+ }
4823
+ if (typeof date === 'string') {
4824
+ date = new Date(date);
4825
+ }
4826
+
4827
+ // 验证日期有效性
4828
+ if (!isDate(date)) return null;
4829
+
4830
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
4831
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
4832
+ // 将星期日的星期数设为7
4833
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
4834
+ // 获取当年的第一天
4835
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
4836
+ // 计算到最近的星期四的完整周数
4837
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
4838
+ // 返回周数
4839
+ return weekNo;
4840
+ };
4841
+
4842
+ var getRangeHours = function getRangeHours(ranges) {
4843
+ var hours = [];
4844
+ var disabledHours = [];
4845
+
4846
+ (ranges || []).forEach(function (range) {
4847
+ var value = range.map(function (date) {
4848
+ return date.getHours();
4849
+ });
4850
+
4851
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
4852
+ });
4853
+
4854
+ if (disabledHours.length) {
4855
+ for (var i = 0; i < 24; i++) {
4856
+ hours[i] = disabledHours.indexOf(i) === -1;
4857
+ }
4858
+ } else {
4859
+ for (var _i = 0; _i < 24; _i++) {
4860
+ hours[_i] = false;
4861
+ }
4862
+ }
4863
+
4864
+ return hours;
4865
+ };
4866
+
4867
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
4868
+ if (amount <= 0) return [];
4869
+ var temp = new Date(date.getTime());
4870
+ temp.setDate(0);
4871
+ var lastDay = temp.getDate();
4872
+ return range(amount).map(function (_, index) {
4873
+ return lastDay - (amount - index - 1);
4874
+ });
4875
+ };
4876
+
4877
+ var getMonthDays = function getMonthDays(date) {
4878
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
4879
+ var days = temp.getDate();
4880
+ return range(days).map(function (_, index) {
4881
+ return index + 1;
4882
+ });
4883
+ };
4884
+
4885
+ function setRangeData(arr, start, end, value) {
4886
+ for (var i = start; i < end; i++) {
4887
+ arr[i] = value;
4888
+ }
4889
+ }
4890
+
4891
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
4892
+ var minutes = new Array(60);
4893
+
4894
+ if (ranges.length > 0) {
4895
+ ranges.forEach(function (range) {
4896
+ var start = range[0];
4897
+ var end = range[1];
4898
+ var startHour = start.getHours();
4899
+ var startMinute = start.getMinutes();
4900
+ var endHour = end.getHours();
4901
+ var endMinute = end.getMinutes();
4902
+ if (startHour === hour && endHour !== hour) {
4903
+ setRangeData(minutes, startMinute, 60, true);
4904
+ } else if (startHour === hour && endHour === hour) {
4905
+ setRangeData(minutes, startMinute, endMinute + 1, true);
4906
+ } else if (startHour !== hour && endHour === hour) {
4907
+ setRangeData(minutes, 0, endMinute + 1, true);
4908
+ } else if (startHour < hour && endHour > hour) {
4909
+ setRangeData(minutes, 0, 60, true);
4910
+ }
4911
+ });
4912
+ } else {
4913
+ setRangeData(minutes, 0, 60, true);
4914
+ }
4915
+ return minutes;
4916
+ };
4917
+
4918
+ var range = function range(n) {
4919
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
4920
+ return Array.apply(null, { length: n }).map(function (_, n) {
4921
+ return n;
4922
+ });
4923
+ };
4924
+
4925
+ var modifyDate = function modifyDate(date, y, m, d) {
4926
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
4927
+ };
4928
+
4929
+ var modifyTime = function modifyTime(date, h, m, s) {
4930
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
4931
+ };
4932
+
4933
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
4934
+ if (date == null || !time) {
4935
+ return date;
4936
+ }
4937
+ time = parseDate(time, 'HH:mm:ss');
4938
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
4939
+ };
4940
+
4941
+ var clearTime = function clearTime(date) {
4942
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
4943
+ };
4944
+
4945
+ var clearMilliseconds = function clearMilliseconds(date) {
4946
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
4947
+ };
4948
+
4949
+ var limitTimeRange = function limitTimeRange(date, ranges) {
4950
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
4951
+
4952
+ // TODO: refactory a more elegant solution
4953
+ if (ranges.length === 0) return date;
4954
+ var normalizeDate = function normalizeDate(date) {
4955
+ return fecha.parse(fecha.format(date, format), format);
4956
+ };
4957
+ var ndate = normalizeDate(date);
4958
+ var nranges = ranges.map(function (range) {
4959
+ return range.map(normalizeDate);
4960
+ });
4961
+ if (nranges.some(function (nrange) {
4962
+ return ndate >= nrange[0] && ndate <= nrange[1];
4963
+ })) return date;
4964
+
4965
+ var minDate = nranges[0][0];
4966
+ var maxDate = nranges[0][0];
4967
+
4968
+ nranges.forEach(function (nrange) {
4969
+ minDate = new Date(Math.min(nrange[0], minDate));
4970
+ maxDate = new Date(Math.max(nrange[1], minDate));
4971
+ });
4972
+
4973
+ var ret = ndate < minDate ? minDate : maxDate;
4974
+ // preserve Year/Month/Date
4975
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
4976
+ };
4977
+
4978
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
4979
+ var limitedDate = limitTimeRange(date, selectableRange, format);
4980
+ return limitedDate.getTime() === date.getTime();
4981
+ };
4982
+
4983
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
4984
+ // clamp date to the number of days in `year`, `month`
4985
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
4986
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
4987
+ return modifyDate(date, year, month, monthDate);
4988
+ };
4989
+
4990
+ var prevMonth = function prevMonth(date) {
4991
+ var year = date.getFullYear();
4992
+ var month = date.getMonth();
4993
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
4994
+ };
4995
+
4996
+ var nextMonth = function nextMonth(date) {
4997
+ var year = date.getFullYear();
4998
+ var month = date.getMonth();
4999
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
5000
+ };
5001
+
5002
+ var prevYear = function prevYear(date) {
5003
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5004
+
5005
+ var year = date.getFullYear();
5006
+ var month = date.getMonth();
5007
+ return changeYearMonthAndClampDate(date, year - amount, month);
5008
+ };
5009
+
5010
+ var nextYear = function nextYear(date) {
5011
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5012
+
5013
+ var year = date.getFullYear();
5014
+ var month = date.getMonth();
5015
+ return changeYearMonthAndClampDate(date, year + amount, month);
5016
+ };
5017
+
5018
+ var extractDateFormat = function extractDateFormat(format) {
5019
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
5020
+ };
5021
+
5022
+ var extractTimeFormat = function extractTimeFormat(format) {
5023
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
5024
+ };
5025
+
5026
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
5027
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
5028
+ };
5029
+
5048
5030
  /**
5049
5031
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
5050
5032
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
5051
5033
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
5052
5034
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
5053
5035
  * @returns {number} 工作日数量
5054
- */
5055
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
5056
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5057
- throw new Error(
5058
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
5059
- );
5060
- }
5061
-
5062
- const startDateObj = new Date(start_date);
5063
- const endDateObj = new Date(end_date);
5064
-
5065
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5066
- throw new Error(
5067
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
5068
- );
5069
- }
5070
-
5071
- if (startDateObj > endDateObj) {
5072
- throw new Error('Start date should be earlier than or equal to end date.');
5073
- }
5074
-
5075
- let workdays = 0;
5076
-
5077
- // Iterate through each day in the date range
5078
- for (
5079
- let currentDate = new Date(startDateObj);
5080
- currentDate <= endDateObj;
5081
- currentDate.setDate(currentDate.getDate() + 1)
5082
- ) {
5083
- // Check if the current day is a weekend (Saturday or Sunday)
5084
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5085
-
5086
- // Check if the current day is a holiday
5087
- const isHoliday = holidays.some((holiday) => {
5088
- const holidayDate = new Date(holiday);
5089
- return currentDate.toDateString() === holidayDate.toDateString();
5090
- });
5091
-
5092
- // If it's a workday (not a weekend or holiday), increment the workdays count
5093
- if (!isWeekend && !isHoliday) {
5094
- workdays++;
5095
- }
5096
- }
5097
-
5098
- return workdays;
5099
- };
5100
-
5036
+ */
5037
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
5038
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5039
+
5040
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5041
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5042
+ }
5043
+
5044
+ var startDateObj = new Date(start_date);
5045
+ var endDateObj = new Date(end_date);
5046
+
5047
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5048
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5049
+ }
5050
+
5051
+ if (startDateObj > endDateObj) {
5052
+ throw new Error('Start date should be earlier than or equal to end date.');
5053
+ }
5054
+
5055
+ var workdays = 0;
5056
+
5057
+ // Iterate through each day in the date range
5058
+
5059
+ var _loop = function _loop(currentDate) {
5060
+ // Check if the current day is a weekend (Saturday or Sunday)
5061
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5062
+
5063
+ // Check if the current day is a holiday
5064
+ var isHoliday = holidays.some(function (holiday) {
5065
+ var holidayDate = new Date(holiday);
5066
+ return currentDate.toDateString() === holidayDate.toDateString();
5067
+ });
5068
+
5069
+ // If it's a workday (not a weekend or holiday), increment the workdays count
5070
+ if (!isWeekend && !isHoliday) {
5071
+ workdays++;
5072
+ }
5073
+ };
5074
+
5075
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
5076
+ _loop(currentDate);
5077
+ }
5078
+
5079
+ return workdays;
5080
+ };
5081
+
5101
5082
  /**
5102
5083
  * 日期加减天数
5103
5084
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
5104
5085
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
5105
5086
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
5106
- */
5107
- const dateAddDays = function (start_date, days) {
5108
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5109
- throw new Error(
5110
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
5111
- );
5112
- }
5113
-
5114
- const startDateObj = new Date(start_date);
5115
- if (isNaN(startDateObj.getTime())) {
5116
- throw new Error(
5117
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5118
- );
5119
- }
5120
-
5121
- const resultDateObj = new Date(startDateObj);
5122
- resultDateObj.setDate(resultDateObj.getDate() + days);
5123
-
5124
- const resultYear = resultDateObj.getFullYear();
5125
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5126
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5127
-
5128
- return `${resultYear}-${resultMonth}-${resultDay}`;
5129
- };
5130
-
5087
+ */
5088
+ var dateAddDays = function dateAddDays(start_date, days) {
5089
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5090
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days.");
5091
+ }
5092
+
5093
+ var startDateObj = new Date(start_date);
5094
+ if (isNaN(startDateObj.getTime())) {
5095
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5096
+ }
5097
+
5098
+ var resultDateObj = new Date(startDateObj);
5099
+ resultDateObj.setDate(resultDateObj.getDate() + days);
5100
+
5101
+ var resultYear = resultDateObj.getFullYear();
5102
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5103
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5104
+
5105
+ return resultYear + '-' + resultMonth + '-' + resultDay;
5106
+ };
5107
+
5131
5108
  /**
5132
5109
  * 计算两个日期之间的差值
5133
5110
  * @date 2023年12月14日
@@ -5135,182 +5112,180 @@ const dateAddDays = function (start_date, days) {
5135
5112
  * @param {String} end_date - 结束日期字符串
5136
5113
  * @param {String} unit - 单位:year/month/day
5137
5114
  * @returns {Number} 差值
5138
- */
5139
- const dateDiff = function (start_date, end_date, unit = 'day') {
5140
- // Assuming date strings are in "YYYY-MM-DD" format
5141
- var startDate = new Date(start_date);
5142
- var endDate = new Date(end_date);
5143
-
5144
- // If the date is invalid, return 0
5145
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5146
- return 0;
5147
- }
5148
-
5149
- if (unit === 'year') {
5150
- return endDate.getFullYear() - startDate.getFullYear();
5151
- } else if (unit === 'month') {
5152
- return (
5153
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
5154
- (endDate.getMonth() - startDate.getMonth())
5155
- );
5156
- } else {
5157
- // Default to day
5158
- var timeDifference = endDate - startDate;
5159
- // Calculate days (86400000 milliseconds per day)
5160
- return Math.floor(timeDifference / 86400000);
5161
- }
5162
- };
5163
-
5115
+ */
5116
+ var dateDiff = function dateDiff(start_date, end_date) {
5117
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
5118
+
5119
+ // Assuming date strings are in "YYYY-MM-DD" format
5120
+ var startDate = new Date(start_date);
5121
+ var endDate = new Date(end_date);
5122
+
5123
+ // If the date is invalid, return 0
5124
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5125
+ return 0;
5126
+ }
5127
+
5128
+ if (unit === 'year') {
5129
+ return endDate.getFullYear() - startDate.getFullYear();
5130
+ } else if (unit === 'month') {
5131
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
5132
+ } else {
5133
+ // Default to day
5134
+ var timeDifference = endDate - startDate;
5135
+ // Calculate days (86400000 milliseconds per day)
5136
+ return Math.floor(timeDifference / 86400000);
5137
+ }
5138
+ };
5139
+
5164
5140
  /**
5165
5141
  * 获取月份中的日期
5166
5142
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
5167
5143
  * @returns {number} 月份中的日期(1-31)
5168
- */
5169
- const dayOfMonth = function (date) {
5170
- if (typeof date !== 'string') {
5171
- throw new Error(
5172
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
5173
- );
5174
- }
5175
-
5176
- const dateObj = new Date(date);
5177
- if (isNaN(dateObj.getTime())) {
5178
- throw new Error(
5179
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5180
- );
5181
- }
5182
-
5183
- return dateObj.getDate();
5184
- };
5185
-
5144
+ */
5145
+ var dayOfMonth = function dayOfMonth(date) {
5146
+ if (typeof date !== 'string') {
5147
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5148
+ }
5149
+
5150
+ var dateObj = new Date(date);
5151
+ if (isNaN(dateObj.getTime())) {
5152
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5153
+ }
5154
+
5155
+ return dateObj.getDate();
5156
+ };
5157
+
5186
5158
  /**
5187
5159
  * 获取当前日期
5188
5160
  * @date 2022年5月7日
5189
5161
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
5190
5162
  * @returns {string} 当前日期的格式化字符串
5191
- */
5192
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
5193
- return formatDate(new Date(), format);
5194
- };
5195
-
5163
+ */
5164
+ var getCurrentDate = function getCurrentDate() {
5165
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
5166
+
5167
+ return formatDate(new Date(), format);
5168
+ };
5169
+
5196
5170
  /**
5197
5171
  * 获取当前日期时间
5198
5172
  * @date 2022年5月7日
5199
5173
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
5200
5174
  * @returns {string} 当前日期时间的格式化字符串
5201
- */
5202
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
5203
- return formatDate(new Date(), format);
5204
- };
5205
-
5175
+ */
5176
+ var getCurrentDateTime = function getCurrentDateTime() {
5177
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
5178
+
5179
+ return formatDate(new Date(), format);
5180
+ };
5181
+
5206
5182
  /**
5207
5183
  * 获取小时
5208
5184
  * @date 2022年5月7日
5209
5185
  * @param {Date|string} [date] - 日期对象或日期字符串
5210
5186
  * @returns {number} 小时数(0-23)
5211
- */
5212
- const getHour = function (date) {
5213
- if (!date) {
5214
- return new Date().getHours();
5215
- }
5216
- if (typeof date === 'string') {
5217
- date = new Date(date);
5218
- }
5219
- return date.getHours();
5220
- };
5221
-
5187
+ */
5188
+ var getHour = function getHour(date) {
5189
+ if (!date) {
5190
+ return new Date().getHours();
5191
+ }
5192
+ if (typeof date === 'string') {
5193
+ date = new Date(date);
5194
+ }
5195
+ return date.getHours();
5196
+ };
5197
+
5222
5198
  /**
5223
5199
  * 获取分钟
5224
5200
  * @date 2022年5月7日
5225
5201
  * @param {Date|string} [date] - 日期对象或日期字符串
5226
5202
  * @returns {number} 分钟数(0-59)
5227
- */
5228
- const getMinute = function (date) {
5229
- if (!date) {
5230
- return new Date().getMinutes();
5231
- }
5232
- if (typeof date === 'string') {
5233
- date = new Date(date);
5234
- }
5235
- return date.getMinutes();
5236
- };
5237
-
5203
+ */
5204
+ var getMinute = function getMinute(date) {
5205
+ if (!date) {
5206
+ return new Date().getMinutes();
5207
+ }
5208
+ if (typeof date === 'string') {
5209
+ date = new Date(date);
5210
+ }
5211
+ return date.getMinutes();
5212
+ };
5213
+
5238
5214
  /**
5239
5215
  * 获取月份
5240
5216
  * @date 2022年5月7日
5241
5217
  * @param {Date|string} [date] - 日期对象或日期字符串
5242
5218
  * @returns {number} 月份数(1-12)
5243
- */
5244
- const getMonth = function (date) {
5245
- if (!date) {
5246
- return new Date().getMonth() + 1;
5247
- }
5248
- if (typeof date === 'string') {
5249
- date = new Date(date);
5250
- }
5251
- return date.getMonth() + 1;
5252
- };
5253
-
5219
+ */
5220
+ var getMonth = function getMonth(date) {
5221
+ if (!date) {
5222
+ return new Date().getMonth() + 1;
5223
+ }
5224
+ if (typeof date === 'string') {
5225
+ date = new Date(date);
5226
+ }
5227
+ return date.getMonth() + 1;
5228
+ };
5229
+
5254
5230
  /**
5255
5231
  * 获取秒
5256
5232
  * @date 2022年5月7日
5257
5233
  * @param {Date|string} [date] - 日期对象或日期字符串
5258
5234
  * @returns {number} 秒数(0-59)
5259
- */
5260
- const getSecond = function (date) {
5261
- if (!date) {
5262
- return new Date().getSeconds();
5263
- }
5264
- if (typeof date === 'string') {
5265
- date = new Date(date);
5266
- }
5267
- return date.getSeconds();
5268
- };
5269
-
5235
+ */
5236
+ var getSecond = function getSecond(date) {
5237
+ if (!date) {
5238
+ return new Date().getSeconds();
5239
+ }
5240
+ if (typeof date === 'string') {
5241
+ date = new Date(date);
5242
+ }
5243
+ return date.getSeconds();
5244
+ };
5245
+
5270
5246
  /**
5271
5247
  * 获取星期几
5272
5248
  * @date 2022年5月7日
5273
5249
  * @param {Date|string} [date] - 日期对象或日期字符串
5274
5250
  * @returns {number} 星期几(0-6,0表示星期日)
5275
- */
5276
- const getWeekday = function (date) {
5277
- if (!date) {
5278
- return new Date().getDay();
5279
- }
5280
- if (typeof date === 'string') {
5281
- date = new Date(date);
5282
- }
5283
- return date.getDay();
5284
- };
5285
-
5286
-
5251
+ */
5252
+ var getWeekday = function getWeekday(date) {
5253
+ if (!date) {
5254
+ return new Date().getDay();
5255
+ }
5256
+ if (typeof date === 'string') {
5257
+ date = new Date(date);
5258
+ }
5259
+ return date.getDay();
5260
+ };
5261
+
5287
5262
  /**
5288
5263
  * @desc 获取上午/下午/晚上
5289
5264
  * @author huangbo
5290
5265
  * @date 2022年5月7日
5291
5266
  * @param {String} [time] - 时间
5292
- **/
5293
- const timeCycle = function (time) {
5294
- let hour = 0;
5295
- if (!time) {
5296
- hour = new Date().getHours();
5297
- } else if (typeof time === 'string') {
5298
- // 从时间字符串中提取小时
5299
- const match = time.match(/^(\d{1,2})/);
5300
- if (match) {
5301
- hour = parseInt(match[1], 10);
5302
- }
5303
- } else if (typeof time === 'number') {
5304
- hour = time;
5305
- }
5306
- // 判断时间段
5307
- if (hour >= 5 && hour < 12) {
5308
- return '上午';
5309
- } else if (hour >= 12 && hour < 18) {
5310
- return '下午';
5311
- } else {
5312
- return '晚上';
5313
- }
5267
+ **/
5268
+ var timeCycle = function timeCycle(time) {
5269
+ var hour = 0;
5270
+ if (!time) {
5271
+ hour = new Date().getHours();
5272
+ } else if (typeof time === 'string') {
5273
+ // 从时间字符串中提取小时
5274
+ var match = time.match(/^(\d{1,2})/);
5275
+ if (match) {
5276
+ hour = parseInt(match[1], 10);
5277
+ }
5278
+ } else if (typeof time === 'number') {
5279
+ hour = time;
5280
+ }
5281
+ // 判断时间段
5282
+ if (hour >= 5 && hour < 12) {
5283
+ return '上午';
5284
+ } else if (hour >= 12 && hour < 18) {
5285
+ return '下午';
5286
+ } else {
5287
+ return '晚上';
5288
+ }
5314
5289
  };
5315
5290
 
5316
5291
  /***/ }),
@@ -5322,7 +5297,7 @@ module.exports = require("eoss/lib/message-box");
5322
5297
 
5323
5298
  /***/ }),
5324
5299
 
5325
- /***/ 84:
5300
+ /***/ 86:
5326
5301
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
5327
5302
 
5328
5303
  "use strict";