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
@@ -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 = 245);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 252);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3521,7 +3521,7 @@ module.exports = require("vue");
3521
3521
 
3522
3522
  /***/ }),
3523
3523
 
3524
- /***/ 245:
3524
+ /***/ 252:
3525
3525
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3526
3526
 
3527
3527
  "use strict";
@@ -4509,759 +4509,736 @@ function insertAfter(newEl, targetEl) {
4509
4509
  /* unused harmony export getSecond */
4510
4510
  /* unused harmony export getWeekday */
4511
4511
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
4512
- /* Modified from https://github.com/taylorhakes/fecha
4513
- *
4514
- * The MIT License (MIT)
4515
- *
4516
- * Copyright (c) 2015 Taylor Hakes
4517
- *
4518
- * Permission is hereby granted, free of charge, to any person obtaining a copy
4519
- * of this software and associated documentation files (the "Software"), to deal
4520
- * in the Software without restriction, including without limitation the rights
4521
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4522
- * copies of the Software, and to permit persons to whom the Software is
4523
- * furnished to do so, subject to the following conditions:
4524
- *
4525
- * The above copyright notice and this permission notice shall be included in all
4526
- * copies or substantial portions of the Software.
4527
- *
4528
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4529
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4530
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4531
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4532
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4533
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4534
- * SOFTWARE.
4535
- */
4536
-
4537
- /*eslint-disable*/
4538
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
4539
-
4540
-
4512
+
4513
+
4541
4514
  /**
4542
4515
  * Parse or format dates
4543
4516
  * @class fecha
4544
- */
4545
- const fecha = {};
4546
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4547
- const twoDigits = '\\d\\d?';
4548
- const threeDigits = '\\d{3}';
4549
- const fourDigits = '\\d{4}';
4550
- const word = '[^\\s]+';
4551
- const literal = /\[([^]*?)\]/gm;
4552
- const noop = function () {};
4553
-
4554
- function regexEscape(str) {
4555
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
4556
- }
4557
-
4558
- function shorten(arr, sLen) {
4559
- const newArr = [];
4560
- for (let i = 0, len = arr.length; i < len; i++) {
4561
- newArr.push(arr[i].substr(0, sLen));
4562
- }
4563
- return newArr;
4564
- }
4565
-
4566
- function monthUpdate() {
4567
- return function (d, v) {
4568
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
4569
- if (~index) {
4570
- d.month = index;
4571
- }
4572
- };
4573
- }
4574
-
4575
- function pad(val, len) {
4576
- val = String(val);
4577
- len = len || 2;
4578
- while (val.length < len) {
4579
- val = '0' + val;
4580
- }
4581
- return val;
4582
- }
4583
-
4584
- // 直接使用中文日期名称常量
4585
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
4586
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
4587
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
4588
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
4589
- const amPm = ['上午', '下午'];
4590
- const DoFn = function DoFn(D) {
4591
- return D + '日';
4592
- };
4593
-
4594
- const formatFlags = {
4595
- D: function(dateObj) {
4596
- return dateObj.getDay();
4597
- },
4598
- DD: function(dateObj) {
4599
- return pad(dateObj.getDay());
4600
- },
4601
- Do: function(dateObj) {
4602
- return DoFn(dateObj.getDate());
4603
- },
4604
- d: function(dateObj) {
4605
- return dateObj.getDate();
4606
- },
4607
- dd: function(dateObj) {
4608
- return pad(dateObj.getDate());
4609
- },
4610
- ddd: function(dateObj) {
4611
- return dayNamesShort[dateObj.getDay()];
4612
- },
4613
- dddd: function(dateObj) {
4614
- return dayNames[dateObj.getDay()];
4615
- },
4616
- M: function(dateObj) {
4617
- return dateObj.getMonth() + 1;
4618
- },
4619
- MM: function(dateObj) {
4620
- return pad(dateObj.getMonth() + 1);
4621
- },
4622
- MMM: function(dateObj) {
4623
- return monthNamesShort[dateObj.getMonth()];
4624
- },
4625
- MMMM: function(dateObj) {
4626
- return monthNames[dateObj.getMonth()];
4627
- },
4628
- yy: function(dateObj) {
4629
- return pad(String(dateObj.getFullYear()), 4).substr(2);
4630
- },
4631
- yyyy: function(dateObj) {
4632
- return pad(dateObj.getFullYear(), 4);
4633
- },
4634
- h: function(dateObj) {
4635
- return dateObj.getHours() % 12 || 12;
4636
- },
4637
- hh: function(dateObj) {
4638
- return pad(dateObj.getHours() % 12 || 12);
4639
- },
4640
- H: function(dateObj) {
4641
- return dateObj.getHours();
4642
- },
4643
- HH: function(dateObj) {
4644
- return pad(dateObj.getHours());
4645
- },
4646
- m: function(dateObj) {
4647
- return dateObj.getMinutes();
4648
- },
4649
- mm: function(dateObj) {
4650
- return pad(dateObj.getMinutes());
4651
- },
4652
- s: function(dateObj) {
4653
- return dateObj.getSeconds();
4654
- },
4655
- ss: function(dateObj) {
4656
- return pad(dateObj.getSeconds());
4657
- },
4658
- S: function(dateObj) {
4659
- return Math.round(dateObj.getMilliseconds() / 100);
4660
- },
4661
- SS: function(dateObj) {
4662
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
4663
- },
4664
- SSS: function(dateObj) {
4665
- return pad(dateObj.getMilliseconds(), 3);
4666
- },
4667
- a: function(dateObj) {
4668
- return dateObj.getHours() < 12 ? '上午' : '下午';
4669
- },
4670
- A: function(dateObj) {
4671
- return dateObj.getHours() < 12 ? '上午' : '下午';
4672
- },
4673
- ZZ: function(dateObj) {
4674
- const o = dateObj.getTimezoneOffset();
4675
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
4676
- }
4677
- };
4678
-
4679
- const parseFlags = {
4680
- d: [twoDigits, function (d, v) {
4681
- d.day = v;
4682
- }],
4683
- Do: [twoDigits + word, function (d, v) {
4684
- d.day = parseInt(v, 10);
4685
- }],
4686
- M: [twoDigits, function (d, v) {
4687
- d.month = v - 1;
4688
- }],
4689
- yy: [twoDigits, function (d, v) {
4690
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
4691
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
4692
- }],
4693
- h: [twoDigits, function (d, v) {
4694
- d.hour = v;
4695
- }],
4696
- m: [twoDigits, function (d, v) {
4697
- d.minute = v;
4698
- }],
4699
- s: [twoDigits, function (d, v) {
4700
- d.second = v;
4701
- }],
4702
- yyyy: [fourDigits, function (d, v) {
4703
- d.year = v;
4704
- }],
4705
- S: ['\\d', function (d, v) {
4706
- d.millisecond = v * 100;
4707
- }],
4708
- SS: ['\\d{2}', function (d, v) {
4709
- d.millisecond = v * 10;
4710
- }],
4711
- SSS: [threeDigits, function (d, v) {
4712
- d.millisecond = v;
4713
- }],
4714
- D: [twoDigits, noop],
4715
- ddd: [word, noop],
4716
- MMM: [word, monthUpdate('monthNamesShort')],
4717
- MMMM: [word, monthUpdate('monthNames')],
4718
- a: [word, function (d, v) {
4719
- const val = v.toLowerCase();
4720
- if (val === '上午') {
4721
- d.isPm = false;
4722
- } else if (val === '下午') {
4723
- d.isPm = true;
4724
- }
4725
- }],
4726
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
4727
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
4728
-
4729
- if (parts) {
4730
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
4731
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
4732
- }
4733
- }]
4734
- };
4735
- parseFlags.dd = parseFlags.d;
4736
- parseFlags.dddd = parseFlags.ddd;
4737
- parseFlags.DD = parseFlags.D;
4738
- parseFlags.mm = parseFlags.m;
4739
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
4740
- parseFlags.MM = parseFlags.M;
4741
- parseFlags.ss = parseFlags.s;
4742
- parseFlags.A = parseFlags.a;
4743
-
4744
-
4745
- // Some common format strings
4746
- fecha.masks = {
4747
- default: 'ddd MMM dd yyyy HH:mm:ss',
4748
- shortDate: 'M/D/yy',
4749
- mediumDate: 'MMM d, yyyy',
4750
- longDate: 'MMMM d, yyyy',
4751
- fullDate: 'dddd, MMMM d, yyyy',
4752
- shortTime: 'HH:mm',
4753
- mediumTime: 'HH:mm:ss',
4754
- longTime: 'HH:mm:ss.SSS'
4755
- };
4756
-
4517
+ */
4518
+ var fecha = {};
4519
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4520
+ var twoDigits = '\\d\\d?';
4521
+ var threeDigits = '\\d{3}';
4522
+ var fourDigits = '\\d{4}';
4523
+ var word = '[^\\s]+';
4524
+ var literal = /\[([^]*?)\]/gm;
4525
+ var noop = function noop() {};
4526
+
4527
+ function regexEscape(str) {
4528
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
4529
+ }
4530
+
4531
+ function shorten(arr, sLen) {
4532
+ var newArr = [];
4533
+ for (var i = 0, len = arr.length; i < len; i++) {
4534
+ newArr.push(arr[i].substr(0, sLen));
4535
+ }
4536
+ return newArr;
4537
+ }
4538
+
4539
+ function monthUpdate() {
4540
+ return function (d, v) {
4541
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
4542
+ if (~index) {
4543
+ d.month = index;
4544
+ }
4545
+ };
4546
+ }
4547
+
4548
+ function pad(val, len) {
4549
+ val = String(val);
4550
+ len = len || 2;
4551
+ while (val.length < len) {
4552
+ val = '0' + val;
4553
+ }
4554
+ return val;
4555
+ }
4556
+
4557
+ // 直接使用中文日期名称常量
4558
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
4559
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
4560
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
4561
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
4562
+ var amPm = ['上午', '下午'];
4563
+ var DoFn = function DoFn(D) {
4564
+ return D + '日';
4565
+ };
4566
+
4567
+ var formatFlags = {
4568
+ D: function D(dateObj) {
4569
+ return dateObj.getDay();
4570
+ },
4571
+ DD: function DD(dateObj) {
4572
+ return pad(dateObj.getDay());
4573
+ },
4574
+ Do: function Do(dateObj) {
4575
+ return DoFn(dateObj.getDate());
4576
+ },
4577
+ d: function d(dateObj) {
4578
+ return dateObj.getDate();
4579
+ },
4580
+ dd: function dd(dateObj) {
4581
+ return pad(dateObj.getDate());
4582
+ },
4583
+ ddd: function ddd(dateObj) {
4584
+ return dayNamesShort[dateObj.getDay()];
4585
+ },
4586
+ dddd: function dddd(dateObj) {
4587
+ return dayNames[dateObj.getDay()];
4588
+ },
4589
+ M: function M(dateObj) {
4590
+ return dateObj.getMonth() + 1;
4591
+ },
4592
+ MM: function MM(dateObj) {
4593
+ return pad(dateObj.getMonth() + 1);
4594
+ },
4595
+ MMM: function MMM(dateObj) {
4596
+ return monthNamesShort[dateObj.getMonth()];
4597
+ },
4598
+ MMMM: function MMMM(dateObj) {
4599
+ return monthNames[dateObj.getMonth()];
4600
+ },
4601
+ yy: function yy(dateObj) {
4602
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
4603
+ },
4604
+ yyyy: function yyyy(dateObj) {
4605
+ return pad(dateObj.getFullYear(), 4);
4606
+ },
4607
+ h: function h(dateObj) {
4608
+ return dateObj.getHours() % 12 || 12;
4609
+ },
4610
+ hh: function hh(dateObj) {
4611
+ return pad(dateObj.getHours() % 12 || 12);
4612
+ },
4613
+ H: function H(dateObj) {
4614
+ return dateObj.getHours();
4615
+ },
4616
+ HH: function HH(dateObj) {
4617
+ return pad(dateObj.getHours());
4618
+ },
4619
+ m: function m(dateObj) {
4620
+ return dateObj.getMinutes();
4621
+ },
4622
+ mm: function mm(dateObj) {
4623
+ return pad(dateObj.getMinutes());
4624
+ },
4625
+ s: function s(dateObj) {
4626
+ return dateObj.getSeconds();
4627
+ },
4628
+ ss: function ss(dateObj) {
4629
+ return pad(dateObj.getSeconds());
4630
+ },
4631
+ S: function S(dateObj) {
4632
+ return Math.round(dateObj.getMilliseconds() / 100);
4633
+ },
4634
+ SS: function SS(dateObj) {
4635
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
4636
+ },
4637
+ SSS: function SSS(dateObj) {
4638
+ return pad(dateObj.getMilliseconds(), 3);
4639
+ },
4640
+ a: function a(dateObj) {
4641
+ return dateObj.getHours() < 12 ? '上午' : '下午';
4642
+ },
4643
+ A: function A(dateObj) {
4644
+ return dateObj.getHours() < 12 ? '上午' : '下午';
4645
+ },
4646
+ ZZ: function ZZ(dateObj) {
4647
+ var o = dateObj.getTimezoneOffset();
4648
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
4649
+ }
4650
+ };
4651
+
4652
+ var parseFlags = {
4653
+ d: [twoDigits, function (d, v) {
4654
+ d.day = v;
4655
+ }],
4656
+ Do: [twoDigits + word, function (d, v) {
4657
+ d.day = parseInt(v, 10);
4658
+ }],
4659
+ M: [twoDigits, function (d, v) {
4660
+ d.month = v - 1;
4661
+ }],
4662
+ yy: [twoDigits, function (d, v) {
4663
+ var da = new Date(),
4664
+ cent = +('' + da.getFullYear()).substr(0, 2);
4665
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
4666
+ }],
4667
+ h: [twoDigits, function (d, v) {
4668
+ d.hour = v;
4669
+ }],
4670
+ m: [twoDigits, function (d, v) {
4671
+ d.minute = v;
4672
+ }],
4673
+ s: [twoDigits, function (d, v) {
4674
+ d.second = v;
4675
+ }],
4676
+ yyyy: [fourDigits, function (d, v) {
4677
+ d.year = v;
4678
+ }],
4679
+ S: ['\\d', function (d, v) {
4680
+ d.millisecond = v * 100;
4681
+ }],
4682
+ SS: ['\\d{2}', function (d, v) {
4683
+ d.millisecond = v * 10;
4684
+ }],
4685
+ SSS: [threeDigits, function (d, v) {
4686
+ d.millisecond = v;
4687
+ }],
4688
+ D: [twoDigits, noop],
4689
+ ddd: [word, noop],
4690
+ MMM: [word, monthUpdate('monthNamesShort')],
4691
+ MMMM: [word, monthUpdate('monthNames')],
4692
+ a: [word, function (d, v) {
4693
+ var val = v.toLowerCase();
4694
+ if (val === '上午') {
4695
+ d.isPm = false;
4696
+ } else if (val === '下午') {
4697
+ d.isPm = true;
4698
+ }
4699
+ }],
4700
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
4701
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
4702
+ minutes = void 0;
4703
+
4704
+ if (parts) {
4705
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
4706
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
4707
+ }
4708
+ }]
4709
+ };
4710
+ parseFlags.dd = parseFlags.d;
4711
+ parseFlags.dddd = parseFlags.ddd;
4712
+ parseFlags.DD = parseFlags.D;
4713
+ parseFlags.mm = parseFlags.m;
4714
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
4715
+ parseFlags.MM = parseFlags.M;
4716
+ parseFlags.ss = parseFlags.s;
4717
+ parseFlags.A = parseFlags.a;
4718
+
4719
+ // Some common format strings
4720
+ fecha.masks = {
4721
+ default: 'ddd MMM dd yyyy HH:mm:ss',
4722
+ shortDate: 'M/D/yy',
4723
+ mediumDate: 'MMM d, yyyy',
4724
+ longDate: 'MMMM d, yyyy',
4725
+ fullDate: 'dddd, MMMM d, yyyy',
4726
+ shortTime: 'HH:mm',
4727
+ mediumTime: 'HH:mm:ss',
4728
+ longTime: 'HH:mm:ss.SSS'
4729
+ };
4730
+
4757
4731
  /***
4758
4732
  * Format a date
4759
4733
  * @method format
4760
4734
  * @param {Date|number} dateObj
4761
4735
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
4762
- */
4763
- fecha.format = function (dateObj, mask) {
4764
- if (typeof dateObj === 'number') {
4765
- dateObj = new Date(dateObj);
4766
- }
4767
-
4768
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
4769
- throw new Error('Invalid Date in fecha.format');
4770
- }
4771
-
4772
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
4773
-
4774
- const literals = [];
4775
-
4776
- // Make literals inactive by replacing them with ??
4777
- mask = mask.replace(literal, function($0, $1) {
4778
- literals.push($1);
4779
- return '@@@';
4780
- });
4781
- // Apply formatting rules
4782
- mask = mask.replace(token, function ($0) {
4783
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
4784
- });
4785
- // Inline literal values back into the formatted value
4786
- return mask.replace(/@@@/g, function() {
4787
- return literals.shift();
4788
- });
4789
- };
4790
-
4736
+ */
4737
+ fecha.format = function (dateObj, mask) {
4738
+ if (typeof dateObj === 'number') {
4739
+ dateObj = new Date(dateObj);
4740
+ }
4741
+
4742
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
4743
+ throw new Error('Invalid Date in fecha.format');
4744
+ }
4745
+
4746
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
4747
+
4748
+ var literals = [];
4749
+
4750
+ // Make literals inactive by replacing them with ??
4751
+ mask = mask.replace(literal, function ($0, $1) {
4752
+ literals.push($1);
4753
+ return '@@@';
4754
+ });
4755
+ // Apply formatting rules
4756
+ mask = mask.replace(token, function ($0) {
4757
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
4758
+ });
4759
+ // Inline literal values back into the formatted value
4760
+ return mask.replace(/@@@/g, function () {
4761
+ return literals.shift();
4762
+ });
4763
+ };
4764
+
4791
4765
  /**
4792
4766
  * Parse a date string into an object, changes - into /
4793
4767
  * @method parse
4794
4768
  * @param {string} dateStr Date string
4795
4769
  * @param {string} format Date parse format
4796
4770
  * @returns {Date|boolean}
4797
- */
4798
- fecha.parse = function (dateStr, format) {
4799
- if (typeof format !== 'string') {
4800
- throw new Error('Invalid format in fecha.parse');
4801
- }
4802
-
4803
- format = fecha.masks[format] || format;
4804
-
4805
- // Avoid regular expression denial of service, fail early for really long strings
4806
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
4807
- if (dateStr.length > 1000) {
4808
- return null;
4809
- }
4810
-
4811
- const dateInfo = {};
4812
- const parseInfo = [];
4813
- const literals = [];
4814
- format = format.replace(literal, function($0, $1) {
4815
- literals.push($1);
4816
- return '@@@';
4817
- });
4818
- let newFormat = regexEscape(format).replace(token, function ($0) {
4819
- if (parseFlags[$0]) {
4820
- const info = parseFlags[$0];
4821
- parseInfo.push(info[1]);
4822
- return '(' + info[0] + ')';
4823
- }
4824
-
4825
- return $0;
4826
- });
4827
- newFormat = newFormat.replace(/@@@/g, function() {
4828
- return literals.shift();
4829
- });
4830
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
4831
- if (!matches) {
4832
- return null;
4833
- }
4834
-
4835
- for (let i = 1; i < matches.length; i++) {
4836
- parseInfo[i - 1](dateInfo, matches[i]);
4837
- }
4838
-
4839
- const today = new Date();
4840
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
4841
- dateInfo.hour = +dateInfo.hour + 12;
4842
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
4843
- dateInfo.hour = 0;
4844
- }
4845
-
4846
- let date;
4847
- if (dateInfo.timezoneOffset != null) {
4848
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
4849
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
4850
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
4851
- } else {
4852
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
4853
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
4854
- }
4855
- return date;
4856
- };
4857
-
4858
- // 导出fecha对象
4859
-
4860
-
4861
- // 以下是从date-util.js合并的函数
4862
- const newArray = function(start, end) {
4863
- let result = [];
4864
- for (let i = start; i <= end; i++) {
4865
- result.push(i);
4866
- }
4867
- return result;
4868
- };
4869
-
4870
- const getSettings = () => {
4871
- return {
4872
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
4873
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
4874
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
4875
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
4876
- amPm: ['上午', '下午']
4877
- };
4878
- };
4879
-
4880
- const toDate = function(date) {
4881
- return isDate(date) ? new Date(date) : null;
4882
- };
4883
-
4884
- const isDate = function(date) {
4885
- if (date === null || date === undefined) return false;
4886
- if (isNaN(new Date(date).getTime())) return false;
4887
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
4888
- return true;
4889
- };
4890
-
4891
- const isDateObject = function(val) {
4892
- return val instanceof Date;
4893
- };
4894
-
4895
- const formatDate = function (date, format = 'yyyy-MM-dd') {
4896
- // 处理多种输入类型
4897
- if (!date) return '';
4898
-
4899
- // 如果是时间戳,转成日期对象
4900
- if (typeof date === 'number') {
4901
- date = new Date(date);
4902
- }
4903
- // 如果是字符串,转成日期对象
4904
- if (typeof date === 'string') {
4905
- date = new Date(date);
4906
- }
4907
-
4908
- // 调用toDate进一步验证和转换
4909
- date = toDate(date);
4910
- if (!date) return '';
4911
-
4912
- // 兼容大写和小写的格式标记
4913
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
4914
- const lowercaseFormat = format
4915
- .replace(/YYYY/g, 'yyyy')
4916
- .replace(/D/g, 'd')
4917
-
4918
- // 使用fecha库进行格式化,支持中文配置
4919
- const str = fecha.format(date, lowercaseFormat, getSettings());
4920
- return str;
4921
- };
4922
-
4923
- const parseDate = function(string, format) {
4924
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
4925
- };
4926
-
4927
- const getDayCountOfMonth = function(year, month) {
4928
- if (month === 3 || month === 5 || month === 8 || month === 10) {
4929
- return 30;
4930
- }
4931
-
4932
- if (month === 1) {
4933
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
4934
- return 29;
4935
- } else {
4936
- return 28;
4937
- }
4938
- }
4939
-
4940
- return 31;
4941
- };
4942
-
4943
- const getDayCountOfYear = function(year) {
4944
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
4945
- return isLeapYear ? 366 : 365;
4946
- };
4947
-
4948
- const getFirstDayOfMonth = function(date) {
4949
- const temp = new Date(date.getTime());
4950
- temp.setDate(1);
4951
- return temp.getDay();
4952
- };
4953
-
4954
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
4955
- // {prev, next} Date should work for Daylight Saving Time
4956
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
4957
- const prevDate = function(date, amount = 1) {
4958
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
4959
- };
4960
-
4961
- const nextDate = function(date, amount = 1) {
4962
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
4963
- };
4964
-
4965
- const getStartDateOfMonth = function(year, month) {
4966
- const result = new Date(year, month, 1);
4967
- const day = result.getDay();
4968
-
4969
- if (day === 0) {
4970
- return prevDate(result, 7);
4971
- } else {
4972
- return prevDate(result, day);
4973
- }
4974
- };
4975
-
4976
- const getWeekNumber = function(date) {
4977
- // 支持多种输入类型
4978
- if (!date||!isDate(date)) {
4979
- date = new Date();
4980
- }
4981
- if (typeof date === 'string') {
4982
- date = new Date(date);
4983
- }
4984
-
4985
- // 验证日期有效性
4986
- if (!isDate(date)) return null;
4987
-
4988
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
4989
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
4990
- // 将星期日的星期数设为7
4991
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
4992
- // 获取当年的第一天
4993
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
4994
- // 计算到最近的星期四的完整周数
4995
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
4996
- // 返回周数
4997
- return weekNo;
4998
- };
4999
-
5000
- const getRangeHours = function(ranges) {
5001
- const hours = [];
5002
- let disabledHours = [];
5003
-
5004
- (ranges || []).forEach(range => {
5005
- const value = range.map(date => date.getHours());
5006
-
5007
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5008
- });
5009
-
5010
- if (disabledHours.length) {
5011
- for (let i = 0; i < 24; i++) {
5012
- hours[i] = disabledHours.indexOf(i) === -1;
5013
- }
5014
- } else {
5015
- for (let i = 0; i < 24; i++) {
5016
- hours[i] = false;
5017
- }
5018
- }
5019
-
5020
- return hours;
5021
- };
5022
-
5023
- const getPrevMonthLastDays = (date, amount) => {
5024
- if (amount <= 0) return [];
5025
- const temp = new Date(date.getTime());
5026
- temp.setDate(0);
5027
- const lastDay = temp.getDate();
5028
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
5029
- };
5030
-
5031
- const getMonthDays = (date) => {
5032
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5033
- const days = temp.getDate();
5034
- return range(days).map((_, index) => index + 1);
5035
- };
5036
-
5037
- function setRangeData(arr, start, end, value) {
5038
- for (let i = start; i < end; i++) {
5039
- arr[i] = value;
5040
- }
5041
- }
5042
-
5043
- const getRangeMinutes = function(ranges, hour) {
5044
- const minutes = new Array(60);
5045
-
5046
- if (ranges.length > 0) {
5047
- ranges.forEach(range => {
5048
- const start = range[0];
5049
- const end = range[1];
5050
- const startHour = start.getHours();
5051
- const startMinute = start.getMinutes();
5052
- const endHour = end.getHours();
5053
- const endMinute = end.getMinutes();
5054
- if (startHour === hour && endHour !== hour) {
5055
- setRangeData(minutes, startMinute, 60, true);
5056
- } else if (startHour === hour && endHour === hour) {
5057
- setRangeData(minutes, startMinute, endMinute + 1, true);
5058
- } else if (startHour !== hour && endHour === hour) {
5059
- setRangeData(minutes, 0, endMinute + 1, true);
5060
- } else if (startHour < hour && endHour > hour) {
5061
- setRangeData(minutes, 0, 60, true);
5062
- }
5063
- });
5064
- } else {
5065
- setRangeData(minutes, 0, 60, true);
5066
- }
5067
- return minutes;
5068
- };
5069
-
5070
- const range = function(n) {
5071
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5072
- return Array.apply(null, {length: n}).map((_, n) => n);
5073
- };
5074
-
5075
- const modifyDate = function(date, y, m, d) {
5076
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5077
- };
5078
-
5079
- const modifyTime = function(date, h, m, s) {
5080
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5081
- };
5082
-
5083
- const modifyWithTimeString = (date, time) => {
5084
- if (date == null || !time) {
5085
- return date;
5086
- }
5087
- time = parseDate(time, 'HH:mm:ss');
5088
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5089
- };
5090
-
5091
- const clearTime = function(date) {
5092
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5093
- };
5094
-
5095
- const clearMilliseconds = function(date) {
5096
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5097
- };
5098
-
5099
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
5100
- // TODO: refactory a more elegant solution
5101
- if (ranges.length === 0) return date;
5102
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
5103
- const ndate = normalizeDate(date);
5104
- const nranges = ranges.map(range => range.map(normalizeDate));
5105
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
5106
-
5107
- let minDate = nranges[0][0];
5108
- let maxDate = nranges[0][0];
5109
-
5110
- nranges.forEach(nrange => {
5111
- minDate = new Date(Math.min(nrange[0], minDate));
5112
- maxDate = new Date(Math.max(nrange[1], minDate));
5113
- });
5114
-
5115
- const ret = ndate < minDate ? minDate : maxDate;
5116
- // preserve Year/Month/Date
5117
- return modifyDate(
5118
- ret,
5119
- date.getFullYear(),
5120
- date.getMonth(),
5121
- date.getDate()
5122
- );
5123
- };
5124
-
5125
- const timeWithinRange = function(date, selectableRange, format) {
5126
- const limitedDate = limitTimeRange(date, selectableRange, format);
5127
- return limitedDate.getTime() === date.getTime();
5128
- };
5129
-
5130
- const changeYearMonthAndClampDate = function(date, year, month) {
5131
- // clamp date to the number of days in `year`, `month`
5132
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
5133
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5134
- return modifyDate(date, year, month, monthDate);
5135
- };
5136
-
5137
- const prevMonth = function(date) {
5138
- const year = date.getFullYear();
5139
- const month = date.getMonth();
5140
- return month === 0
5141
- ? changeYearMonthAndClampDate(date, year - 1, 11)
5142
- : changeYearMonthAndClampDate(date, year, month - 1);
5143
- };
5144
-
5145
- const nextMonth = function(date) {
5146
- const year = date.getFullYear();
5147
- const month = date.getMonth();
5148
- return month === 11
5149
- ? changeYearMonthAndClampDate(date, year + 1, 0)
5150
- : changeYearMonthAndClampDate(date, year, month + 1);
5151
- };
5152
-
5153
- const prevYear = function(date, amount = 1) {
5154
- const year = date.getFullYear();
5155
- const month = date.getMonth();
5156
- return changeYearMonthAndClampDate(date, year - amount, month);
5157
- };
5158
-
5159
- const nextYear = function(date, amount = 1) {
5160
- const year = date.getFullYear();
5161
- const month = date.getMonth();
5162
- return changeYearMonthAndClampDate(date, year + amount, month);
5163
- };
5164
-
5165
- const extractDateFormat = function(format) {
5166
- return format
5167
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
5168
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
5169
- .trim();
5170
- };
5171
-
5172
- const extractTimeFormat = function(format) {
5173
- return format
5174
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
5175
- .trim();
5176
- };
5177
-
5178
- const validateRangeInOneMonth = function(start, end) {
5179
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
5180
- };
5181
-
4771
+ */
4772
+ fecha.parse = function (dateStr, format) {
4773
+ if (typeof format !== 'string') {
4774
+ throw new Error('Invalid format in fecha.parse');
4775
+ }
4776
+
4777
+ format = fecha.masks[format] || format;
4778
+
4779
+ // Avoid regular expression denial of service, fail early for really long strings
4780
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
4781
+ if (dateStr.length > 1000) {
4782
+ return null;
4783
+ }
4784
+
4785
+ var dateInfo = {};
4786
+ var parseInfo = [];
4787
+ var literals = [];
4788
+ format = format.replace(literal, function ($0, $1) {
4789
+ literals.push($1);
4790
+ return '@@@';
4791
+ });
4792
+ var newFormat = regexEscape(format).replace(token, function ($0) {
4793
+ if (parseFlags[$0]) {
4794
+ var info = parseFlags[$0];
4795
+ parseInfo.push(info[1]);
4796
+ return '(' + info[0] + ')';
4797
+ }
4798
+
4799
+ return $0;
4800
+ });
4801
+ newFormat = newFormat.replace(/@@@/g, function () {
4802
+ return literals.shift();
4803
+ });
4804
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
4805
+ if (!matches) {
4806
+ return null;
4807
+ }
4808
+
4809
+ for (var i = 1; i < matches.length; i++) {
4810
+ parseInfo[i - 1](dateInfo, matches[i]);
4811
+ }
4812
+
4813
+ var today = new Date();
4814
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
4815
+ dateInfo.hour = +dateInfo.hour + 12;
4816
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
4817
+ dateInfo.hour = 0;
4818
+ }
4819
+
4820
+ var date = void 0;
4821
+ if (dateInfo.timezoneOffset != null) {
4822
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
4823
+ 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));
4824
+ } else {
4825
+ 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);
4826
+ }
4827
+ return date;
4828
+ };
4829
+
4830
+ // 导出fecha对象
4831
+
4832
+
4833
+ // 以下是从date-util.js合并的函数
4834
+ var newArray = function newArray(start, end) {
4835
+ var result = [];
4836
+ for (var i = start; i <= end; i++) {
4837
+ result.push(i);
4838
+ }
4839
+ return result;
4840
+ };
4841
+
4842
+ var getSettings = function getSettings() {
4843
+ return {
4844
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
4845
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
4846
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
4847
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
4848
+ amPm: ['上午', '下午']
4849
+ };
4850
+ };
4851
+
4852
+ var toDate = function toDate(date) {
4853
+ return isDate(date) ? new Date(date) : null;
4854
+ };
4855
+
4856
+ var isDate = function isDate(date) {
4857
+ if (date === null || date === undefined) return false;
4858
+ if (isNaN(new Date(date).getTime())) return false;
4859
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
4860
+ return true;
4861
+ };
4862
+
4863
+ var isDateObject = function isDateObject(val) {
4864
+ return val instanceof Date;
4865
+ };
4866
+
4867
+ var formatDate = function formatDate(date) {
4868
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
4869
+
4870
+ // 处理多种输入类型
4871
+ if (!date) return '';
4872
+
4873
+ // 如果是时间戳,转成日期对象
4874
+ if (typeof date === 'number') {
4875
+ date = new Date(date);
4876
+ }
4877
+ // 如果是字符串,转成日期对象
4878
+ if (typeof date === 'string') {
4879
+ date = new Date(date);
4880
+ }
4881
+
4882
+ // 调用toDate进一步验证和转换
4883
+ date = toDate(date);
4884
+ if (!date) return '';
4885
+
4886
+ // 兼容大写和小写的格式标记
4887
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
4888
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
4889
+
4890
+ // 使用fecha库进行格式化,支持中文配置
4891
+ var str = fecha.format(date, lowercaseFormat, getSettings());
4892
+ return str;
4893
+ };
4894
+
4895
+ var parseDate = function parseDate(string, format) {
4896
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
4897
+ };
4898
+
4899
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
4900
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
4901
+ return 30;
4902
+ }
4903
+
4904
+ if (month === 1) {
4905
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
4906
+ return 29;
4907
+ } else {
4908
+ return 28;
4909
+ }
4910
+ }
4911
+
4912
+ return 31;
4913
+ };
4914
+
4915
+ var getDayCountOfYear = function getDayCountOfYear(year) {
4916
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
4917
+ return isLeapYear ? 366 : 365;
4918
+ };
4919
+
4920
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
4921
+ var temp = new Date(date.getTime());
4922
+ temp.setDate(1);
4923
+ return temp.getDay();
4924
+ };
4925
+
4926
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
4927
+ // {prev, next} Date should work for Daylight Saving Time
4928
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
4929
+ var prevDate = function prevDate(date) {
4930
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
4931
+
4932
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
4933
+ };
4934
+
4935
+ var nextDate = function nextDate(date) {
4936
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
4937
+
4938
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
4939
+ };
4940
+
4941
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
4942
+ var result = new Date(year, month, 1);
4943
+ var day = result.getDay();
4944
+
4945
+ if (day === 0) {
4946
+ return prevDate(result, 7);
4947
+ } else {
4948
+ return prevDate(result, day);
4949
+ }
4950
+ };
4951
+
4952
+ var getWeekNumber = function getWeekNumber(date) {
4953
+ // 支持多种输入类型
4954
+ if (!date || !isDate(date)) {
4955
+ date = new Date();
4956
+ }
4957
+ if (typeof date === 'string') {
4958
+ date = new Date(date);
4959
+ }
4960
+
4961
+ // 验证日期有效性
4962
+ if (!isDate(date)) return null;
4963
+
4964
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
4965
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
4966
+ // 将星期日的星期数设为7
4967
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
4968
+ // 获取当年的第一天
4969
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
4970
+ // 计算到最近的星期四的完整周数
4971
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
4972
+ // 返回周数
4973
+ return weekNo;
4974
+ };
4975
+
4976
+ var getRangeHours = function getRangeHours(ranges) {
4977
+ var hours = [];
4978
+ var disabledHours = [];
4979
+
4980
+ (ranges || []).forEach(function (range) {
4981
+ var value = range.map(function (date) {
4982
+ return date.getHours();
4983
+ });
4984
+
4985
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
4986
+ });
4987
+
4988
+ if (disabledHours.length) {
4989
+ for (var i = 0; i < 24; i++) {
4990
+ hours[i] = disabledHours.indexOf(i) === -1;
4991
+ }
4992
+ } else {
4993
+ for (var _i = 0; _i < 24; _i++) {
4994
+ hours[_i] = false;
4995
+ }
4996
+ }
4997
+
4998
+ return hours;
4999
+ };
5000
+
5001
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
5002
+ if (amount <= 0) return [];
5003
+ var temp = new Date(date.getTime());
5004
+ temp.setDate(0);
5005
+ var lastDay = temp.getDate();
5006
+ return range(amount).map(function (_, index) {
5007
+ return lastDay - (amount - index - 1);
5008
+ });
5009
+ };
5010
+
5011
+ var getMonthDays = function getMonthDays(date) {
5012
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5013
+ var days = temp.getDate();
5014
+ return range(days).map(function (_, index) {
5015
+ return index + 1;
5016
+ });
5017
+ };
5018
+
5019
+ function setRangeData(arr, start, end, value) {
5020
+ for (var i = start; i < end; i++) {
5021
+ arr[i] = value;
5022
+ }
5023
+ }
5024
+
5025
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
5026
+ var minutes = new Array(60);
5027
+
5028
+ if (ranges.length > 0) {
5029
+ ranges.forEach(function (range) {
5030
+ var start = range[0];
5031
+ var end = range[1];
5032
+ var startHour = start.getHours();
5033
+ var startMinute = start.getMinutes();
5034
+ var endHour = end.getHours();
5035
+ var endMinute = end.getMinutes();
5036
+ if (startHour === hour && endHour !== hour) {
5037
+ setRangeData(minutes, startMinute, 60, true);
5038
+ } else if (startHour === hour && endHour === hour) {
5039
+ setRangeData(minutes, startMinute, endMinute + 1, true);
5040
+ } else if (startHour !== hour && endHour === hour) {
5041
+ setRangeData(minutes, 0, endMinute + 1, true);
5042
+ } else if (startHour < hour && endHour > hour) {
5043
+ setRangeData(minutes, 0, 60, true);
5044
+ }
5045
+ });
5046
+ } else {
5047
+ setRangeData(minutes, 0, 60, true);
5048
+ }
5049
+ return minutes;
5050
+ };
5051
+
5052
+ var range = function range(n) {
5053
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5054
+ return Array.apply(null, { length: n }).map(function (_, n) {
5055
+ return n;
5056
+ });
5057
+ };
5058
+
5059
+ var modifyDate = function modifyDate(date, y, m, d) {
5060
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5061
+ };
5062
+
5063
+ var modifyTime = function modifyTime(date, h, m, s) {
5064
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5065
+ };
5066
+
5067
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
5068
+ if (date == null || !time) {
5069
+ return date;
5070
+ }
5071
+ time = parseDate(time, 'HH:mm:ss');
5072
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5073
+ };
5074
+
5075
+ var clearTime = function clearTime(date) {
5076
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5077
+ };
5078
+
5079
+ var clearMilliseconds = function clearMilliseconds(date) {
5080
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5081
+ };
5082
+
5083
+ var limitTimeRange = function limitTimeRange(date, ranges) {
5084
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
5085
+
5086
+ // TODO: refactory a more elegant solution
5087
+ if (ranges.length === 0) return date;
5088
+ var normalizeDate = function normalizeDate(date) {
5089
+ return fecha.parse(fecha.format(date, format), format);
5090
+ };
5091
+ var ndate = normalizeDate(date);
5092
+ var nranges = ranges.map(function (range) {
5093
+ return range.map(normalizeDate);
5094
+ });
5095
+ if (nranges.some(function (nrange) {
5096
+ return ndate >= nrange[0] && ndate <= nrange[1];
5097
+ })) return date;
5098
+
5099
+ var minDate = nranges[0][0];
5100
+ var maxDate = nranges[0][0];
5101
+
5102
+ nranges.forEach(function (nrange) {
5103
+ minDate = new Date(Math.min(nrange[0], minDate));
5104
+ maxDate = new Date(Math.max(nrange[1], minDate));
5105
+ });
5106
+
5107
+ var ret = ndate < minDate ? minDate : maxDate;
5108
+ // preserve Year/Month/Date
5109
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
5110
+ };
5111
+
5112
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
5113
+ var limitedDate = limitTimeRange(date, selectableRange, format);
5114
+ return limitedDate.getTime() === date.getTime();
5115
+ };
5116
+
5117
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
5118
+ // clamp date to the number of days in `year`, `month`
5119
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
5120
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5121
+ return modifyDate(date, year, month, monthDate);
5122
+ };
5123
+
5124
+ var prevMonth = function prevMonth(date) {
5125
+ var year = date.getFullYear();
5126
+ var month = date.getMonth();
5127
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
5128
+ };
5129
+
5130
+ var nextMonth = function nextMonth(date) {
5131
+ var year = date.getFullYear();
5132
+ var month = date.getMonth();
5133
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
5134
+ };
5135
+
5136
+ var prevYear = function prevYear(date) {
5137
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5138
+
5139
+ var year = date.getFullYear();
5140
+ var month = date.getMonth();
5141
+ return changeYearMonthAndClampDate(date, year - amount, month);
5142
+ };
5143
+
5144
+ var nextYear = function nextYear(date) {
5145
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5146
+
5147
+ var year = date.getFullYear();
5148
+ var month = date.getMonth();
5149
+ return changeYearMonthAndClampDate(date, year + amount, month);
5150
+ };
5151
+
5152
+ var extractDateFormat = function extractDateFormat(format) {
5153
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
5154
+ };
5155
+
5156
+ var extractTimeFormat = function extractTimeFormat(format) {
5157
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
5158
+ };
5159
+
5160
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
5161
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
5162
+ };
5163
+
5182
5164
  /**
5183
5165
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
5184
5166
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
5185
5167
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
5186
5168
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
5187
5169
  * @returns {number} 工作日数量
5188
- */
5189
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
5190
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5191
- throw new Error(
5192
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
5193
- );
5194
- }
5195
-
5196
- const startDateObj = new Date(start_date);
5197
- const endDateObj = new Date(end_date);
5198
-
5199
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5200
- throw new Error(
5201
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
5202
- );
5203
- }
5204
-
5205
- if (startDateObj > endDateObj) {
5206
- throw new Error('Start date should be earlier than or equal to end date.');
5207
- }
5208
-
5209
- let workdays = 0;
5210
-
5211
- // Iterate through each day in the date range
5212
- for (
5213
- let currentDate = new Date(startDateObj);
5214
- currentDate <= endDateObj;
5215
- currentDate.setDate(currentDate.getDate() + 1)
5216
- ) {
5217
- // Check if the current day is a weekend (Saturday or Sunday)
5218
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5219
-
5220
- // Check if the current day is a holiday
5221
- const isHoliday = holidays.some((holiday) => {
5222
- const holidayDate = new Date(holiday);
5223
- return currentDate.toDateString() === holidayDate.toDateString();
5224
- });
5225
-
5226
- // If it's a workday (not a weekend or holiday), increment the workdays count
5227
- if (!isWeekend && !isHoliday) {
5228
- workdays++;
5229
- }
5230
- }
5231
-
5232
- return workdays;
5233
- };
5234
-
5170
+ */
5171
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
5172
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5173
+
5174
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5175
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5176
+ }
5177
+
5178
+ var startDateObj = new Date(start_date);
5179
+ var endDateObj = new Date(end_date);
5180
+
5181
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5182
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5183
+ }
5184
+
5185
+ if (startDateObj > endDateObj) {
5186
+ throw new Error('Start date should be earlier than or equal to end date.');
5187
+ }
5188
+
5189
+ var workdays = 0;
5190
+
5191
+ // Iterate through each day in the date range
5192
+
5193
+ var _loop = function _loop(currentDate) {
5194
+ // Check if the current day is a weekend (Saturday or Sunday)
5195
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5196
+
5197
+ // Check if the current day is a holiday
5198
+ var isHoliday = holidays.some(function (holiday) {
5199
+ var holidayDate = new Date(holiday);
5200
+ return currentDate.toDateString() === holidayDate.toDateString();
5201
+ });
5202
+
5203
+ // If it's a workday (not a weekend or holiday), increment the workdays count
5204
+ if (!isWeekend && !isHoliday) {
5205
+ workdays++;
5206
+ }
5207
+ };
5208
+
5209
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
5210
+ _loop(currentDate);
5211
+ }
5212
+
5213
+ return workdays;
5214
+ };
5215
+
5235
5216
  /**
5236
5217
  * 日期加减天数
5237
5218
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
5238
5219
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
5239
5220
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
5240
- */
5241
- const dateAddDays = function (start_date, days) {
5242
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5243
- throw new Error(
5244
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
5245
- );
5246
- }
5247
-
5248
- const startDateObj = new Date(start_date);
5249
- if (isNaN(startDateObj.getTime())) {
5250
- throw new Error(
5251
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5252
- );
5253
- }
5254
-
5255
- const resultDateObj = new Date(startDateObj);
5256
- resultDateObj.setDate(resultDateObj.getDate() + days);
5257
-
5258
- const resultYear = resultDateObj.getFullYear();
5259
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5260
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5261
-
5262
- return `${resultYear}-${resultMonth}-${resultDay}`;
5263
- };
5264
-
5221
+ */
5222
+ var dateAddDays = function dateAddDays(start_date, days) {
5223
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5224
+ 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.");
5225
+ }
5226
+
5227
+ var startDateObj = new Date(start_date);
5228
+ if (isNaN(startDateObj.getTime())) {
5229
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5230
+ }
5231
+
5232
+ var resultDateObj = new Date(startDateObj);
5233
+ resultDateObj.setDate(resultDateObj.getDate() + days);
5234
+
5235
+ var resultYear = resultDateObj.getFullYear();
5236
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5237
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5238
+
5239
+ return resultYear + '-' + resultMonth + '-' + resultDay;
5240
+ };
5241
+
5265
5242
  /**
5266
5243
  * 计算两个日期之间的差值
5267
5244
  * @date 2023年12月14日
@@ -5269,182 +5246,180 @@ const dateAddDays = function (start_date, days) {
5269
5246
  * @param {String} end_date - 结束日期字符串
5270
5247
  * @param {String} unit - 单位:year/month/day
5271
5248
  * @returns {Number} 差值
5272
- */
5273
- const dateDiff = function (start_date, end_date, unit = 'day') {
5274
- // Assuming date strings are in "YYYY-MM-DD" format
5275
- var startDate = new Date(start_date);
5276
- var endDate = new Date(end_date);
5277
-
5278
- // If the date is invalid, return 0
5279
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5280
- return 0;
5281
- }
5282
-
5283
- if (unit === 'year') {
5284
- return endDate.getFullYear() - startDate.getFullYear();
5285
- } else if (unit === 'month') {
5286
- return (
5287
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
5288
- (endDate.getMonth() - startDate.getMonth())
5289
- );
5290
- } else {
5291
- // Default to day
5292
- var timeDifference = endDate - startDate;
5293
- // Calculate days (86400000 milliseconds per day)
5294
- return Math.floor(timeDifference / 86400000);
5295
- }
5296
- };
5297
-
5249
+ */
5250
+ var dateDiff = function dateDiff(start_date, end_date) {
5251
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
5252
+
5253
+ // Assuming date strings are in "YYYY-MM-DD" format
5254
+ var startDate = new Date(start_date);
5255
+ var endDate = new Date(end_date);
5256
+
5257
+ // If the date is invalid, return 0
5258
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5259
+ return 0;
5260
+ }
5261
+
5262
+ if (unit === 'year') {
5263
+ return endDate.getFullYear() - startDate.getFullYear();
5264
+ } else if (unit === 'month') {
5265
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
5266
+ } else {
5267
+ // Default to day
5268
+ var timeDifference = endDate - startDate;
5269
+ // Calculate days (86400000 milliseconds per day)
5270
+ return Math.floor(timeDifference / 86400000);
5271
+ }
5272
+ };
5273
+
5298
5274
  /**
5299
5275
  * 获取月份中的日期
5300
5276
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
5301
5277
  * @returns {number} 月份中的日期(1-31)
5302
- */
5303
- const dayOfMonth = function (date) {
5304
- if (typeof date !== 'string') {
5305
- throw new Error(
5306
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
5307
- );
5308
- }
5309
-
5310
- const dateObj = new Date(date);
5311
- if (isNaN(dateObj.getTime())) {
5312
- throw new Error(
5313
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5314
- );
5315
- }
5316
-
5317
- return dateObj.getDate();
5318
- };
5319
-
5278
+ */
5279
+ var dayOfMonth = function dayOfMonth(date) {
5280
+ if (typeof date !== 'string') {
5281
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5282
+ }
5283
+
5284
+ var dateObj = new Date(date);
5285
+ if (isNaN(dateObj.getTime())) {
5286
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5287
+ }
5288
+
5289
+ return dateObj.getDate();
5290
+ };
5291
+
5320
5292
  /**
5321
5293
  * 获取当前日期
5322
5294
  * @date 2022年5月7日
5323
5295
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
5324
5296
  * @returns {string} 当前日期的格式化字符串
5325
- */
5326
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
5327
- return formatDate(new Date(), format);
5328
- };
5329
-
5297
+ */
5298
+ var getCurrentDate = function getCurrentDate() {
5299
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
5300
+
5301
+ return formatDate(new Date(), format);
5302
+ };
5303
+
5330
5304
  /**
5331
5305
  * 获取当前日期时间
5332
5306
  * @date 2022年5月7日
5333
5307
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
5334
5308
  * @returns {string} 当前日期时间的格式化字符串
5335
- */
5336
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
5337
- return formatDate(new Date(), format);
5338
- };
5339
-
5309
+ */
5310
+ var getCurrentDateTime = function getCurrentDateTime() {
5311
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
5312
+
5313
+ return formatDate(new Date(), format);
5314
+ };
5315
+
5340
5316
  /**
5341
5317
  * 获取小时
5342
5318
  * @date 2022年5月7日
5343
5319
  * @param {Date|string} [date] - 日期对象或日期字符串
5344
5320
  * @returns {number} 小时数(0-23)
5345
- */
5346
- const getHour = function (date) {
5347
- if (!date) {
5348
- return new Date().getHours();
5349
- }
5350
- if (typeof date === 'string') {
5351
- date = new Date(date);
5352
- }
5353
- return date.getHours();
5354
- };
5355
-
5321
+ */
5322
+ var getHour = function getHour(date) {
5323
+ if (!date) {
5324
+ return new Date().getHours();
5325
+ }
5326
+ if (typeof date === 'string') {
5327
+ date = new Date(date);
5328
+ }
5329
+ return date.getHours();
5330
+ };
5331
+
5356
5332
  /**
5357
5333
  * 获取分钟
5358
5334
  * @date 2022年5月7日
5359
5335
  * @param {Date|string} [date] - 日期对象或日期字符串
5360
5336
  * @returns {number} 分钟数(0-59)
5361
- */
5362
- const getMinute = function (date) {
5363
- if (!date) {
5364
- return new Date().getMinutes();
5365
- }
5366
- if (typeof date === 'string') {
5367
- date = new Date(date);
5368
- }
5369
- return date.getMinutes();
5370
- };
5371
-
5337
+ */
5338
+ var getMinute = function getMinute(date) {
5339
+ if (!date) {
5340
+ return new Date().getMinutes();
5341
+ }
5342
+ if (typeof date === 'string') {
5343
+ date = new Date(date);
5344
+ }
5345
+ return date.getMinutes();
5346
+ };
5347
+
5372
5348
  /**
5373
5349
  * 获取月份
5374
5350
  * @date 2022年5月7日
5375
5351
  * @param {Date|string} [date] - 日期对象或日期字符串
5376
5352
  * @returns {number} 月份数(1-12)
5377
- */
5378
- const getMonth = function (date) {
5379
- if (!date) {
5380
- return new Date().getMonth() + 1;
5381
- }
5382
- if (typeof date === 'string') {
5383
- date = new Date(date);
5384
- }
5385
- return date.getMonth() + 1;
5386
- };
5387
-
5353
+ */
5354
+ var getMonth = function getMonth(date) {
5355
+ if (!date) {
5356
+ return new Date().getMonth() + 1;
5357
+ }
5358
+ if (typeof date === 'string') {
5359
+ date = new Date(date);
5360
+ }
5361
+ return date.getMonth() + 1;
5362
+ };
5363
+
5388
5364
  /**
5389
5365
  * 获取秒
5390
5366
  * @date 2022年5月7日
5391
5367
  * @param {Date|string} [date] - 日期对象或日期字符串
5392
5368
  * @returns {number} 秒数(0-59)
5393
- */
5394
- const getSecond = function (date) {
5395
- if (!date) {
5396
- return new Date().getSeconds();
5397
- }
5398
- if (typeof date === 'string') {
5399
- date = new Date(date);
5400
- }
5401
- return date.getSeconds();
5402
- };
5403
-
5369
+ */
5370
+ var getSecond = function getSecond(date) {
5371
+ if (!date) {
5372
+ return new Date().getSeconds();
5373
+ }
5374
+ if (typeof date === 'string') {
5375
+ date = new Date(date);
5376
+ }
5377
+ return date.getSeconds();
5378
+ };
5379
+
5404
5380
  /**
5405
5381
  * 获取星期几
5406
5382
  * @date 2022年5月7日
5407
5383
  * @param {Date|string} [date] - 日期对象或日期字符串
5408
5384
  * @returns {number} 星期几(0-6,0表示星期日)
5409
- */
5410
- const getWeekday = function (date) {
5411
- if (!date) {
5412
- return new Date().getDay();
5413
- }
5414
- if (typeof date === 'string') {
5415
- date = new Date(date);
5416
- }
5417
- return date.getDay();
5418
- };
5419
-
5420
-
5385
+ */
5386
+ var getWeekday = function getWeekday(date) {
5387
+ if (!date) {
5388
+ return new Date().getDay();
5389
+ }
5390
+ if (typeof date === 'string') {
5391
+ date = new Date(date);
5392
+ }
5393
+ return date.getDay();
5394
+ };
5395
+
5421
5396
  /**
5422
5397
  * @desc 获取上午/下午/晚上
5423
5398
  * @author huangbo
5424
5399
  * @date 2022年5月7日
5425
5400
  * @param {String} [time] - 时间
5426
- **/
5427
- const timeCycle = function (time) {
5428
- let hour = 0;
5429
- if (!time) {
5430
- hour = new Date().getHours();
5431
- } else if (typeof time === 'string') {
5432
- // 从时间字符串中提取小时
5433
- const match = time.match(/^(\d{1,2})/);
5434
- if (match) {
5435
- hour = parseInt(match[1], 10);
5436
- }
5437
- } else if (typeof time === 'number') {
5438
- hour = time;
5439
- }
5440
- // 判断时间段
5441
- if (hour >= 5 && hour < 12) {
5442
- return '上午';
5443
- } else if (hour >= 12 && hour < 18) {
5444
- return '下午';
5445
- } else {
5446
- return '晚上';
5447
- }
5401
+ **/
5402
+ var timeCycle = function timeCycle(time) {
5403
+ var hour = 0;
5404
+ if (!time) {
5405
+ hour = new Date().getHours();
5406
+ } else if (typeof time === 'string') {
5407
+ // 从时间字符串中提取小时
5408
+ var match = time.match(/^(\d{1,2})/);
5409
+ if (match) {
5410
+ hour = parseInt(match[1], 10);
5411
+ }
5412
+ } else if (typeof time === 'number') {
5413
+ hour = time;
5414
+ }
5415
+ // 判断时间段
5416
+ if (hour >= 5 && hour < 12) {
5417
+ return '上午';
5418
+ } else if (hour >= 12 && hour < 18) {
5419
+ return '下午';
5420
+ } else {
5421
+ return '晚上';
5422
+ }
5448
5423
  };
5449
5424
 
5450
5425
  /***/ }),