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/tree-group.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 = 263);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 270);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3535,7 +3535,7 @@ module.exports = require("eoss/lib/form");
3535
3535
 
3536
3536
  /***/ }),
3537
3537
 
3538
- /***/ 263:
3538
+ /***/ 270:
3539
3539
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3540
3540
 
3541
3541
  "use strict";
@@ -3761,7 +3761,7 @@ var api = __webpack_require__(6);
3761
3761
  var external_throttle_debounce_ = __webpack_require__(24);
3762
3762
 
3763
3763
  // EXTERNAL MODULE: external "eoss/lib/data-table"
3764
- var data_table_ = __webpack_require__(47);
3764
+ var data_table_ = __webpack_require__(48);
3765
3765
  var data_table_default = /*#__PURE__*/__webpack_require__.n(data_table_);
3766
3766
 
3767
3767
  // EXTERNAL MODULE: external "eoss/lib/form"
@@ -3769,19 +3769,19 @@ var form_ = __webpack_require__(25);
3769
3769
  var form_default = /*#__PURE__*/__webpack_require__.n(form_);
3770
3770
 
3771
3771
  // EXTERNAL MODULE: external "eoss/lib/selector"
3772
- var selector_ = __webpack_require__(66);
3772
+ var selector_ = __webpack_require__(67);
3773
3773
  var selector_default = /*#__PURE__*/__webpack_require__.n(selector_);
3774
3774
 
3775
3775
  // EXTERNAL MODULE: external "eoss/lib/tab-pane"
3776
- var tab_pane_ = __webpack_require__(59);
3776
+ var tab_pane_ = __webpack_require__(60);
3777
3777
  var tab_pane_default = /*#__PURE__*/__webpack_require__.n(tab_pane_);
3778
3778
 
3779
3779
  // EXTERNAL MODULE: external "eoss/lib/tabs"
3780
- var tabs_ = __webpack_require__(55);
3780
+ var tabs_ = __webpack_require__(57);
3781
3781
  var tabs_default = /*#__PURE__*/__webpack_require__.n(tabs_);
3782
3782
 
3783
3783
  // EXTERNAL MODULE: external "eoss/lib/tree"
3784
- var tree_ = __webpack_require__(50);
3784
+ var tree_ = __webpack_require__(51);
3785
3785
  var tree_default = /*#__PURE__*/__webpack_require__.n(tree_);
3786
3786
 
3787
3787
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/tree-group/src/tree-group.vue?vue&type=script&lang=js&
@@ -4641,34 +4641,27 @@ function normalizeComponent(
4641
4641
 
4642
4642
  /***/ }),
4643
4643
 
4644
- /***/ 47:
4644
+ /***/ 48:
4645
4645
  /***/ (function(module, exports) {
4646
4646
 
4647
4647
  module.exports = require("eoss/lib/data-table");
4648
4648
 
4649
4649
  /***/ }),
4650
4650
 
4651
- /***/ 50:
4651
+ /***/ 51:
4652
4652
  /***/ (function(module, exports) {
4653
4653
 
4654
4654
  module.exports = require("eoss/lib/tree");
4655
4655
 
4656
4656
  /***/ }),
4657
4657
 
4658
- /***/ 55:
4658
+ /***/ 57:
4659
4659
  /***/ (function(module, exports) {
4660
4660
 
4661
4661
  module.exports = require("eoss/lib/tabs");
4662
4662
 
4663
4663
  /***/ }),
4664
4664
 
4665
- /***/ 59:
4666
- /***/ (function(module, exports) {
4667
-
4668
- module.exports = require("eoss/lib/tab-pane");
4669
-
4670
- /***/ }),
4671
-
4672
4665
  /***/ 6:
4673
4666
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4674
4667
 
@@ -5242,7 +5235,14 @@ var changeInTime = '/baseIssueRules/changeInTime';
5242
5235
 
5243
5236
  /***/ }),
5244
5237
 
5245
- /***/ 66:
5238
+ /***/ 60:
5239
+ /***/ (function(module, exports) {
5240
+
5241
+ module.exports = require("eoss/lib/tab-pane");
5242
+
5243
+ /***/ }),
5244
+
5245
+ /***/ 67:
5246
5246
  /***/ (function(module, exports) {
5247
5247
 
5248
5248
  module.exports = require("eoss/lib/selector");
@@ -5299,759 +5299,736 @@ module.exports = require("eoss/lib/selector");
5299
5299
  /* unused harmony export getSecond */
5300
5300
  /* unused harmony export getWeekday */
5301
5301
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
5302
- /* Modified from https://github.com/taylorhakes/fecha
5303
- *
5304
- * The MIT License (MIT)
5305
- *
5306
- * Copyright (c) 2015 Taylor Hakes
5307
- *
5308
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5309
- * of this software and associated documentation files (the "Software"), to deal
5310
- * in the Software without restriction, including without limitation the rights
5311
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5312
- * copies of the Software, and to permit persons to whom the Software is
5313
- * furnished to do so, subject to the following conditions:
5314
- *
5315
- * The above copyright notice and this permission notice shall be included in all
5316
- * copies or substantial portions of the Software.
5317
- *
5318
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5319
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5320
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5321
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5322
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5323
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5324
- * SOFTWARE.
5325
- */
5326
-
5327
- /*eslint-disable*/
5328
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
5329
-
5330
-
5302
+
5303
+
5331
5304
  /**
5332
5305
  * Parse or format dates
5333
5306
  * @class fecha
5334
- */
5335
- const fecha = {};
5336
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5337
- const twoDigits = '\\d\\d?';
5338
- const threeDigits = '\\d{3}';
5339
- const fourDigits = '\\d{4}';
5340
- const word = '[^\\s]+';
5341
- const literal = /\[([^]*?)\]/gm;
5342
- const noop = function () {};
5343
-
5344
- function regexEscape(str) {
5345
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5346
- }
5347
-
5348
- function shorten(arr, sLen) {
5349
- const newArr = [];
5350
- for (let i = 0, len = arr.length; i < len; i++) {
5351
- newArr.push(arr[i].substr(0, sLen));
5352
- }
5353
- return newArr;
5354
- }
5355
-
5356
- function monthUpdate() {
5357
- return function (d, v) {
5358
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5359
- if (~index) {
5360
- d.month = index;
5361
- }
5362
- };
5363
- }
5364
-
5365
- function pad(val, len) {
5366
- val = String(val);
5367
- len = len || 2;
5368
- while (val.length < len) {
5369
- val = '0' + val;
5370
- }
5371
- return val;
5372
- }
5373
-
5374
- // 直接使用中文日期名称常量
5375
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5376
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5377
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5378
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5379
- const amPm = ['上午', '下午'];
5380
- const DoFn = function DoFn(D) {
5381
- return D + '日';
5382
- };
5383
-
5384
- const formatFlags = {
5385
- D: function(dateObj) {
5386
- return dateObj.getDay();
5387
- },
5388
- DD: function(dateObj) {
5389
- return pad(dateObj.getDay());
5390
- },
5391
- Do: function(dateObj) {
5392
- return DoFn(dateObj.getDate());
5393
- },
5394
- d: function(dateObj) {
5395
- return dateObj.getDate();
5396
- },
5397
- dd: function(dateObj) {
5398
- return pad(dateObj.getDate());
5399
- },
5400
- ddd: function(dateObj) {
5401
- return dayNamesShort[dateObj.getDay()];
5402
- },
5403
- dddd: function(dateObj) {
5404
- return dayNames[dateObj.getDay()];
5405
- },
5406
- M: function(dateObj) {
5407
- return dateObj.getMonth() + 1;
5408
- },
5409
- MM: function(dateObj) {
5410
- return pad(dateObj.getMonth() + 1);
5411
- },
5412
- MMM: function(dateObj) {
5413
- return monthNamesShort[dateObj.getMonth()];
5414
- },
5415
- MMMM: function(dateObj) {
5416
- return monthNames[dateObj.getMonth()];
5417
- },
5418
- yy: function(dateObj) {
5419
- return pad(String(dateObj.getFullYear()), 4).substr(2);
5420
- },
5421
- yyyy: function(dateObj) {
5422
- return pad(dateObj.getFullYear(), 4);
5423
- },
5424
- h: function(dateObj) {
5425
- return dateObj.getHours() % 12 || 12;
5426
- },
5427
- hh: function(dateObj) {
5428
- return pad(dateObj.getHours() % 12 || 12);
5429
- },
5430
- H: function(dateObj) {
5431
- return dateObj.getHours();
5432
- },
5433
- HH: function(dateObj) {
5434
- return pad(dateObj.getHours());
5435
- },
5436
- m: function(dateObj) {
5437
- return dateObj.getMinutes();
5438
- },
5439
- mm: function(dateObj) {
5440
- return pad(dateObj.getMinutes());
5441
- },
5442
- s: function(dateObj) {
5443
- return dateObj.getSeconds();
5444
- },
5445
- ss: function(dateObj) {
5446
- return pad(dateObj.getSeconds());
5447
- },
5448
- S: function(dateObj) {
5449
- return Math.round(dateObj.getMilliseconds() / 100);
5450
- },
5451
- SS: function(dateObj) {
5452
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5453
- },
5454
- SSS: function(dateObj) {
5455
- return pad(dateObj.getMilliseconds(), 3);
5456
- },
5457
- a: function(dateObj) {
5458
- return dateObj.getHours() < 12 ? '上午' : '下午';
5459
- },
5460
- A: function(dateObj) {
5461
- return dateObj.getHours() < 12 ? '上午' : '下午';
5462
- },
5463
- ZZ: function(dateObj) {
5464
- const o = dateObj.getTimezoneOffset();
5465
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5466
- }
5467
- };
5468
-
5469
- const parseFlags = {
5470
- d: [twoDigits, function (d, v) {
5471
- d.day = v;
5472
- }],
5473
- Do: [twoDigits + word, function (d, v) {
5474
- d.day = parseInt(v, 10);
5475
- }],
5476
- M: [twoDigits, function (d, v) {
5477
- d.month = v - 1;
5478
- }],
5479
- yy: [twoDigits, function (d, v) {
5480
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
5481
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5482
- }],
5483
- h: [twoDigits, function (d, v) {
5484
- d.hour = v;
5485
- }],
5486
- m: [twoDigits, function (d, v) {
5487
- d.minute = v;
5488
- }],
5489
- s: [twoDigits, function (d, v) {
5490
- d.second = v;
5491
- }],
5492
- yyyy: [fourDigits, function (d, v) {
5493
- d.year = v;
5494
- }],
5495
- S: ['\\d', function (d, v) {
5496
- d.millisecond = v * 100;
5497
- }],
5498
- SS: ['\\d{2}', function (d, v) {
5499
- d.millisecond = v * 10;
5500
- }],
5501
- SSS: [threeDigits, function (d, v) {
5502
- d.millisecond = v;
5503
- }],
5504
- D: [twoDigits, noop],
5505
- ddd: [word, noop],
5506
- MMM: [word, monthUpdate('monthNamesShort')],
5507
- MMMM: [word, monthUpdate('monthNames')],
5508
- a: [word, function (d, v) {
5509
- const val = v.toLowerCase();
5510
- if (val === '上午') {
5511
- d.isPm = false;
5512
- } else if (val === '下午') {
5513
- d.isPm = true;
5514
- }
5515
- }],
5516
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5517
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
5518
-
5519
- if (parts) {
5520
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5521
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5522
- }
5523
- }]
5524
- };
5525
- parseFlags.dd = parseFlags.d;
5526
- parseFlags.dddd = parseFlags.ddd;
5527
- parseFlags.DD = parseFlags.D;
5528
- parseFlags.mm = parseFlags.m;
5529
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5530
- parseFlags.MM = parseFlags.M;
5531
- parseFlags.ss = parseFlags.s;
5532
- parseFlags.A = parseFlags.a;
5533
-
5534
-
5535
- // Some common format strings
5536
- fecha.masks = {
5537
- default: 'ddd MMM dd yyyy HH:mm:ss',
5538
- shortDate: 'M/D/yy',
5539
- mediumDate: 'MMM d, yyyy',
5540
- longDate: 'MMMM d, yyyy',
5541
- fullDate: 'dddd, MMMM d, yyyy',
5542
- shortTime: 'HH:mm',
5543
- mediumTime: 'HH:mm:ss',
5544
- longTime: 'HH:mm:ss.SSS'
5545
- };
5546
-
5307
+ */
5308
+ var fecha = {};
5309
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5310
+ var twoDigits = '\\d\\d?';
5311
+ var threeDigits = '\\d{3}';
5312
+ var fourDigits = '\\d{4}';
5313
+ var word = '[^\\s]+';
5314
+ var literal = /\[([^]*?)\]/gm;
5315
+ var noop = function noop() {};
5316
+
5317
+ function regexEscape(str) {
5318
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5319
+ }
5320
+
5321
+ function shorten(arr, sLen) {
5322
+ var newArr = [];
5323
+ for (var i = 0, len = arr.length; i < len; i++) {
5324
+ newArr.push(arr[i].substr(0, sLen));
5325
+ }
5326
+ return newArr;
5327
+ }
5328
+
5329
+ function monthUpdate() {
5330
+ return function (d, v) {
5331
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5332
+ if (~index) {
5333
+ d.month = index;
5334
+ }
5335
+ };
5336
+ }
5337
+
5338
+ function pad(val, len) {
5339
+ val = String(val);
5340
+ len = len || 2;
5341
+ while (val.length < len) {
5342
+ val = '0' + val;
5343
+ }
5344
+ return val;
5345
+ }
5346
+
5347
+ // 直接使用中文日期名称常量
5348
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5349
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5350
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5351
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5352
+ var amPm = ['上午', '下午'];
5353
+ var DoFn = function DoFn(D) {
5354
+ return D + '日';
5355
+ };
5356
+
5357
+ var formatFlags = {
5358
+ D: function D(dateObj) {
5359
+ return dateObj.getDay();
5360
+ },
5361
+ DD: function DD(dateObj) {
5362
+ return pad(dateObj.getDay());
5363
+ },
5364
+ Do: function Do(dateObj) {
5365
+ return DoFn(dateObj.getDate());
5366
+ },
5367
+ d: function d(dateObj) {
5368
+ return dateObj.getDate();
5369
+ },
5370
+ dd: function dd(dateObj) {
5371
+ return pad(dateObj.getDate());
5372
+ },
5373
+ ddd: function ddd(dateObj) {
5374
+ return dayNamesShort[dateObj.getDay()];
5375
+ },
5376
+ dddd: function dddd(dateObj) {
5377
+ return dayNames[dateObj.getDay()];
5378
+ },
5379
+ M: function M(dateObj) {
5380
+ return dateObj.getMonth() + 1;
5381
+ },
5382
+ MM: function MM(dateObj) {
5383
+ return pad(dateObj.getMonth() + 1);
5384
+ },
5385
+ MMM: function MMM(dateObj) {
5386
+ return monthNamesShort[dateObj.getMonth()];
5387
+ },
5388
+ MMMM: function MMMM(dateObj) {
5389
+ return monthNames[dateObj.getMonth()];
5390
+ },
5391
+ yy: function yy(dateObj) {
5392
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
5393
+ },
5394
+ yyyy: function yyyy(dateObj) {
5395
+ return pad(dateObj.getFullYear(), 4);
5396
+ },
5397
+ h: function h(dateObj) {
5398
+ return dateObj.getHours() % 12 || 12;
5399
+ },
5400
+ hh: function hh(dateObj) {
5401
+ return pad(dateObj.getHours() % 12 || 12);
5402
+ },
5403
+ H: function H(dateObj) {
5404
+ return dateObj.getHours();
5405
+ },
5406
+ HH: function HH(dateObj) {
5407
+ return pad(dateObj.getHours());
5408
+ },
5409
+ m: function m(dateObj) {
5410
+ return dateObj.getMinutes();
5411
+ },
5412
+ mm: function mm(dateObj) {
5413
+ return pad(dateObj.getMinutes());
5414
+ },
5415
+ s: function s(dateObj) {
5416
+ return dateObj.getSeconds();
5417
+ },
5418
+ ss: function ss(dateObj) {
5419
+ return pad(dateObj.getSeconds());
5420
+ },
5421
+ S: function S(dateObj) {
5422
+ return Math.round(dateObj.getMilliseconds() / 100);
5423
+ },
5424
+ SS: function SS(dateObj) {
5425
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5426
+ },
5427
+ SSS: function SSS(dateObj) {
5428
+ return pad(dateObj.getMilliseconds(), 3);
5429
+ },
5430
+ a: function a(dateObj) {
5431
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5432
+ },
5433
+ A: function A(dateObj) {
5434
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5435
+ },
5436
+ ZZ: function ZZ(dateObj) {
5437
+ var o = dateObj.getTimezoneOffset();
5438
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5439
+ }
5440
+ };
5441
+
5442
+ var parseFlags = {
5443
+ d: [twoDigits, function (d, v) {
5444
+ d.day = v;
5445
+ }],
5446
+ Do: [twoDigits + word, function (d, v) {
5447
+ d.day = parseInt(v, 10);
5448
+ }],
5449
+ M: [twoDigits, function (d, v) {
5450
+ d.month = v - 1;
5451
+ }],
5452
+ yy: [twoDigits, function (d, v) {
5453
+ var da = new Date(),
5454
+ cent = +('' + da.getFullYear()).substr(0, 2);
5455
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5456
+ }],
5457
+ h: [twoDigits, function (d, v) {
5458
+ d.hour = v;
5459
+ }],
5460
+ m: [twoDigits, function (d, v) {
5461
+ d.minute = v;
5462
+ }],
5463
+ s: [twoDigits, function (d, v) {
5464
+ d.second = v;
5465
+ }],
5466
+ yyyy: [fourDigits, function (d, v) {
5467
+ d.year = v;
5468
+ }],
5469
+ S: ['\\d', function (d, v) {
5470
+ d.millisecond = v * 100;
5471
+ }],
5472
+ SS: ['\\d{2}', function (d, v) {
5473
+ d.millisecond = v * 10;
5474
+ }],
5475
+ SSS: [threeDigits, function (d, v) {
5476
+ d.millisecond = v;
5477
+ }],
5478
+ D: [twoDigits, noop],
5479
+ ddd: [word, noop],
5480
+ MMM: [word, monthUpdate('monthNamesShort')],
5481
+ MMMM: [word, monthUpdate('monthNames')],
5482
+ a: [word, function (d, v) {
5483
+ var val = v.toLowerCase();
5484
+ if (val === '上午') {
5485
+ d.isPm = false;
5486
+ } else if (val === '下午') {
5487
+ d.isPm = true;
5488
+ }
5489
+ }],
5490
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5491
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
5492
+ minutes = void 0;
5493
+
5494
+ if (parts) {
5495
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5496
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5497
+ }
5498
+ }]
5499
+ };
5500
+ parseFlags.dd = parseFlags.d;
5501
+ parseFlags.dddd = parseFlags.ddd;
5502
+ parseFlags.DD = parseFlags.D;
5503
+ parseFlags.mm = parseFlags.m;
5504
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5505
+ parseFlags.MM = parseFlags.M;
5506
+ parseFlags.ss = parseFlags.s;
5507
+ parseFlags.A = parseFlags.a;
5508
+
5509
+ // Some common format strings
5510
+ fecha.masks = {
5511
+ default: 'ddd MMM dd yyyy HH:mm:ss',
5512
+ shortDate: 'M/D/yy',
5513
+ mediumDate: 'MMM d, yyyy',
5514
+ longDate: 'MMMM d, yyyy',
5515
+ fullDate: 'dddd, MMMM d, yyyy',
5516
+ shortTime: 'HH:mm',
5517
+ mediumTime: 'HH:mm:ss',
5518
+ longTime: 'HH:mm:ss.SSS'
5519
+ };
5520
+
5547
5521
  /***
5548
5522
  * Format a date
5549
5523
  * @method format
5550
5524
  * @param {Date|number} dateObj
5551
5525
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
5552
- */
5553
- fecha.format = function (dateObj, mask) {
5554
- if (typeof dateObj === 'number') {
5555
- dateObj = new Date(dateObj);
5556
- }
5557
-
5558
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5559
- throw new Error('Invalid Date in fecha.format');
5560
- }
5561
-
5562
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
5563
-
5564
- const literals = [];
5565
-
5566
- // Make literals inactive by replacing them with ??
5567
- mask = mask.replace(literal, function($0, $1) {
5568
- literals.push($1);
5569
- return '@@@';
5570
- });
5571
- // Apply formatting rules
5572
- mask = mask.replace(token, function ($0) {
5573
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5574
- });
5575
- // Inline literal values back into the formatted value
5576
- return mask.replace(/@@@/g, function() {
5577
- return literals.shift();
5578
- });
5579
- };
5580
-
5526
+ */
5527
+ fecha.format = function (dateObj, mask) {
5528
+ if (typeof dateObj === 'number') {
5529
+ dateObj = new Date(dateObj);
5530
+ }
5531
+
5532
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5533
+ throw new Error('Invalid Date in fecha.format');
5534
+ }
5535
+
5536
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
5537
+
5538
+ var literals = [];
5539
+
5540
+ // Make literals inactive by replacing them with ??
5541
+ mask = mask.replace(literal, function ($0, $1) {
5542
+ literals.push($1);
5543
+ return '@@@';
5544
+ });
5545
+ // Apply formatting rules
5546
+ mask = mask.replace(token, function ($0) {
5547
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5548
+ });
5549
+ // Inline literal values back into the formatted value
5550
+ return mask.replace(/@@@/g, function () {
5551
+ return literals.shift();
5552
+ });
5553
+ };
5554
+
5581
5555
  /**
5582
5556
  * Parse a date string into an object, changes - into /
5583
5557
  * @method parse
5584
5558
  * @param {string} dateStr Date string
5585
5559
  * @param {string} format Date parse format
5586
5560
  * @returns {Date|boolean}
5587
- */
5588
- fecha.parse = function (dateStr, format) {
5589
- if (typeof format !== 'string') {
5590
- throw new Error('Invalid format in fecha.parse');
5591
- }
5592
-
5593
- format = fecha.masks[format] || format;
5594
-
5595
- // Avoid regular expression denial of service, fail early for really long strings
5596
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5597
- if (dateStr.length > 1000) {
5598
- return null;
5599
- }
5600
-
5601
- const dateInfo = {};
5602
- const parseInfo = [];
5603
- const literals = [];
5604
- format = format.replace(literal, function($0, $1) {
5605
- literals.push($1);
5606
- return '@@@';
5607
- });
5608
- let newFormat = regexEscape(format).replace(token, function ($0) {
5609
- if (parseFlags[$0]) {
5610
- const info = parseFlags[$0];
5611
- parseInfo.push(info[1]);
5612
- return '(' + info[0] + ')';
5613
- }
5614
-
5615
- return $0;
5616
- });
5617
- newFormat = newFormat.replace(/@@@/g, function() {
5618
- return literals.shift();
5619
- });
5620
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
5621
- if (!matches) {
5622
- return null;
5623
- }
5624
-
5625
- for (let i = 1; i < matches.length; i++) {
5626
- parseInfo[i - 1](dateInfo, matches[i]);
5627
- }
5628
-
5629
- const today = new Date();
5630
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5631
- dateInfo.hour = +dateInfo.hour + 12;
5632
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5633
- dateInfo.hour = 0;
5634
- }
5635
-
5636
- let date;
5637
- if (dateInfo.timezoneOffset != null) {
5638
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5639
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5640
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
5641
- } else {
5642
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5643
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
5644
- }
5645
- return date;
5646
- };
5647
-
5648
- // 导出fecha对象
5649
-
5650
-
5651
- // 以下是从date-util.js合并的函数
5652
- const newArray = function(start, end) {
5653
- let result = [];
5654
- for (let i = start; i <= end; i++) {
5655
- result.push(i);
5656
- }
5657
- return result;
5658
- };
5659
-
5660
- const getSettings = () => {
5661
- return {
5662
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5663
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5664
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5665
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5666
- amPm: ['上午', '下午']
5667
- };
5668
- };
5669
-
5670
- const toDate = function(date) {
5671
- return isDate(date) ? new Date(date) : null;
5672
- };
5673
-
5674
- const isDate = function(date) {
5675
- if (date === null || date === undefined) return false;
5676
- if (isNaN(new Date(date).getTime())) return false;
5677
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5678
- return true;
5679
- };
5680
-
5681
- const isDateObject = function(val) {
5682
- return val instanceof Date;
5683
- };
5684
-
5685
- const formatDate = function (date, format = 'yyyy-MM-dd') {
5686
- // 处理多种输入类型
5687
- if (!date) return '';
5688
-
5689
- // 如果是时间戳,转成日期对象
5690
- if (typeof date === 'number') {
5691
- date = new Date(date);
5692
- }
5693
- // 如果是字符串,转成日期对象
5694
- if (typeof date === 'string') {
5695
- date = new Date(date);
5696
- }
5697
-
5698
- // 调用toDate进一步验证和转换
5699
- date = toDate(date);
5700
- if (!date) return '';
5701
-
5702
- // 兼容大写和小写的格式标记
5703
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5704
- const lowercaseFormat = format
5705
- .replace(/YYYY/g, 'yyyy')
5706
- .replace(/D/g, 'd')
5707
-
5708
- // 使用fecha库进行格式化,支持中文配置
5709
- const str = fecha.format(date, lowercaseFormat, getSettings());
5710
- return str;
5711
- };
5712
-
5713
- const parseDate = function(string, format) {
5714
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5715
- };
5716
-
5717
- const getDayCountOfMonth = function(year, month) {
5718
- if (month === 3 || month === 5 || month === 8 || month === 10) {
5719
- return 30;
5720
- }
5721
-
5722
- if (month === 1) {
5723
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5724
- return 29;
5725
- } else {
5726
- return 28;
5727
- }
5728
- }
5729
-
5730
- return 31;
5731
- };
5732
-
5733
- const getDayCountOfYear = function(year) {
5734
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
5735
- return isLeapYear ? 366 : 365;
5736
- };
5737
-
5738
- const getFirstDayOfMonth = function(date) {
5739
- const temp = new Date(date.getTime());
5740
- temp.setDate(1);
5741
- return temp.getDay();
5742
- };
5743
-
5744
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5745
- // {prev, next} Date should work for Daylight Saving Time
5746
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5747
- const prevDate = function(date, amount = 1) {
5748
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5749
- };
5750
-
5751
- const nextDate = function(date, amount = 1) {
5752
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5753
- };
5754
-
5755
- const getStartDateOfMonth = function(year, month) {
5756
- const result = new Date(year, month, 1);
5757
- const day = result.getDay();
5758
-
5759
- if (day === 0) {
5760
- return prevDate(result, 7);
5761
- } else {
5762
- return prevDate(result, day);
5763
- }
5764
- };
5765
-
5766
- const getWeekNumber = function(date) {
5767
- // 支持多种输入类型
5768
- if (!date||!isDate(date)) {
5769
- date = new Date();
5770
- }
5771
- if (typeof date === 'string') {
5772
- date = new Date(date);
5773
- }
5774
-
5775
- // 验证日期有效性
5776
- if (!isDate(date)) return null;
5777
-
5778
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5779
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5780
- // 将星期日的星期数设为7
5781
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5782
- // 获取当年的第一天
5783
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5784
- // 计算到最近的星期四的完整周数
5785
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
5786
- // 返回周数
5787
- return weekNo;
5788
- };
5789
-
5790
- const getRangeHours = function(ranges) {
5791
- const hours = [];
5792
- let disabledHours = [];
5793
-
5794
- (ranges || []).forEach(range => {
5795
- const value = range.map(date => date.getHours());
5796
-
5797
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5798
- });
5799
-
5800
- if (disabledHours.length) {
5801
- for (let i = 0; i < 24; i++) {
5802
- hours[i] = disabledHours.indexOf(i) === -1;
5803
- }
5804
- } else {
5805
- for (let i = 0; i < 24; i++) {
5806
- hours[i] = false;
5807
- }
5808
- }
5809
-
5810
- return hours;
5811
- };
5812
-
5813
- const getPrevMonthLastDays = (date, amount) => {
5814
- if (amount <= 0) return [];
5815
- const temp = new Date(date.getTime());
5816
- temp.setDate(0);
5817
- const lastDay = temp.getDate();
5818
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
5819
- };
5820
-
5821
- const getMonthDays = (date) => {
5822
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5823
- const days = temp.getDate();
5824
- return range(days).map((_, index) => index + 1);
5825
- };
5826
-
5827
- function setRangeData(arr, start, end, value) {
5828
- for (let i = start; i < end; i++) {
5829
- arr[i] = value;
5830
- }
5831
- }
5832
-
5833
- const getRangeMinutes = function(ranges, hour) {
5834
- const minutes = new Array(60);
5835
-
5836
- if (ranges.length > 0) {
5837
- ranges.forEach(range => {
5838
- const start = range[0];
5839
- const end = range[1];
5840
- const startHour = start.getHours();
5841
- const startMinute = start.getMinutes();
5842
- const endHour = end.getHours();
5843
- const endMinute = end.getMinutes();
5844
- if (startHour === hour && endHour !== hour) {
5845
- setRangeData(minutes, startMinute, 60, true);
5846
- } else if (startHour === hour && endHour === hour) {
5847
- setRangeData(minutes, startMinute, endMinute + 1, true);
5848
- } else if (startHour !== hour && endHour === hour) {
5849
- setRangeData(minutes, 0, endMinute + 1, true);
5850
- } else if (startHour < hour && endHour > hour) {
5851
- setRangeData(minutes, 0, 60, true);
5852
- }
5853
- });
5854
- } else {
5855
- setRangeData(minutes, 0, 60, true);
5856
- }
5857
- return minutes;
5858
- };
5859
-
5860
- const range = function(n) {
5861
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5862
- return Array.apply(null, {length: n}).map((_, n) => n);
5863
- };
5864
-
5865
- const modifyDate = function(date, y, m, d) {
5866
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5867
- };
5868
-
5869
- const modifyTime = function(date, h, m, s) {
5870
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5871
- };
5872
-
5873
- const modifyWithTimeString = (date, time) => {
5874
- if (date == null || !time) {
5875
- return date;
5876
- }
5877
- time = parseDate(time, 'HH:mm:ss');
5878
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5879
- };
5880
-
5881
- const clearTime = function(date) {
5882
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5883
- };
5884
-
5885
- const clearMilliseconds = function(date) {
5886
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5887
- };
5888
-
5889
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
5890
- // TODO: refactory a more elegant solution
5891
- if (ranges.length === 0) return date;
5892
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
5893
- const ndate = normalizeDate(date);
5894
- const nranges = ranges.map(range => range.map(normalizeDate));
5895
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
5896
-
5897
- let minDate = nranges[0][0];
5898
- let maxDate = nranges[0][0];
5899
-
5900
- nranges.forEach(nrange => {
5901
- minDate = new Date(Math.min(nrange[0], minDate));
5902
- maxDate = new Date(Math.max(nrange[1], minDate));
5903
- });
5904
-
5905
- const ret = ndate < minDate ? minDate : maxDate;
5906
- // preserve Year/Month/Date
5907
- return modifyDate(
5908
- ret,
5909
- date.getFullYear(),
5910
- date.getMonth(),
5911
- date.getDate()
5912
- );
5913
- };
5914
-
5915
- const timeWithinRange = function(date, selectableRange, format) {
5916
- const limitedDate = limitTimeRange(date, selectableRange, format);
5917
- return limitedDate.getTime() === date.getTime();
5918
- };
5919
-
5920
- const changeYearMonthAndClampDate = function(date, year, month) {
5921
- // clamp date to the number of days in `year`, `month`
5922
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
5923
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5924
- return modifyDate(date, year, month, monthDate);
5925
- };
5926
-
5927
- const prevMonth = function(date) {
5928
- const year = date.getFullYear();
5929
- const month = date.getMonth();
5930
- return month === 0
5931
- ? changeYearMonthAndClampDate(date, year - 1, 11)
5932
- : changeYearMonthAndClampDate(date, year, month - 1);
5933
- };
5934
-
5935
- const nextMonth = function(date) {
5936
- const year = date.getFullYear();
5937
- const month = date.getMonth();
5938
- return month === 11
5939
- ? changeYearMonthAndClampDate(date, year + 1, 0)
5940
- : changeYearMonthAndClampDate(date, year, month + 1);
5941
- };
5942
-
5943
- const prevYear = function(date, amount = 1) {
5944
- const year = date.getFullYear();
5945
- const month = date.getMonth();
5946
- return changeYearMonthAndClampDate(date, year - amount, month);
5947
- };
5948
-
5949
- const nextYear = function(date, amount = 1) {
5950
- const year = date.getFullYear();
5951
- const month = date.getMonth();
5952
- return changeYearMonthAndClampDate(date, year + amount, month);
5953
- };
5954
-
5955
- const extractDateFormat = function(format) {
5956
- return format
5957
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
5958
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
5959
- .trim();
5960
- };
5961
-
5962
- const extractTimeFormat = function(format) {
5963
- return format
5964
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
5965
- .trim();
5966
- };
5967
-
5968
- const validateRangeInOneMonth = function(start, end) {
5969
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
5970
- };
5971
-
5561
+ */
5562
+ fecha.parse = function (dateStr, format) {
5563
+ if (typeof format !== 'string') {
5564
+ throw new Error('Invalid format in fecha.parse');
5565
+ }
5566
+
5567
+ format = fecha.masks[format] || format;
5568
+
5569
+ // Avoid regular expression denial of service, fail early for really long strings
5570
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5571
+ if (dateStr.length > 1000) {
5572
+ return null;
5573
+ }
5574
+
5575
+ var dateInfo = {};
5576
+ var parseInfo = [];
5577
+ var literals = [];
5578
+ format = format.replace(literal, function ($0, $1) {
5579
+ literals.push($1);
5580
+ return '@@@';
5581
+ });
5582
+ var newFormat = regexEscape(format).replace(token, function ($0) {
5583
+ if (parseFlags[$0]) {
5584
+ var info = parseFlags[$0];
5585
+ parseInfo.push(info[1]);
5586
+ return '(' + info[0] + ')';
5587
+ }
5588
+
5589
+ return $0;
5590
+ });
5591
+ newFormat = newFormat.replace(/@@@/g, function () {
5592
+ return literals.shift();
5593
+ });
5594
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
5595
+ if (!matches) {
5596
+ return null;
5597
+ }
5598
+
5599
+ for (var i = 1; i < matches.length; i++) {
5600
+ parseInfo[i - 1](dateInfo, matches[i]);
5601
+ }
5602
+
5603
+ var today = new Date();
5604
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5605
+ dateInfo.hour = +dateInfo.hour + 12;
5606
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5607
+ dateInfo.hour = 0;
5608
+ }
5609
+
5610
+ var date = void 0;
5611
+ if (dateInfo.timezoneOffset != null) {
5612
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5613
+ 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));
5614
+ } else {
5615
+ 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);
5616
+ }
5617
+ return date;
5618
+ };
5619
+
5620
+ // 导出fecha对象
5621
+
5622
+
5623
+ // 以下是从date-util.js合并的函数
5624
+ var newArray = function newArray(start, end) {
5625
+ var result = [];
5626
+ for (var i = start; i <= end; i++) {
5627
+ result.push(i);
5628
+ }
5629
+ return result;
5630
+ };
5631
+
5632
+ var getSettings = function getSettings() {
5633
+ return {
5634
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5635
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5636
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5637
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5638
+ amPm: ['上午', '下午']
5639
+ };
5640
+ };
5641
+
5642
+ var toDate = function toDate(date) {
5643
+ return isDate(date) ? new Date(date) : null;
5644
+ };
5645
+
5646
+ var isDate = function isDate(date) {
5647
+ if (date === null || date === undefined) return false;
5648
+ if (isNaN(new Date(date).getTime())) return false;
5649
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5650
+ return true;
5651
+ };
5652
+
5653
+ var isDateObject = function isDateObject(val) {
5654
+ return val instanceof Date;
5655
+ };
5656
+
5657
+ var formatDate = function formatDate(date) {
5658
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
5659
+
5660
+ // 处理多种输入类型
5661
+ if (!date) return '';
5662
+
5663
+ // 如果是时间戳,转成日期对象
5664
+ if (typeof date === 'number') {
5665
+ date = new Date(date);
5666
+ }
5667
+ // 如果是字符串,转成日期对象
5668
+ if (typeof date === 'string') {
5669
+ date = new Date(date);
5670
+ }
5671
+
5672
+ // 调用toDate进一步验证和转换
5673
+ date = toDate(date);
5674
+ if (!date) return '';
5675
+
5676
+ // 兼容大写和小写的格式标记
5677
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5678
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
5679
+
5680
+ // 使用fecha库进行格式化,支持中文配置
5681
+ var str = fecha.format(date, lowercaseFormat, getSettings());
5682
+ return str;
5683
+ };
5684
+
5685
+ var parseDate = function parseDate(string, format) {
5686
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5687
+ };
5688
+
5689
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
5690
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
5691
+ return 30;
5692
+ }
5693
+
5694
+ if (month === 1) {
5695
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5696
+ return 29;
5697
+ } else {
5698
+ return 28;
5699
+ }
5700
+ }
5701
+
5702
+ return 31;
5703
+ };
5704
+
5705
+ var getDayCountOfYear = function getDayCountOfYear(year) {
5706
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
5707
+ return isLeapYear ? 366 : 365;
5708
+ };
5709
+
5710
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
5711
+ var temp = new Date(date.getTime());
5712
+ temp.setDate(1);
5713
+ return temp.getDay();
5714
+ };
5715
+
5716
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5717
+ // {prev, next} Date should work for Daylight Saving Time
5718
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5719
+ var prevDate = function prevDate(date) {
5720
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5721
+
5722
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5723
+ };
5724
+
5725
+ var nextDate = function nextDate(date) {
5726
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5727
+
5728
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5729
+ };
5730
+
5731
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
5732
+ var result = new Date(year, month, 1);
5733
+ var day = result.getDay();
5734
+
5735
+ if (day === 0) {
5736
+ return prevDate(result, 7);
5737
+ } else {
5738
+ return prevDate(result, day);
5739
+ }
5740
+ };
5741
+
5742
+ var getWeekNumber = function getWeekNumber(date) {
5743
+ // 支持多种输入类型
5744
+ if (!date || !isDate(date)) {
5745
+ date = new Date();
5746
+ }
5747
+ if (typeof date === 'string') {
5748
+ date = new Date(date);
5749
+ }
5750
+
5751
+ // 验证日期有效性
5752
+ if (!isDate(date)) return null;
5753
+
5754
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5755
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5756
+ // 将星期日的星期数设为7
5757
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5758
+ // 获取当年的第一天
5759
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5760
+ // 计算到最近的星期四的完整周数
5761
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
5762
+ // 返回周数
5763
+ return weekNo;
5764
+ };
5765
+
5766
+ var getRangeHours = function getRangeHours(ranges) {
5767
+ var hours = [];
5768
+ var disabledHours = [];
5769
+
5770
+ (ranges || []).forEach(function (range) {
5771
+ var value = range.map(function (date) {
5772
+ return date.getHours();
5773
+ });
5774
+
5775
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5776
+ });
5777
+
5778
+ if (disabledHours.length) {
5779
+ for (var i = 0; i < 24; i++) {
5780
+ hours[i] = disabledHours.indexOf(i) === -1;
5781
+ }
5782
+ } else {
5783
+ for (var _i = 0; _i < 24; _i++) {
5784
+ hours[_i] = false;
5785
+ }
5786
+ }
5787
+
5788
+ return hours;
5789
+ };
5790
+
5791
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
5792
+ if (amount <= 0) return [];
5793
+ var temp = new Date(date.getTime());
5794
+ temp.setDate(0);
5795
+ var lastDay = temp.getDate();
5796
+ return range(amount).map(function (_, index) {
5797
+ return lastDay - (amount - index - 1);
5798
+ });
5799
+ };
5800
+
5801
+ var getMonthDays = function getMonthDays(date) {
5802
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5803
+ var days = temp.getDate();
5804
+ return range(days).map(function (_, index) {
5805
+ return index + 1;
5806
+ });
5807
+ };
5808
+
5809
+ function setRangeData(arr, start, end, value) {
5810
+ for (var i = start; i < end; i++) {
5811
+ arr[i] = value;
5812
+ }
5813
+ }
5814
+
5815
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
5816
+ var minutes = new Array(60);
5817
+
5818
+ if (ranges.length > 0) {
5819
+ ranges.forEach(function (range) {
5820
+ var start = range[0];
5821
+ var end = range[1];
5822
+ var startHour = start.getHours();
5823
+ var startMinute = start.getMinutes();
5824
+ var endHour = end.getHours();
5825
+ var endMinute = end.getMinutes();
5826
+ if (startHour === hour && endHour !== hour) {
5827
+ setRangeData(minutes, startMinute, 60, true);
5828
+ } else if (startHour === hour && endHour === hour) {
5829
+ setRangeData(minutes, startMinute, endMinute + 1, true);
5830
+ } else if (startHour !== hour && endHour === hour) {
5831
+ setRangeData(minutes, 0, endMinute + 1, true);
5832
+ } else if (startHour < hour && endHour > hour) {
5833
+ setRangeData(minutes, 0, 60, true);
5834
+ }
5835
+ });
5836
+ } else {
5837
+ setRangeData(minutes, 0, 60, true);
5838
+ }
5839
+ return minutes;
5840
+ };
5841
+
5842
+ var range = function range(n) {
5843
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5844
+ return Array.apply(null, { length: n }).map(function (_, n) {
5845
+ return n;
5846
+ });
5847
+ };
5848
+
5849
+ var modifyDate = function modifyDate(date, y, m, d) {
5850
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5851
+ };
5852
+
5853
+ var modifyTime = function modifyTime(date, h, m, s) {
5854
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5855
+ };
5856
+
5857
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
5858
+ if (date == null || !time) {
5859
+ return date;
5860
+ }
5861
+ time = parseDate(time, 'HH:mm:ss');
5862
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5863
+ };
5864
+
5865
+ var clearTime = function clearTime(date) {
5866
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5867
+ };
5868
+
5869
+ var clearMilliseconds = function clearMilliseconds(date) {
5870
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5871
+ };
5872
+
5873
+ var limitTimeRange = function limitTimeRange(date, ranges) {
5874
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
5875
+
5876
+ // TODO: refactory a more elegant solution
5877
+ if (ranges.length === 0) return date;
5878
+ var normalizeDate = function normalizeDate(date) {
5879
+ return fecha.parse(fecha.format(date, format), format);
5880
+ };
5881
+ var ndate = normalizeDate(date);
5882
+ var nranges = ranges.map(function (range) {
5883
+ return range.map(normalizeDate);
5884
+ });
5885
+ if (nranges.some(function (nrange) {
5886
+ return ndate >= nrange[0] && ndate <= nrange[1];
5887
+ })) return date;
5888
+
5889
+ var minDate = nranges[0][0];
5890
+ var maxDate = nranges[0][0];
5891
+
5892
+ nranges.forEach(function (nrange) {
5893
+ minDate = new Date(Math.min(nrange[0], minDate));
5894
+ maxDate = new Date(Math.max(nrange[1], minDate));
5895
+ });
5896
+
5897
+ var ret = ndate < minDate ? minDate : maxDate;
5898
+ // preserve Year/Month/Date
5899
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
5900
+ };
5901
+
5902
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
5903
+ var limitedDate = limitTimeRange(date, selectableRange, format);
5904
+ return limitedDate.getTime() === date.getTime();
5905
+ };
5906
+
5907
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
5908
+ // clamp date to the number of days in `year`, `month`
5909
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
5910
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5911
+ return modifyDate(date, year, month, monthDate);
5912
+ };
5913
+
5914
+ var prevMonth = function prevMonth(date) {
5915
+ var year = date.getFullYear();
5916
+ var month = date.getMonth();
5917
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
5918
+ };
5919
+
5920
+ var nextMonth = function nextMonth(date) {
5921
+ var year = date.getFullYear();
5922
+ var month = date.getMonth();
5923
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
5924
+ };
5925
+
5926
+ var prevYear = function prevYear(date) {
5927
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5928
+
5929
+ var year = date.getFullYear();
5930
+ var month = date.getMonth();
5931
+ return changeYearMonthAndClampDate(date, year - amount, month);
5932
+ };
5933
+
5934
+ var nextYear = function nextYear(date) {
5935
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5936
+
5937
+ var year = date.getFullYear();
5938
+ var month = date.getMonth();
5939
+ return changeYearMonthAndClampDate(date, year + amount, month);
5940
+ };
5941
+
5942
+ var extractDateFormat = function extractDateFormat(format) {
5943
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
5944
+ };
5945
+
5946
+ var extractTimeFormat = function extractTimeFormat(format) {
5947
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
5948
+ };
5949
+
5950
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
5951
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
5952
+ };
5953
+
5972
5954
  /**
5973
5955
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
5974
5956
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
5975
5957
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
5976
5958
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
5977
5959
  * @returns {number} 工作日数量
5978
- */
5979
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
5980
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5981
- throw new Error(
5982
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
5983
- );
5984
- }
5985
-
5986
- const startDateObj = new Date(start_date);
5987
- const endDateObj = new Date(end_date);
5988
-
5989
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5990
- throw new Error(
5991
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
5992
- );
5993
- }
5994
-
5995
- if (startDateObj > endDateObj) {
5996
- throw new Error('Start date should be earlier than or equal to end date.');
5997
- }
5998
-
5999
- let workdays = 0;
6000
-
6001
- // Iterate through each day in the date range
6002
- for (
6003
- let currentDate = new Date(startDateObj);
6004
- currentDate <= endDateObj;
6005
- currentDate.setDate(currentDate.getDate() + 1)
6006
- ) {
6007
- // Check if the current day is a weekend (Saturday or Sunday)
6008
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
6009
-
6010
- // Check if the current day is a holiday
6011
- const isHoliday = holidays.some((holiday) => {
6012
- const holidayDate = new Date(holiday);
6013
- return currentDate.toDateString() === holidayDate.toDateString();
6014
- });
6015
-
6016
- // If it's a workday (not a weekend or holiday), increment the workdays count
6017
- if (!isWeekend && !isHoliday) {
6018
- workdays++;
6019
- }
6020
- }
6021
-
6022
- return workdays;
6023
- };
6024
-
5960
+ */
5961
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
5962
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5963
+
5964
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5965
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5966
+ }
5967
+
5968
+ var startDateObj = new Date(start_date);
5969
+ var endDateObj = new Date(end_date);
5970
+
5971
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5972
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5973
+ }
5974
+
5975
+ if (startDateObj > endDateObj) {
5976
+ throw new Error('Start date should be earlier than or equal to end date.');
5977
+ }
5978
+
5979
+ var workdays = 0;
5980
+
5981
+ // Iterate through each day in the date range
5982
+
5983
+ var _loop = function _loop(currentDate) {
5984
+ // Check if the current day is a weekend (Saturday or Sunday)
5985
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5986
+
5987
+ // Check if the current day is a holiday
5988
+ var isHoliday = holidays.some(function (holiday) {
5989
+ var holidayDate = new Date(holiday);
5990
+ return currentDate.toDateString() === holidayDate.toDateString();
5991
+ });
5992
+
5993
+ // If it's a workday (not a weekend or holiday), increment the workdays count
5994
+ if (!isWeekend && !isHoliday) {
5995
+ workdays++;
5996
+ }
5997
+ };
5998
+
5999
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
6000
+ _loop(currentDate);
6001
+ }
6002
+
6003
+ return workdays;
6004
+ };
6005
+
6025
6006
  /**
6026
6007
  * 日期加减天数
6027
6008
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
6028
6009
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
6029
6010
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
6030
- */
6031
- const dateAddDays = function (start_date, days) {
6032
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6033
- throw new Error(
6034
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
6035
- );
6036
- }
6037
-
6038
- const startDateObj = new Date(start_date);
6039
- if (isNaN(startDateObj.getTime())) {
6040
- throw new Error(
6041
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6042
- );
6043
- }
6044
-
6045
- const resultDateObj = new Date(startDateObj);
6046
- resultDateObj.setDate(resultDateObj.getDate() + days);
6047
-
6048
- const resultYear = resultDateObj.getFullYear();
6049
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6050
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6051
-
6052
- return `${resultYear}-${resultMonth}-${resultDay}`;
6053
- };
6054
-
6011
+ */
6012
+ var dateAddDays = function dateAddDays(start_date, days) {
6013
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6014
+ 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.");
6015
+ }
6016
+
6017
+ var startDateObj = new Date(start_date);
6018
+ if (isNaN(startDateObj.getTime())) {
6019
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6020
+ }
6021
+
6022
+ var resultDateObj = new Date(startDateObj);
6023
+ resultDateObj.setDate(resultDateObj.getDate() + days);
6024
+
6025
+ var resultYear = resultDateObj.getFullYear();
6026
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6027
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6028
+
6029
+ return resultYear + '-' + resultMonth + '-' + resultDay;
6030
+ };
6031
+
6055
6032
  /**
6056
6033
  * 计算两个日期之间的差值
6057
6034
  * @date 2023年12月14日
@@ -6059,182 +6036,180 @@ const dateAddDays = function (start_date, days) {
6059
6036
  * @param {String} end_date - 结束日期字符串
6060
6037
  * @param {String} unit - 单位:year/month/day
6061
6038
  * @returns {Number} 差值
6062
- */
6063
- const dateDiff = function (start_date, end_date, unit = 'day') {
6064
- // Assuming date strings are in "YYYY-MM-DD" format
6065
- var startDate = new Date(start_date);
6066
- var endDate = new Date(end_date);
6067
-
6068
- // If the date is invalid, return 0
6069
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6070
- return 0;
6071
- }
6072
-
6073
- if (unit === 'year') {
6074
- return endDate.getFullYear() - startDate.getFullYear();
6075
- } else if (unit === 'month') {
6076
- return (
6077
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
6078
- (endDate.getMonth() - startDate.getMonth())
6079
- );
6080
- } else {
6081
- // Default to day
6082
- var timeDifference = endDate - startDate;
6083
- // Calculate days (86400000 milliseconds per day)
6084
- return Math.floor(timeDifference / 86400000);
6085
- }
6086
- };
6087
-
6039
+ */
6040
+ var dateDiff = function dateDiff(start_date, end_date) {
6041
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
6042
+
6043
+ // Assuming date strings are in "YYYY-MM-DD" format
6044
+ var startDate = new Date(start_date);
6045
+ var endDate = new Date(end_date);
6046
+
6047
+ // If the date is invalid, return 0
6048
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6049
+ return 0;
6050
+ }
6051
+
6052
+ if (unit === 'year') {
6053
+ return endDate.getFullYear() - startDate.getFullYear();
6054
+ } else if (unit === 'month') {
6055
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
6056
+ } else {
6057
+ // Default to day
6058
+ var timeDifference = endDate - startDate;
6059
+ // Calculate days (86400000 milliseconds per day)
6060
+ return Math.floor(timeDifference / 86400000);
6061
+ }
6062
+ };
6063
+
6088
6064
  /**
6089
6065
  * 获取月份中的日期
6090
6066
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
6091
6067
  * @returns {number} 月份中的日期(1-31)
6092
- */
6093
- const dayOfMonth = function (date) {
6094
- if (typeof date !== 'string') {
6095
- throw new Error(
6096
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
6097
- );
6098
- }
6099
-
6100
- const dateObj = new Date(date);
6101
- if (isNaN(dateObj.getTime())) {
6102
- throw new Error(
6103
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6104
- );
6105
- }
6106
-
6107
- return dateObj.getDate();
6108
- };
6109
-
6068
+ */
6069
+ var dayOfMonth = function dayOfMonth(date) {
6070
+ if (typeof date !== 'string') {
6071
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6072
+ }
6073
+
6074
+ var dateObj = new Date(date);
6075
+ if (isNaN(dateObj.getTime())) {
6076
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6077
+ }
6078
+
6079
+ return dateObj.getDate();
6080
+ };
6081
+
6110
6082
  /**
6111
6083
  * 获取当前日期
6112
6084
  * @date 2022年5月7日
6113
6085
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
6114
6086
  * @returns {string} 当前日期的格式化字符串
6115
- */
6116
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
6117
- return formatDate(new Date(), format);
6118
- };
6119
-
6087
+ */
6088
+ var getCurrentDate = function getCurrentDate() {
6089
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
6090
+
6091
+ return formatDate(new Date(), format);
6092
+ };
6093
+
6120
6094
  /**
6121
6095
  * 获取当前日期时间
6122
6096
  * @date 2022年5月7日
6123
6097
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
6124
6098
  * @returns {string} 当前日期时间的格式化字符串
6125
- */
6126
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
6127
- return formatDate(new Date(), format);
6128
- };
6129
-
6099
+ */
6100
+ var getCurrentDateTime = function getCurrentDateTime() {
6101
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
6102
+
6103
+ return formatDate(new Date(), format);
6104
+ };
6105
+
6130
6106
  /**
6131
6107
  * 获取小时
6132
6108
  * @date 2022年5月7日
6133
6109
  * @param {Date|string} [date] - 日期对象或日期字符串
6134
6110
  * @returns {number} 小时数(0-23)
6135
- */
6136
- const getHour = function (date) {
6137
- if (!date) {
6138
- return new Date().getHours();
6139
- }
6140
- if (typeof date === 'string') {
6141
- date = new Date(date);
6142
- }
6143
- return date.getHours();
6144
- };
6145
-
6111
+ */
6112
+ var getHour = function getHour(date) {
6113
+ if (!date) {
6114
+ return new Date().getHours();
6115
+ }
6116
+ if (typeof date === 'string') {
6117
+ date = new Date(date);
6118
+ }
6119
+ return date.getHours();
6120
+ };
6121
+
6146
6122
  /**
6147
6123
  * 获取分钟
6148
6124
  * @date 2022年5月7日
6149
6125
  * @param {Date|string} [date] - 日期对象或日期字符串
6150
6126
  * @returns {number} 分钟数(0-59)
6151
- */
6152
- const getMinute = function (date) {
6153
- if (!date) {
6154
- return new Date().getMinutes();
6155
- }
6156
- if (typeof date === 'string') {
6157
- date = new Date(date);
6158
- }
6159
- return date.getMinutes();
6160
- };
6161
-
6127
+ */
6128
+ var getMinute = function getMinute(date) {
6129
+ if (!date) {
6130
+ return new Date().getMinutes();
6131
+ }
6132
+ if (typeof date === 'string') {
6133
+ date = new Date(date);
6134
+ }
6135
+ return date.getMinutes();
6136
+ };
6137
+
6162
6138
  /**
6163
6139
  * 获取月份
6164
6140
  * @date 2022年5月7日
6165
6141
  * @param {Date|string} [date] - 日期对象或日期字符串
6166
6142
  * @returns {number} 月份数(1-12)
6167
- */
6168
- const getMonth = function (date) {
6169
- if (!date) {
6170
- return new Date().getMonth() + 1;
6171
- }
6172
- if (typeof date === 'string') {
6173
- date = new Date(date);
6174
- }
6175
- return date.getMonth() + 1;
6176
- };
6177
-
6143
+ */
6144
+ var getMonth = function getMonth(date) {
6145
+ if (!date) {
6146
+ return new Date().getMonth() + 1;
6147
+ }
6148
+ if (typeof date === 'string') {
6149
+ date = new Date(date);
6150
+ }
6151
+ return date.getMonth() + 1;
6152
+ };
6153
+
6178
6154
  /**
6179
6155
  * 获取秒
6180
6156
  * @date 2022年5月7日
6181
6157
  * @param {Date|string} [date] - 日期对象或日期字符串
6182
6158
  * @returns {number} 秒数(0-59)
6183
- */
6184
- const getSecond = function (date) {
6185
- if (!date) {
6186
- return new Date().getSeconds();
6187
- }
6188
- if (typeof date === 'string') {
6189
- date = new Date(date);
6190
- }
6191
- return date.getSeconds();
6192
- };
6193
-
6159
+ */
6160
+ var getSecond = function getSecond(date) {
6161
+ if (!date) {
6162
+ return new Date().getSeconds();
6163
+ }
6164
+ if (typeof date === 'string') {
6165
+ date = new Date(date);
6166
+ }
6167
+ return date.getSeconds();
6168
+ };
6169
+
6194
6170
  /**
6195
6171
  * 获取星期几
6196
6172
  * @date 2022年5月7日
6197
6173
  * @param {Date|string} [date] - 日期对象或日期字符串
6198
6174
  * @returns {number} 星期几(0-6,0表示星期日)
6199
- */
6200
- const getWeekday = function (date) {
6201
- if (!date) {
6202
- return new Date().getDay();
6203
- }
6204
- if (typeof date === 'string') {
6205
- date = new Date(date);
6206
- }
6207
- return date.getDay();
6208
- };
6209
-
6210
-
6175
+ */
6176
+ var getWeekday = function getWeekday(date) {
6177
+ if (!date) {
6178
+ return new Date().getDay();
6179
+ }
6180
+ if (typeof date === 'string') {
6181
+ date = new Date(date);
6182
+ }
6183
+ return date.getDay();
6184
+ };
6185
+
6211
6186
  /**
6212
6187
  * @desc 获取上午/下午/晚上
6213
6188
  * @author huangbo
6214
6189
  * @date 2022年5月7日
6215
6190
  * @param {String} [time] - 时间
6216
- **/
6217
- const timeCycle = function (time) {
6218
- let hour = 0;
6219
- if (!time) {
6220
- hour = new Date().getHours();
6221
- } else if (typeof time === 'string') {
6222
- // 从时间字符串中提取小时
6223
- const match = time.match(/^(\d{1,2})/);
6224
- if (match) {
6225
- hour = parseInt(match[1], 10);
6226
- }
6227
- } else if (typeof time === 'number') {
6228
- hour = time;
6229
- }
6230
- // 判断时间段
6231
- if (hour >= 5 && hour < 12) {
6232
- return '上午';
6233
- } else if (hour >= 12 && hour < 18) {
6234
- return '下午';
6235
- } else {
6236
- return '晚上';
6237
- }
6191
+ **/
6192
+ var timeCycle = function timeCycle(time) {
6193
+ var hour = 0;
6194
+ if (!time) {
6195
+ hour = new Date().getHours();
6196
+ } else if (typeof time === 'string') {
6197
+ // 从时间字符串中提取小时
6198
+ var match = time.match(/^(\d{1,2})/);
6199
+ if (match) {
6200
+ hour = parseInt(match[1], 10);
6201
+ }
6202
+ } else if (typeof time === 'number') {
6203
+ hour = time;
6204
+ }
6205
+ // 判断时间段
6206
+ if (hour >= 5 && hour < 12) {
6207
+ return '上午';
6208
+ } else if (hour >= 12 && hour < 18) {
6209
+ return '下午';
6210
+ } else {
6211
+ return '晚上';
6212
+ }
6238
6213
  };
6239
6214
 
6240
6215
  /***/ }),