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/flows.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 = 185);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 192);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -4703,7 +4703,14 @@ module.exports = require("lodash/set");
4703
4703
 
4704
4704
  /***/ }),
4705
4705
 
4706
- /***/ 185:
4706
+ /***/ 19:
4707
+ /***/ (function(module, exports) {
4708
+
4709
+ module.exports = require("lodash/cloneDeep");
4710
+
4711
+ /***/ }),
4712
+
4713
+ /***/ 192:
4707
4714
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4708
4715
 
4709
4716
  "use strict";
@@ -5450,7 +5457,7 @@ opinions_listvue_type_template_id_4794b30e_scoped_true_render._withStripped = tr
5450
5457
  // CONCATENATED MODULE: ./packages/flows/src/components/opinions-list.vue?vue&type=template&id=4794b30e&scoped=true&
5451
5458
 
5452
5459
  // EXTERNAL MODULE: external "eoss/lib/data-table"
5453
- var data_table_ = __webpack_require__(47);
5460
+ var data_table_ = __webpack_require__(48);
5454
5461
  var data_table_default = /*#__PURE__*/__webpack_require__.n(data_table_);
5455
5462
 
5456
5463
  // EXTERNAL MODULE: external "eoss/lib/dialog"
@@ -5746,7 +5753,7 @@ opinions_filevue_type_template_id_0804b7bb_render._withStripped = true
5746
5753
  // CONCATENATED MODULE: ./packages/flows/src/components/opinions-file.vue?vue&type=template&id=0804b7bb&
5747
5754
 
5748
5755
  // EXTERNAL MODULE: external "eoss/lib/upload"
5749
- var upload_ = __webpack_require__(49);
5756
+ var upload_ = __webpack_require__(50);
5750
5757
  var upload_default = /*#__PURE__*/__webpack_require__.n(upload_);
5751
5758
 
5752
5759
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/flows/src/components/opinions-file.vue?vue&type=script&lang=js&
@@ -5900,11 +5907,11 @@ var opinions_file_component = Object(componentNormalizer["a" /* default */])(
5900
5907
 
5901
5908
  /* harmony default export */ var opinions_file = (opinions_file_component.exports);
5902
5909
  // EXTERNAL MODULE: external "eoss/lib/dropdown"
5903
- var dropdown_ = __webpack_require__(57);
5910
+ var dropdown_ = __webpack_require__(58);
5904
5911
  var dropdown_default = /*#__PURE__*/__webpack_require__.n(dropdown_);
5905
5912
 
5906
5913
  // EXTERNAL MODULE: external "eoss/lib/tag"
5907
- var tag_ = __webpack_require__(68);
5914
+ var tag_ = __webpack_require__(69);
5908
5915
  var tag_default = /*#__PURE__*/__webpack_require__.n(tag_);
5909
5916
 
5910
5917
  // EXTERNAL MODULE: external "eoss/lib/tooltip"
@@ -6575,7 +6582,7 @@ var select_ = __webpack_require__(41);
6575
6582
  var select_default = /*#__PURE__*/__webpack_require__.n(select_);
6576
6583
 
6577
6584
  // EXTERNAL MODULE: external "eoss/lib/selector"
6578
- var selector_ = __webpack_require__(66);
6585
+ var selector_ = __webpack_require__(67);
6579
6586
  var selector_default = /*#__PURE__*/__webpack_require__.n(selector_);
6580
6587
 
6581
6588
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/flows/src/components/start-flow.vue?vue&type=script&lang=js&
@@ -7581,13 +7588,6 @@ flow.install = function (Vue) {
7581
7588
 
7582
7589
  /***/ }),
7583
7590
 
7584
- /***/ 19:
7585
- /***/ (function(module, exports) {
7586
-
7587
- module.exports = require("lodash/cloneDeep");
7588
-
7589
- /***/ }),
7590
-
7591
7591
  /***/ 2:
7592
7592
  /***/ (function(module, exports) {
7593
7593
 
@@ -7917,21 +7917,21 @@ module.exports = require("eoss/lib/radio-group");
7917
7917
 
7918
7918
  /***/ }),
7919
7919
 
7920
- /***/ 47:
7920
+ /***/ 48:
7921
7921
  /***/ (function(module, exports) {
7922
7922
 
7923
7923
  module.exports = require("eoss/lib/data-table");
7924
7924
 
7925
7925
  /***/ }),
7926
7926
 
7927
- /***/ 49:
7927
+ /***/ 50:
7928
7928
  /***/ (function(module, exports) {
7929
7929
 
7930
7930
  module.exports = require("eoss/lib/upload");
7931
7931
 
7932
7932
  /***/ }),
7933
7933
 
7934
- /***/ 57:
7934
+ /***/ 58:
7935
7935
  /***/ (function(module, exports) {
7936
7936
 
7937
7937
  module.exports = require("eoss/lib/dropdown");
@@ -8511,14 +8511,14 @@ var changeInTime = '/baseIssueRules/changeInTime';
8511
8511
 
8512
8512
  /***/ }),
8513
8513
 
8514
- /***/ 66:
8514
+ /***/ 67:
8515
8515
  /***/ (function(module, exports) {
8516
8516
 
8517
8517
  module.exports = require("eoss/lib/selector");
8518
8518
 
8519
8519
  /***/ }),
8520
8520
 
8521
- /***/ 68:
8521
+ /***/ 69:
8522
8522
  /***/ (function(module, exports) {
8523
8523
 
8524
8524
  module.exports = require("eoss/lib/tag");
@@ -8575,759 +8575,736 @@ module.exports = require("eoss/lib/tag");
8575
8575
  /* unused harmony export getSecond */
8576
8576
  /* unused harmony export getWeekday */
8577
8577
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
8578
- /* Modified from https://github.com/taylorhakes/fecha
8579
- *
8580
- * The MIT License (MIT)
8581
- *
8582
- * Copyright (c) 2015 Taylor Hakes
8583
- *
8584
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8585
- * of this software and associated documentation files (the "Software"), to deal
8586
- * in the Software without restriction, including without limitation the rights
8587
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8588
- * copies of the Software, and to permit persons to whom the Software is
8589
- * furnished to do so, subject to the following conditions:
8590
- *
8591
- * The above copyright notice and this permission notice shall be included in all
8592
- * copies or substantial portions of the Software.
8593
- *
8594
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8595
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8596
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8597
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8598
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
8599
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
8600
- * SOFTWARE.
8601
- */
8602
-
8603
- /*eslint-disable*/
8604
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
8605
-
8606
-
8578
+
8579
+
8607
8580
  /**
8608
8581
  * Parse or format dates
8609
8582
  * @class fecha
8610
- */
8611
- const fecha = {};
8612
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
8613
- const twoDigits = '\\d\\d?';
8614
- const threeDigits = '\\d{3}';
8615
- const fourDigits = '\\d{4}';
8616
- const word = '[^\\s]+';
8617
- const literal = /\[([^]*?)\]/gm;
8618
- const noop = function () {};
8619
-
8620
- function regexEscape(str) {
8621
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
8622
- }
8623
-
8624
- function shorten(arr, sLen) {
8625
- const newArr = [];
8626
- for (let i = 0, len = arr.length; i < len; i++) {
8627
- newArr.push(arr[i].substr(0, sLen));
8628
- }
8629
- return newArr;
8630
- }
8631
-
8632
- function monthUpdate() {
8633
- return function (d, v) {
8634
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
8635
- if (~index) {
8636
- d.month = index;
8637
- }
8638
- };
8639
- }
8640
-
8641
- function pad(val, len) {
8642
- val = String(val);
8643
- len = len || 2;
8644
- while (val.length < len) {
8645
- val = '0' + val;
8646
- }
8647
- return val;
8648
- }
8649
-
8650
- // 直接使用中文日期名称常量
8651
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
8652
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
8653
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
8654
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
8655
- const amPm = ['上午', '下午'];
8656
- const DoFn = function DoFn(D) {
8657
- return D + '日';
8658
- };
8659
-
8660
- const formatFlags = {
8661
- D: function(dateObj) {
8662
- return dateObj.getDay();
8663
- },
8664
- DD: function(dateObj) {
8665
- return pad(dateObj.getDay());
8666
- },
8667
- Do: function(dateObj) {
8668
- return DoFn(dateObj.getDate());
8669
- },
8670
- d: function(dateObj) {
8671
- return dateObj.getDate();
8672
- },
8673
- dd: function(dateObj) {
8674
- return pad(dateObj.getDate());
8675
- },
8676
- ddd: function(dateObj) {
8677
- return dayNamesShort[dateObj.getDay()];
8678
- },
8679
- dddd: function(dateObj) {
8680
- return dayNames[dateObj.getDay()];
8681
- },
8682
- M: function(dateObj) {
8683
- return dateObj.getMonth() + 1;
8684
- },
8685
- MM: function(dateObj) {
8686
- return pad(dateObj.getMonth() + 1);
8687
- },
8688
- MMM: function(dateObj) {
8689
- return monthNamesShort[dateObj.getMonth()];
8690
- },
8691
- MMMM: function(dateObj) {
8692
- return monthNames[dateObj.getMonth()];
8693
- },
8694
- yy: function(dateObj) {
8695
- return pad(String(dateObj.getFullYear()), 4).substr(2);
8696
- },
8697
- yyyy: function(dateObj) {
8698
- return pad(dateObj.getFullYear(), 4);
8699
- },
8700
- h: function(dateObj) {
8701
- return dateObj.getHours() % 12 || 12;
8702
- },
8703
- hh: function(dateObj) {
8704
- return pad(dateObj.getHours() % 12 || 12);
8705
- },
8706
- H: function(dateObj) {
8707
- return dateObj.getHours();
8708
- },
8709
- HH: function(dateObj) {
8710
- return pad(dateObj.getHours());
8711
- },
8712
- m: function(dateObj) {
8713
- return dateObj.getMinutes();
8714
- },
8715
- mm: function(dateObj) {
8716
- return pad(dateObj.getMinutes());
8717
- },
8718
- s: function(dateObj) {
8719
- return dateObj.getSeconds();
8720
- },
8721
- ss: function(dateObj) {
8722
- return pad(dateObj.getSeconds());
8723
- },
8724
- S: function(dateObj) {
8725
- return Math.round(dateObj.getMilliseconds() / 100);
8726
- },
8727
- SS: function(dateObj) {
8728
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
8729
- },
8730
- SSS: function(dateObj) {
8731
- return pad(dateObj.getMilliseconds(), 3);
8732
- },
8733
- a: function(dateObj) {
8734
- return dateObj.getHours() < 12 ? '上午' : '下午';
8735
- },
8736
- A: function(dateObj) {
8737
- return dateObj.getHours() < 12 ? '上午' : '下午';
8738
- },
8739
- ZZ: function(dateObj) {
8740
- const o = dateObj.getTimezoneOffset();
8741
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
8742
- }
8743
- };
8744
-
8745
- const parseFlags = {
8746
- d: [twoDigits, function (d, v) {
8747
- d.day = v;
8748
- }],
8749
- Do: [twoDigits + word, function (d, v) {
8750
- d.day = parseInt(v, 10);
8751
- }],
8752
- M: [twoDigits, function (d, v) {
8753
- d.month = v - 1;
8754
- }],
8755
- yy: [twoDigits, function (d, v) {
8756
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
8757
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
8758
- }],
8759
- h: [twoDigits, function (d, v) {
8760
- d.hour = v;
8761
- }],
8762
- m: [twoDigits, function (d, v) {
8763
- d.minute = v;
8764
- }],
8765
- s: [twoDigits, function (d, v) {
8766
- d.second = v;
8767
- }],
8768
- yyyy: [fourDigits, function (d, v) {
8769
- d.year = v;
8770
- }],
8771
- S: ['\\d', function (d, v) {
8772
- d.millisecond = v * 100;
8773
- }],
8774
- SS: ['\\d{2}', function (d, v) {
8775
- d.millisecond = v * 10;
8776
- }],
8777
- SSS: [threeDigits, function (d, v) {
8778
- d.millisecond = v;
8779
- }],
8780
- D: [twoDigits, noop],
8781
- ddd: [word, noop],
8782
- MMM: [word, monthUpdate('monthNamesShort')],
8783
- MMMM: [word, monthUpdate('monthNames')],
8784
- a: [word, function (d, v) {
8785
- const val = v.toLowerCase();
8786
- if (val === '上午') {
8787
- d.isPm = false;
8788
- } else if (val === '下午') {
8789
- d.isPm = true;
8790
- }
8791
- }],
8792
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
8793
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
8794
-
8795
- if (parts) {
8796
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
8797
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
8798
- }
8799
- }]
8800
- };
8801
- parseFlags.dd = parseFlags.d;
8802
- parseFlags.dddd = parseFlags.ddd;
8803
- parseFlags.DD = parseFlags.D;
8804
- parseFlags.mm = parseFlags.m;
8805
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
8806
- parseFlags.MM = parseFlags.M;
8807
- parseFlags.ss = parseFlags.s;
8808
- parseFlags.A = parseFlags.a;
8809
-
8810
-
8811
- // Some common format strings
8812
- fecha.masks = {
8813
- default: 'ddd MMM dd yyyy HH:mm:ss',
8814
- shortDate: 'M/D/yy',
8815
- mediumDate: 'MMM d, yyyy',
8816
- longDate: 'MMMM d, yyyy',
8817
- fullDate: 'dddd, MMMM d, yyyy',
8818
- shortTime: 'HH:mm',
8819
- mediumTime: 'HH:mm:ss',
8820
- longTime: 'HH:mm:ss.SSS'
8821
- };
8822
-
8583
+ */
8584
+ var fecha = {};
8585
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
8586
+ var twoDigits = '\\d\\d?';
8587
+ var threeDigits = '\\d{3}';
8588
+ var fourDigits = '\\d{4}';
8589
+ var word = '[^\\s]+';
8590
+ var literal = /\[([^]*?)\]/gm;
8591
+ var noop = function noop() {};
8592
+
8593
+ function regexEscape(str) {
8594
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
8595
+ }
8596
+
8597
+ function shorten(arr, sLen) {
8598
+ var newArr = [];
8599
+ for (var i = 0, len = arr.length; i < len; i++) {
8600
+ newArr.push(arr[i].substr(0, sLen));
8601
+ }
8602
+ return newArr;
8603
+ }
8604
+
8605
+ function monthUpdate() {
8606
+ return function (d, v) {
8607
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
8608
+ if (~index) {
8609
+ d.month = index;
8610
+ }
8611
+ };
8612
+ }
8613
+
8614
+ function pad(val, len) {
8615
+ val = String(val);
8616
+ len = len || 2;
8617
+ while (val.length < len) {
8618
+ val = '0' + val;
8619
+ }
8620
+ return val;
8621
+ }
8622
+
8623
+ // 直接使用中文日期名称常量
8624
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
8625
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
8626
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
8627
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
8628
+ var amPm = ['上午', '下午'];
8629
+ var DoFn = function DoFn(D) {
8630
+ return D + '日';
8631
+ };
8632
+
8633
+ var formatFlags = {
8634
+ D: function D(dateObj) {
8635
+ return dateObj.getDay();
8636
+ },
8637
+ DD: function DD(dateObj) {
8638
+ return pad(dateObj.getDay());
8639
+ },
8640
+ Do: function Do(dateObj) {
8641
+ return DoFn(dateObj.getDate());
8642
+ },
8643
+ d: function d(dateObj) {
8644
+ return dateObj.getDate();
8645
+ },
8646
+ dd: function dd(dateObj) {
8647
+ return pad(dateObj.getDate());
8648
+ },
8649
+ ddd: function ddd(dateObj) {
8650
+ return dayNamesShort[dateObj.getDay()];
8651
+ },
8652
+ dddd: function dddd(dateObj) {
8653
+ return dayNames[dateObj.getDay()];
8654
+ },
8655
+ M: function M(dateObj) {
8656
+ return dateObj.getMonth() + 1;
8657
+ },
8658
+ MM: function MM(dateObj) {
8659
+ return pad(dateObj.getMonth() + 1);
8660
+ },
8661
+ MMM: function MMM(dateObj) {
8662
+ return monthNamesShort[dateObj.getMonth()];
8663
+ },
8664
+ MMMM: function MMMM(dateObj) {
8665
+ return monthNames[dateObj.getMonth()];
8666
+ },
8667
+ yy: function yy(dateObj) {
8668
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
8669
+ },
8670
+ yyyy: function yyyy(dateObj) {
8671
+ return pad(dateObj.getFullYear(), 4);
8672
+ },
8673
+ h: function h(dateObj) {
8674
+ return dateObj.getHours() % 12 || 12;
8675
+ },
8676
+ hh: function hh(dateObj) {
8677
+ return pad(dateObj.getHours() % 12 || 12);
8678
+ },
8679
+ H: function H(dateObj) {
8680
+ return dateObj.getHours();
8681
+ },
8682
+ HH: function HH(dateObj) {
8683
+ return pad(dateObj.getHours());
8684
+ },
8685
+ m: function m(dateObj) {
8686
+ return dateObj.getMinutes();
8687
+ },
8688
+ mm: function mm(dateObj) {
8689
+ return pad(dateObj.getMinutes());
8690
+ },
8691
+ s: function s(dateObj) {
8692
+ return dateObj.getSeconds();
8693
+ },
8694
+ ss: function ss(dateObj) {
8695
+ return pad(dateObj.getSeconds());
8696
+ },
8697
+ S: function S(dateObj) {
8698
+ return Math.round(dateObj.getMilliseconds() / 100);
8699
+ },
8700
+ SS: function SS(dateObj) {
8701
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
8702
+ },
8703
+ SSS: function SSS(dateObj) {
8704
+ return pad(dateObj.getMilliseconds(), 3);
8705
+ },
8706
+ a: function a(dateObj) {
8707
+ return dateObj.getHours() < 12 ? '上午' : '下午';
8708
+ },
8709
+ A: function A(dateObj) {
8710
+ return dateObj.getHours() < 12 ? '上午' : '下午';
8711
+ },
8712
+ ZZ: function ZZ(dateObj) {
8713
+ var o = dateObj.getTimezoneOffset();
8714
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
8715
+ }
8716
+ };
8717
+
8718
+ var parseFlags = {
8719
+ d: [twoDigits, function (d, v) {
8720
+ d.day = v;
8721
+ }],
8722
+ Do: [twoDigits + word, function (d, v) {
8723
+ d.day = parseInt(v, 10);
8724
+ }],
8725
+ M: [twoDigits, function (d, v) {
8726
+ d.month = v - 1;
8727
+ }],
8728
+ yy: [twoDigits, function (d, v) {
8729
+ var da = new Date(),
8730
+ cent = +('' + da.getFullYear()).substr(0, 2);
8731
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
8732
+ }],
8733
+ h: [twoDigits, function (d, v) {
8734
+ d.hour = v;
8735
+ }],
8736
+ m: [twoDigits, function (d, v) {
8737
+ d.minute = v;
8738
+ }],
8739
+ s: [twoDigits, function (d, v) {
8740
+ d.second = v;
8741
+ }],
8742
+ yyyy: [fourDigits, function (d, v) {
8743
+ d.year = v;
8744
+ }],
8745
+ S: ['\\d', function (d, v) {
8746
+ d.millisecond = v * 100;
8747
+ }],
8748
+ SS: ['\\d{2}', function (d, v) {
8749
+ d.millisecond = v * 10;
8750
+ }],
8751
+ SSS: [threeDigits, function (d, v) {
8752
+ d.millisecond = v;
8753
+ }],
8754
+ D: [twoDigits, noop],
8755
+ ddd: [word, noop],
8756
+ MMM: [word, monthUpdate('monthNamesShort')],
8757
+ MMMM: [word, monthUpdate('monthNames')],
8758
+ a: [word, function (d, v) {
8759
+ var val = v.toLowerCase();
8760
+ if (val === '上午') {
8761
+ d.isPm = false;
8762
+ } else if (val === '下午') {
8763
+ d.isPm = true;
8764
+ }
8765
+ }],
8766
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
8767
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
8768
+ minutes = void 0;
8769
+
8770
+ if (parts) {
8771
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
8772
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
8773
+ }
8774
+ }]
8775
+ };
8776
+ parseFlags.dd = parseFlags.d;
8777
+ parseFlags.dddd = parseFlags.ddd;
8778
+ parseFlags.DD = parseFlags.D;
8779
+ parseFlags.mm = parseFlags.m;
8780
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
8781
+ parseFlags.MM = parseFlags.M;
8782
+ parseFlags.ss = parseFlags.s;
8783
+ parseFlags.A = parseFlags.a;
8784
+
8785
+ // Some common format strings
8786
+ fecha.masks = {
8787
+ default: 'ddd MMM dd yyyy HH:mm:ss',
8788
+ shortDate: 'M/D/yy',
8789
+ mediumDate: 'MMM d, yyyy',
8790
+ longDate: 'MMMM d, yyyy',
8791
+ fullDate: 'dddd, MMMM d, yyyy',
8792
+ shortTime: 'HH:mm',
8793
+ mediumTime: 'HH:mm:ss',
8794
+ longTime: 'HH:mm:ss.SSS'
8795
+ };
8796
+
8823
8797
  /***
8824
8798
  * Format a date
8825
8799
  * @method format
8826
8800
  * @param {Date|number} dateObj
8827
8801
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
8828
- */
8829
- fecha.format = function (dateObj, mask) {
8830
- if (typeof dateObj === 'number') {
8831
- dateObj = new Date(dateObj);
8832
- }
8833
-
8834
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
8835
- throw new Error('Invalid Date in fecha.format');
8836
- }
8837
-
8838
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
8839
-
8840
- const literals = [];
8841
-
8842
- // Make literals inactive by replacing them with ??
8843
- mask = mask.replace(literal, function($0, $1) {
8844
- literals.push($1);
8845
- return '@@@';
8846
- });
8847
- // Apply formatting rules
8848
- mask = mask.replace(token, function ($0) {
8849
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
8850
- });
8851
- // Inline literal values back into the formatted value
8852
- return mask.replace(/@@@/g, function() {
8853
- return literals.shift();
8854
- });
8855
- };
8856
-
8802
+ */
8803
+ fecha.format = function (dateObj, mask) {
8804
+ if (typeof dateObj === 'number') {
8805
+ dateObj = new Date(dateObj);
8806
+ }
8807
+
8808
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
8809
+ throw new Error('Invalid Date in fecha.format');
8810
+ }
8811
+
8812
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
8813
+
8814
+ var literals = [];
8815
+
8816
+ // Make literals inactive by replacing them with ??
8817
+ mask = mask.replace(literal, function ($0, $1) {
8818
+ literals.push($1);
8819
+ return '@@@';
8820
+ });
8821
+ // Apply formatting rules
8822
+ mask = mask.replace(token, function ($0) {
8823
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
8824
+ });
8825
+ // Inline literal values back into the formatted value
8826
+ return mask.replace(/@@@/g, function () {
8827
+ return literals.shift();
8828
+ });
8829
+ };
8830
+
8857
8831
  /**
8858
8832
  * Parse a date string into an object, changes - into /
8859
8833
  * @method parse
8860
8834
  * @param {string} dateStr Date string
8861
8835
  * @param {string} format Date parse format
8862
8836
  * @returns {Date|boolean}
8863
- */
8864
- fecha.parse = function (dateStr, format) {
8865
- if (typeof format !== 'string') {
8866
- throw new Error('Invalid format in fecha.parse');
8867
- }
8868
-
8869
- format = fecha.masks[format] || format;
8870
-
8871
- // Avoid regular expression denial of service, fail early for really long strings
8872
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
8873
- if (dateStr.length > 1000) {
8874
- return null;
8875
- }
8876
-
8877
- const dateInfo = {};
8878
- const parseInfo = [];
8879
- const literals = [];
8880
- format = format.replace(literal, function($0, $1) {
8881
- literals.push($1);
8882
- return '@@@';
8883
- });
8884
- let newFormat = regexEscape(format).replace(token, function ($0) {
8885
- if (parseFlags[$0]) {
8886
- const info = parseFlags[$0];
8887
- parseInfo.push(info[1]);
8888
- return '(' + info[0] + ')';
8889
- }
8890
-
8891
- return $0;
8892
- });
8893
- newFormat = newFormat.replace(/@@@/g, function() {
8894
- return literals.shift();
8895
- });
8896
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
8897
- if (!matches) {
8898
- return null;
8899
- }
8900
-
8901
- for (let i = 1; i < matches.length; i++) {
8902
- parseInfo[i - 1](dateInfo, matches[i]);
8903
- }
8904
-
8905
- const today = new Date();
8906
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
8907
- dateInfo.hour = +dateInfo.hour + 12;
8908
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
8909
- dateInfo.hour = 0;
8910
- }
8911
-
8912
- let date;
8913
- if (dateInfo.timezoneOffset != null) {
8914
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
8915
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
8916
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
8917
- } else {
8918
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
8919
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
8920
- }
8921
- return date;
8922
- };
8923
-
8924
- // 导出fecha对象
8925
-
8926
-
8927
- // 以下是从date-util.js合并的函数
8928
- const newArray = function(start, end) {
8929
- let result = [];
8930
- for (let i = start; i <= end; i++) {
8931
- result.push(i);
8932
- }
8933
- return result;
8934
- };
8935
-
8936
- const getSettings = () => {
8937
- return {
8938
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
8939
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
8940
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
8941
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
8942
- amPm: ['上午', '下午']
8943
- };
8944
- };
8945
-
8946
- const toDate = function(date) {
8947
- return isDate(date) ? new Date(date) : null;
8948
- };
8949
-
8950
- const isDate = function(date) {
8951
- if (date === null || date === undefined) return false;
8952
- if (isNaN(new Date(date).getTime())) return false;
8953
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
8954
- return true;
8955
- };
8956
-
8957
- const isDateObject = function(val) {
8958
- return val instanceof Date;
8959
- };
8960
-
8961
- const formatDate = function (date, format = 'yyyy-MM-dd') {
8962
- // 处理多种输入类型
8963
- if (!date) return '';
8964
-
8965
- // 如果是时间戳,转成日期对象
8966
- if (typeof date === 'number') {
8967
- date = new Date(date);
8968
- }
8969
- // 如果是字符串,转成日期对象
8970
- if (typeof date === 'string') {
8971
- date = new Date(date);
8972
- }
8973
-
8974
- // 调用toDate进一步验证和转换
8975
- date = toDate(date);
8976
- if (!date) return '';
8977
-
8978
- // 兼容大写和小写的格式标记
8979
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
8980
- const lowercaseFormat = format
8981
- .replace(/YYYY/g, 'yyyy')
8982
- .replace(/D/g, 'd')
8983
-
8984
- // 使用fecha库进行格式化,支持中文配置
8985
- const str = fecha.format(date, lowercaseFormat, getSettings());
8986
- return str;
8987
- };
8988
-
8989
- const parseDate = function(string, format) {
8990
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
8991
- };
8992
-
8993
- const getDayCountOfMonth = function(year, month) {
8994
- if (month === 3 || month === 5 || month === 8 || month === 10) {
8995
- return 30;
8996
- }
8997
-
8998
- if (month === 1) {
8999
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
9000
- return 29;
9001
- } else {
9002
- return 28;
9003
- }
9004
- }
9005
-
9006
- return 31;
9007
- };
9008
-
9009
- const getDayCountOfYear = function(year) {
9010
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
9011
- return isLeapYear ? 366 : 365;
9012
- };
9013
-
9014
- const getFirstDayOfMonth = function(date) {
9015
- const temp = new Date(date.getTime());
9016
- temp.setDate(1);
9017
- return temp.getDay();
9018
- };
9019
-
9020
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
9021
- // {prev, next} Date should work for Daylight Saving Time
9022
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
9023
- const prevDate = function(date, amount = 1) {
9024
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
9025
- };
9026
-
9027
- const nextDate = function(date, amount = 1) {
9028
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
9029
- };
9030
-
9031
- const getStartDateOfMonth = function(year, month) {
9032
- const result = new Date(year, month, 1);
9033
- const day = result.getDay();
9034
-
9035
- if (day === 0) {
9036
- return prevDate(result, 7);
9037
- } else {
9038
- return prevDate(result, day);
9039
- }
9040
- };
9041
-
9042
- const getWeekNumber = function(date) {
9043
- // 支持多种输入类型
9044
- if (!date||!isDate(date)) {
9045
- date = new Date();
9046
- }
9047
- if (typeof date === 'string') {
9048
- date = new Date(date);
9049
- }
9050
-
9051
- // 验证日期有效性
9052
- if (!isDate(date)) return null;
9053
-
9054
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
9055
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
9056
- // 将星期日的星期数设为7
9057
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
9058
- // 获取当年的第一天
9059
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
9060
- // 计算到最近的星期四的完整周数
9061
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
9062
- // 返回周数
9063
- return weekNo;
9064
- };
9065
-
9066
- const getRangeHours = function(ranges) {
9067
- const hours = [];
9068
- let disabledHours = [];
9069
-
9070
- (ranges || []).forEach(range => {
9071
- const value = range.map(date => date.getHours());
9072
-
9073
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
9074
- });
9075
-
9076
- if (disabledHours.length) {
9077
- for (let i = 0; i < 24; i++) {
9078
- hours[i] = disabledHours.indexOf(i) === -1;
9079
- }
9080
- } else {
9081
- for (let i = 0; i < 24; i++) {
9082
- hours[i] = false;
9083
- }
9084
- }
9085
-
9086
- return hours;
9087
- };
9088
-
9089
- const getPrevMonthLastDays = (date, amount) => {
9090
- if (amount <= 0) return [];
9091
- const temp = new Date(date.getTime());
9092
- temp.setDate(0);
9093
- const lastDay = temp.getDate();
9094
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
9095
- };
9096
-
9097
- const getMonthDays = (date) => {
9098
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
9099
- const days = temp.getDate();
9100
- return range(days).map((_, index) => index + 1);
9101
- };
9102
-
9103
- function setRangeData(arr, start, end, value) {
9104
- for (let i = start; i < end; i++) {
9105
- arr[i] = value;
9106
- }
9107
- }
9108
-
9109
- const getRangeMinutes = function(ranges, hour) {
9110
- const minutes = new Array(60);
9111
-
9112
- if (ranges.length > 0) {
9113
- ranges.forEach(range => {
9114
- const start = range[0];
9115
- const end = range[1];
9116
- const startHour = start.getHours();
9117
- const startMinute = start.getMinutes();
9118
- const endHour = end.getHours();
9119
- const endMinute = end.getMinutes();
9120
- if (startHour === hour && endHour !== hour) {
9121
- setRangeData(minutes, startMinute, 60, true);
9122
- } else if (startHour === hour && endHour === hour) {
9123
- setRangeData(minutes, startMinute, endMinute + 1, true);
9124
- } else if (startHour !== hour && endHour === hour) {
9125
- setRangeData(minutes, 0, endMinute + 1, true);
9126
- } else if (startHour < hour && endHour > hour) {
9127
- setRangeData(minutes, 0, 60, true);
9128
- }
9129
- });
9130
- } else {
9131
- setRangeData(minutes, 0, 60, true);
9132
- }
9133
- return minutes;
9134
- };
9135
-
9136
- const range = function(n) {
9137
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
9138
- return Array.apply(null, {length: n}).map((_, n) => n);
9139
- };
9140
-
9141
- const modifyDate = function(date, y, m, d) {
9142
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
9143
- };
9144
-
9145
- const modifyTime = function(date, h, m, s) {
9146
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
9147
- };
9148
-
9149
- const modifyWithTimeString = (date, time) => {
9150
- if (date == null || !time) {
9151
- return date;
9152
- }
9153
- time = parseDate(time, 'HH:mm:ss');
9154
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
9155
- };
9156
-
9157
- const clearTime = function(date) {
9158
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
9159
- };
9160
-
9161
- const clearMilliseconds = function(date) {
9162
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
9163
- };
9164
-
9165
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
9166
- // TODO: refactory a more elegant solution
9167
- if (ranges.length === 0) return date;
9168
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
9169
- const ndate = normalizeDate(date);
9170
- const nranges = ranges.map(range => range.map(normalizeDate));
9171
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
9172
-
9173
- let minDate = nranges[0][0];
9174
- let maxDate = nranges[0][0];
9175
-
9176
- nranges.forEach(nrange => {
9177
- minDate = new Date(Math.min(nrange[0], minDate));
9178
- maxDate = new Date(Math.max(nrange[1], minDate));
9179
- });
9180
-
9181
- const ret = ndate < minDate ? minDate : maxDate;
9182
- // preserve Year/Month/Date
9183
- return modifyDate(
9184
- ret,
9185
- date.getFullYear(),
9186
- date.getMonth(),
9187
- date.getDate()
9188
- );
9189
- };
9190
-
9191
- const timeWithinRange = function(date, selectableRange, format) {
9192
- const limitedDate = limitTimeRange(date, selectableRange, format);
9193
- return limitedDate.getTime() === date.getTime();
9194
- };
9195
-
9196
- const changeYearMonthAndClampDate = function(date, year, month) {
9197
- // clamp date to the number of days in `year`, `month`
9198
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
9199
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
9200
- return modifyDate(date, year, month, monthDate);
9201
- };
9202
-
9203
- const prevMonth = function(date) {
9204
- const year = date.getFullYear();
9205
- const month = date.getMonth();
9206
- return month === 0
9207
- ? changeYearMonthAndClampDate(date, year - 1, 11)
9208
- : changeYearMonthAndClampDate(date, year, month - 1);
9209
- };
9210
-
9211
- const nextMonth = function(date) {
9212
- const year = date.getFullYear();
9213
- const month = date.getMonth();
9214
- return month === 11
9215
- ? changeYearMonthAndClampDate(date, year + 1, 0)
9216
- : changeYearMonthAndClampDate(date, year, month + 1);
9217
- };
9218
-
9219
- const prevYear = function(date, amount = 1) {
9220
- const year = date.getFullYear();
9221
- const month = date.getMonth();
9222
- return changeYearMonthAndClampDate(date, year - amount, month);
9223
- };
9224
-
9225
- const nextYear = function(date, amount = 1) {
9226
- const year = date.getFullYear();
9227
- const month = date.getMonth();
9228
- return changeYearMonthAndClampDate(date, year + amount, month);
9229
- };
9230
-
9231
- const extractDateFormat = function(format) {
9232
- return format
9233
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
9234
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
9235
- .trim();
9236
- };
9237
-
9238
- const extractTimeFormat = function(format) {
9239
- return format
9240
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
9241
- .trim();
9242
- };
9243
-
9244
- const validateRangeInOneMonth = function(start, end) {
9245
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
9246
- };
9247
-
8837
+ */
8838
+ fecha.parse = function (dateStr, format) {
8839
+ if (typeof format !== 'string') {
8840
+ throw new Error('Invalid format in fecha.parse');
8841
+ }
8842
+
8843
+ format = fecha.masks[format] || format;
8844
+
8845
+ // Avoid regular expression denial of service, fail early for really long strings
8846
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
8847
+ if (dateStr.length > 1000) {
8848
+ return null;
8849
+ }
8850
+
8851
+ var dateInfo = {};
8852
+ var parseInfo = [];
8853
+ var literals = [];
8854
+ format = format.replace(literal, function ($0, $1) {
8855
+ literals.push($1);
8856
+ return '@@@';
8857
+ });
8858
+ var newFormat = regexEscape(format).replace(token, function ($0) {
8859
+ if (parseFlags[$0]) {
8860
+ var info = parseFlags[$0];
8861
+ parseInfo.push(info[1]);
8862
+ return '(' + info[0] + ')';
8863
+ }
8864
+
8865
+ return $0;
8866
+ });
8867
+ newFormat = newFormat.replace(/@@@/g, function () {
8868
+ return literals.shift();
8869
+ });
8870
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
8871
+ if (!matches) {
8872
+ return null;
8873
+ }
8874
+
8875
+ for (var i = 1; i < matches.length; i++) {
8876
+ parseInfo[i - 1](dateInfo, matches[i]);
8877
+ }
8878
+
8879
+ var today = new Date();
8880
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
8881
+ dateInfo.hour = +dateInfo.hour + 12;
8882
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
8883
+ dateInfo.hour = 0;
8884
+ }
8885
+
8886
+ var date = void 0;
8887
+ if (dateInfo.timezoneOffset != null) {
8888
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
8889
+ 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));
8890
+ } else {
8891
+ 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);
8892
+ }
8893
+ return date;
8894
+ };
8895
+
8896
+ // 导出fecha对象
8897
+
8898
+
8899
+ // 以下是从date-util.js合并的函数
8900
+ var newArray = function newArray(start, end) {
8901
+ var result = [];
8902
+ for (var i = start; i <= end; i++) {
8903
+ result.push(i);
8904
+ }
8905
+ return result;
8906
+ };
8907
+
8908
+ var getSettings = function getSettings() {
8909
+ return {
8910
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
8911
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
8912
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
8913
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
8914
+ amPm: ['上午', '下午']
8915
+ };
8916
+ };
8917
+
8918
+ var toDate = function toDate(date) {
8919
+ return isDate(date) ? new Date(date) : null;
8920
+ };
8921
+
8922
+ var isDate = function isDate(date) {
8923
+ if (date === null || date === undefined) return false;
8924
+ if (isNaN(new Date(date).getTime())) return false;
8925
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
8926
+ return true;
8927
+ };
8928
+
8929
+ var isDateObject = function isDateObject(val) {
8930
+ return val instanceof Date;
8931
+ };
8932
+
8933
+ var formatDate = function formatDate(date) {
8934
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
8935
+
8936
+ // 处理多种输入类型
8937
+ if (!date) return '';
8938
+
8939
+ // 如果是时间戳,转成日期对象
8940
+ if (typeof date === 'number') {
8941
+ date = new Date(date);
8942
+ }
8943
+ // 如果是字符串,转成日期对象
8944
+ if (typeof date === 'string') {
8945
+ date = new Date(date);
8946
+ }
8947
+
8948
+ // 调用toDate进一步验证和转换
8949
+ date = toDate(date);
8950
+ if (!date) return '';
8951
+
8952
+ // 兼容大写和小写的格式标记
8953
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
8954
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
8955
+
8956
+ // 使用fecha库进行格式化,支持中文配置
8957
+ var str = fecha.format(date, lowercaseFormat, getSettings());
8958
+ return str;
8959
+ };
8960
+
8961
+ var parseDate = function parseDate(string, format) {
8962
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
8963
+ };
8964
+
8965
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
8966
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
8967
+ return 30;
8968
+ }
8969
+
8970
+ if (month === 1) {
8971
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
8972
+ return 29;
8973
+ } else {
8974
+ return 28;
8975
+ }
8976
+ }
8977
+
8978
+ return 31;
8979
+ };
8980
+
8981
+ var getDayCountOfYear = function getDayCountOfYear(year) {
8982
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
8983
+ return isLeapYear ? 366 : 365;
8984
+ };
8985
+
8986
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
8987
+ var temp = new Date(date.getTime());
8988
+ temp.setDate(1);
8989
+ return temp.getDay();
8990
+ };
8991
+
8992
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
8993
+ // {prev, next} Date should work for Daylight Saving Time
8994
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
8995
+ var prevDate = function prevDate(date) {
8996
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
8997
+
8998
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
8999
+ };
9000
+
9001
+ var nextDate = function nextDate(date) {
9002
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
9003
+
9004
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
9005
+ };
9006
+
9007
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
9008
+ var result = new Date(year, month, 1);
9009
+ var day = result.getDay();
9010
+
9011
+ if (day === 0) {
9012
+ return prevDate(result, 7);
9013
+ } else {
9014
+ return prevDate(result, day);
9015
+ }
9016
+ };
9017
+
9018
+ var getWeekNumber = function getWeekNumber(date) {
9019
+ // 支持多种输入类型
9020
+ if (!date || !isDate(date)) {
9021
+ date = new Date();
9022
+ }
9023
+ if (typeof date === 'string') {
9024
+ date = new Date(date);
9025
+ }
9026
+
9027
+ // 验证日期有效性
9028
+ if (!isDate(date)) return null;
9029
+
9030
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
9031
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
9032
+ // 将星期日的星期数设为7
9033
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
9034
+ // 获取当年的第一天
9035
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
9036
+ // 计算到最近的星期四的完整周数
9037
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
9038
+ // 返回周数
9039
+ return weekNo;
9040
+ };
9041
+
9042
+ var getRangeHours = function getRangeHours(ranges) {
9043
+ var hours = [];
9044
+ var disabledHours = [];
9045
+
9046
+ (ranges || []).forEach(function (range) {
9047
+ var value = range.map(function (date) {
9048
+ return date.getHours();
9049
+ });
9050
+
9051
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
9052
+ });
9053
+
9054
+ if (disabledHours.length) {
9055
+ for (var i = 0; i < 24; i++) {
9056
+ hours[i] = disabledHours.indexOf(i) === -1;
9057
+ }
9058
+ } else {
9059
+ for (var _i = 0; _i < 24; _i++) {
9060
+ hours[_i] = false;
9061
+ }
9062
+ }
9063
+
9064
+ return hours;
9065
+ };
9066
+
9067
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
9068
+ if (amount <= 0) return [];
9069
+ var temp = new Date(date.getTime());
9070
+ temp.setDate(0);
9071
+ var lastDay = temp.getDate();
9072
+ return range(amount).map(function (_, index) {
9073
+ return lastDay - (amount - index - 1);
9074
+ });
9075
+ };
9076
+
9077
+ var getMonthDays = function getMonthDays(date) {
9078
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
9079
+ var days = temp.getDate();
9080
+ return range(days).map(function (_, index) {
9081
+ return index + 1;
9082
+ });
9083
+ };
9084
+
9085
+ function setRangeData(arr, start, end, value) {
9086
+ for (var i = start; i < end; i++) {
9087
+ arr[i] = value;
9088
+ }
9089
+ }
9090
+
9091
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
9092
+ var minutes = new Array(60);
9093
+
9094
+ if (ranges.length > 0) {
9095
+ ranges.forEach(function (range) {
9096
+ var start = range[0];
9097
+ var end = range[1];
9098
+ var startHour = start.getHours();
9099
+ var startMinute = start.getMinutes();
9100
+ var endHour = end.getHours();
9101
+ var endMinute = end.getMinutes();
9102
+ if (startHour === hour && endHour !== hour) {
9103
+ setRangeData(minutes, startMinute, 60, true);
9104
+ } else if (startHour === hour && endHour === hour) {
9105
+ setRangeData(minutes, startMinute, endMinute + 1, true);
9106
+ } else if (startHour !== hour && endHour === hour) {
9107
+ setRangeData(minutes, 0, endMinute + 1, true);
9108
+ } else if (startHour < hour && endHour > hour) {
9109
+ setRangeData(minutes, 0, 60, true);
9110
+ }
9111
+ });
9112
+ } else {
9113
+ setRangeData(minutes, 0, 60, true);
9114
+ }
9115
+ return minutes;
9116
+ };
9117
+
9118
+ var range = function range(n) {
9119
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
9120
+ return Array.apply(null, { length: n }).map(function (_, n) {
9121
+ return n;
9122
+ });
9123
+ };
9124
+
9125
+ var modifyDate = function modifyDate(date, y, m, d) {
9126
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
9127
+ };
9128
+
9129
+ var modifyTime = function modifyTime(date, h, m, s) {
9130
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
9131
+ };
9132
+
9133
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
9134
+ if (date == null || !time) {
9135
+ return date;
9136
+ }
9137
+ time = parseDate(time, 'HH:mm:ss');
9138
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
9139
+ };
9140
+
9141
+ var clearTime = function clearTime(date) {
9142
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
9143
+ };
9144
+
9145
+ var clearMilliseconds = function clearMilliseconds(date) {
9146
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
9147
+ };
9148
+
9149
+ var limitTimeRange = function limitTimeRange(date, ranges) {
9150
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
9151
+
9152
+ // TODO: refactory a more elegant solution
9153
+ if (ranges.length === 0) return date;
9154
+ var normalizeDate = function normalizeDate(date) {
9155
+ return fecha.parse(fecha.format(date, format), format);
9156
+ };
9157
+ var ndate = normalizeDate(date);
9158
+ var nranges = ranges.map(function (range) {
9159
+ return range.map(normalizeDate);
9160
+ });
9161
+ if (nranges.some(function (nrange) {
9162
+ return ndate >= nrange[0] && ndate <= nrange[1];
9163
+ })) return date;
9164
+
9165
+ var minDate = nranges[0][0];
9166
+ var maxDate = nranges[0][0];
9167
+
9168
+ nranges.forEach(function (nrange) {
9169
+ minDate = new Date(Math.min(nrange[0], minDate));
9170
+ maxDate = new Date(Math.max(nrange[1], minDate));
9171
+ });
9172
+
9173
+ var ret = ndate < minDate ? minDate : maxDate;
9174
+ // preserve Year/Month/Date
9175
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
9176
+ };
9177
+
9178
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
9179
+ var limitedDate = limitTimeRange(date, selectableRange, format);
9180
+ return limitedDate.getTime() === date.getTime();
9181
+ };
9182
+
9183
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
9184
+ // clamp date to the number of days in `year`, `month`
9185
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
9186
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
9187
+ return modifyDate(date, year, month, monthDate);
9188
+ };
9189
+
9190
+ var prevMonth = function prevMonth(date) {
9191
+ var year = date.getFullYear();
9192
+ var month = date.getMonth();
9193
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
9194
+ };
9195
+
9196
+ var nextMonth = function nextMonth(date) {
9197
+ var year = date.getFullYear();
9198
+ var month = date.getMonth();
9199
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
9200
+ };
9201
+
9202
+ var prevYear = function prevYear(date) {
9203
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
9204
+
9205
+ var year = date.getFullYear();
9206
+ var month = date.getMonth();
9207
+ return changeYearMonthAndClampDate(date, year - amount, month);
9208
+ };
9209
+
9210
+ var nextYear = function nextYear(date) {
9211
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
9212
+
9213
+ var year = date.getFullYear();
9214
+ var month = date.getMonth();
9215
+ return changeYearMonthAndClampDate(date, year + amount, month);
9216
+ };
9217
+
9218
+ var extractDateFormat = function extractDateFormat(format) {
9219
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
9220
+ };
9221
+
9222
+ var extractTimeFormat = function extractTimeFormat(format) {
9223
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
9224
+ };
9225
+
9226
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
9227
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
9228
+ };
9229
+
9248
9230
  /**
9249
9231
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
9250
9232
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
9251
9233
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
9252
9234
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
9253
9235
  * @returns {number} 工作日数量
9254
- */
9255
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
9256
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
9257
- throw new Error(
9258
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
9259
- );
9260
- }
9261
-
9262
- const startDateObj = new Date(start_date);
9263
- const endDateObj = new Date(end_date);
9264
-
9265
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
9266
- throw new Error(
9267
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
9268
- );
9269
- }
9270
-
9271
- if (startDateObj > endDateObj) {
9272
- throw new Error('Start date should be earlier than or equal to end date.');
9273
- }
9274
-
9275
- let workdays = 0;
9276
-
9277
- // Iterate through each day in the date range
9278
- for (
9279
- let currentDate = new Date(startDateObj);
9280
- currentDate <= endDateObj;
9281
- currentDate.setDate(currentDate.getDate() + 1)
9282
- ) {
9283
- // Check if the current day is a weekend (Saturday or Sunday)
9284
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
9285
-
9286
- // Check if the current day is a holiday
9287
- const isHoliday = holidays.some((holiday) => {
9288
- const holidayDate = new Date(holiday);
9289
- return currentDate.toDateString() === holidayDate.toDateString();
9290
- });
9291
-
9292
- // If it's a workday (not a weekend or holiday), increment the workdays count
9293
- if (!isWeekend && !isHoliday) {
9294
- workdays++;
9295
- }
9296
- }
9297
-
9298
- return workdays;
9299
- };
9300
-
9236
+ */
9237
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
9238
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
9239
+
9240
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
9241
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
9242
+ }
9243
+
9244
+ var startDateObj = new Date(start_date);
9245
+ var endDateObj = new Date(end_date);
9246
+
9247
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
9248
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
9249
+ }
9250
+
9251
+ if (startDateObj > endDateObj) {
9252
+ throw new Error('Start date should be earlier than or equal to end date.');
9253
+ }
9254
+
9255
+ var workdays = 0;
9256
+
9257
+ // Iterate through each day in the date range
9258
+
9259
+ var _loop = function _loop(currentDate) {
9260
+ // Check if the current day is a weekend (Saturday or Sunday)
9261
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
9262
+
9263
+ // Check if the current day is a holiday
9264
+ var isHoliday = holidays.some(function (holiday) {
9265
+ var holidayDate = new Date(holiday);
9266
+ return currentDate.toDateString() === holidayDate.toDateString();
9267
+ });
9268
+
9269
+ // If it's a workday (not a weekend or holiday), increment the workdays count
9270
+ if (!isWeekend && !isHoliday) {
9271
+ workdays++;
9272
+ }
9273
+ };
9274
+
9275
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
9276
+ _loop(currentDate);
9277
+ }
9278
+
9279
+ return workdays;
9280
+ };
9281
+
9301
9282
  /**
9302
9283
  * 日期加减天数
9303
9284
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
9304
9285
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
9305
9286
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
9306
- */
9307
- const dateAddDays = function (start_date, days) {
9308
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
9309
- throw new Error(
9310
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
9311
- );
9312
- }
9313
-
9314
- const startDateObj = new Date(start_date);
9315
- if (isNaN(startDateObj.getTime())) {
9316
- throw new Error(
9317
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
9318
- );
9319
- }
9320
-
9321
- const resultDateObj = new Date(startDateObj);
9322
- resultDateObj.setDate(resultDateObj.getDate() + days);
9323
-
9324
- const resultYear = resultDateObj.getFullYear();
9325
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
9326
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
9327
-
9328
- return `${resultYear}-${resultMonth}-${resultDay}`;
9329
- };
9330
-
9287
+ */
9288
+ var dateAddDays = function dateAddDays(start_date, days) {
9289
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
9290
+ 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.");
9291
+ }
9292
+
9293
+ var startDateObj = new Date(start_date);
9294
+ if (isNaN(startDateObj.getTime())) {
9295
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
9296
+ }
9297
+
9298
+ var resultDateObj = new Date(startDateObj);
9299
+ resultDateObj.setDate(resultDateObj.getDate() + days);
9300
+
9301
+ var resultYear = resultDateObj.getFullYear();
9302
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
9303
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
9304
+
9305
+ return resultYear + '-' + resultMonth + '-' + resultDay;
9306
+ };
9307
+
9331
9308
  /**
9332
9309
  * 计算两个日期之间的差值
9333
9310
  * @date 2023年12月14日
@@ -9335,182 +9312,180 @@ const dateAddDays = function (start_date, days) {
9335
9312
  * @param {String} end_date - 结束日期字符串
9336
9313
  * @param {String} unit - 单位:year/month/day
9337
9314
  * @returns {Number} 差值
9338
- */
9339
- const dateDiff = function (start_date, end_date, unit = 'day') {
9340
- // Assuming date strings are in "YYYY-MM-DD" format
9341
- var startDate = new Date(start_date);
9342
- var endDate = new Date(end_date);
9343
-
9344
- // If the date is invalid, return 0
9345
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
9346
- return 0;
9347
- }
9348
-
9349
- if (unit === 'year') {
9350
- return endDate.getFullYear() - startDate.getFullYear();
9351
- } else if (unit === 'month') {
9352
- return (
9353
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
9354
- (endDate.getMonth() - startDate.getMonth())
9355
- );
9356
- } else {
9357
- // Default to day
9358
- var timeDifference = endDate - startDate;
9359
- // Calculate days (86400000 milliseconds per day)
9360
- return Math.floor(timeDifference / 86400000);
9361
- }
9362
- };
9363
-
9315
+ */
9316
+ var dateDiff = function dateDiff(start_date, end_date) {
9317
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
9318
+
9319
+ // Assuming date strings are in "YYYY-MM-DD" format
9320
+ var startDate = new Date(start_date);
9321
+ var endDate = new Date(end_date);
9322
+
9323
+ // If the date is invalid, return 0
9324
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
9325
+ return 0;
9326
+ }
9327
+
9328
+ if (unit === 'year') {
9329
+ return endDate.getFullYear() - startDate.getFullYear();
9330
+ } else if (unit === 'month') {
9331
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
9332
+ } else {
9333
+ // Default to day
9334
+ var timeDifference = endDate - startDate;
9335
+ // Calculate days (86400000 milliseconds per day)
9336
+ return Math.floor(timeDifference / 86400000);
9337
+ }
9338
+ };
9339
+
9364
9340
  /**
9365
9341
  * 获取月份中的日期
9366
9342
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
9367
9343
  * @returns {number} 月份中的日期(1-31)
9368
- */
9369
- const dayOfMonth = function (date) {
9370
- if (typeof date !== 'string') {
9371
- throw new Error(
9372
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
9373
- );
9374
- }
9375
-
9376
- const dateObj = new Date(date);
9377
- if (isNaN(dateObj.getTime())) {
9378
- throw new Error(
9379
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
9380
- );
9381
- }
9382
-
9383
- return dateObj.getDate();
9384
- };
9385
-
9344
+ */
9345
+ var dayOfMonth = function dayOfMonth(date) {
9346
+ if (typeof date !== 'string') {
9347
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
9348
+ }
9349
+
9350
+ var dateObj = new Date(date);
9351
+ if (isNaN(dateObj.getTime())) {
9352
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
9353
+ }
9354
+
9355
+ return dateObj.getDate();
9356
+ };
9357
+
9386
9358
  /**
9387
9359
  * 获取当前日期
9388
9360
  * @date 2022年5月7日
9389
9361
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
9390
9362
  * @returns {string} 当前日期的格式化字符串
9391
- */
9392
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
9393
- return formatDate(new Date(), format);
9394
- };
9395
-
9363
+ */
9364
+ var getCurrentDate = function getCurrentDate() {
9365
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
9366
+
9367
+ return formatDate(new Date(), format);
9368
+ };
9369
+
9396
9370
  /**
9397
9371
  * 获取当前日期时间
9398
9372
  * @date 2022年5月7日
9399
9373
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
9400
9374
  * @returns {string} 当前日期时间的格式化字符串
9401
- */
9402
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
9403
- return formatDate(new Date(), format);
9404
- };
9405
-
9375
+ */
9376
+ var getCurrentDateTime = function getCurrentDateTime() {
9377
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
9378
+
9379
+ return formatDate(new Date(), format);
9380
+ };
9381
+
9406
9382
  /**
9407
9383
  * 获取小时
9408
9384
  * @date 2022年5月7日
9409
9385
  * @param {Date|string} [date] - 日期对象或日期字符串
9410
9386
  * @returns {number} 小时数(0-23)
9411
- */
9412
- const getHour = function (date) {
9413
- if (!date) {
9414
- return new Date().getHours();
9415
- }
9416
- if (typeof date === 'string') {
9417
- date = new Date(date);
9418
- }
9419
- return date.getHours();
9420
- };
9421
-
9387
+ */
9388
+ var getHour = function getHour(date) {
9389
+ if (!date) {
9390
+ return new Date().getHours();
9391
+ }
9392
+ if (typeof date === 'string') {
9393
+ date = new Date(date);
9394
+ }
9395
+ return date.getHours();
9396
+ };
9397
+
9422
9398
  /**
9423
9399
  * 获取分钟
9424
9400
  * @date 2022年5月7日
9425
9401
  * @param {Date|string} [date] - 日期对象或日期字符串
9426
9402
  * @returns {number} 分钟数(0-59)
9427
- */
9428
- const getMinute = function (date) {
9429
- if (!date) {
9430
- return new Date().getMinutes();
9431
- }
9432
- if (typeof date === 'string') {
9433
- date = new Date(date);
9434
- }
9435
- return date.getMinutes();
9436
- };
9437
-
9403
+ */
9404
+ var getMinute = function getMinute(date) {
9405
+ if (!date) {
9406
+ return new Date().getMinutes();
9407
+ }
9408
+ if (typeof date === 'string') {
9409
+ date = new Date(date);
9410
+ }
9411
+ return date.getMinutes();
9412
+ };
9413
+
9438
9414
  /**
9439
9415
  * 获取月份
9440
9416
  * @date 2022年5月7日
9441
9417
  * @param {Date|string} [date] - 日期对象或日期字符串
9442
9418
  * @returns {number} 月份数(1-12)
9443
- */
9444
- const getMonth = function (date) {
9445
- if (!date) {
9446
- return new Date().getMonth() + 1;
9447
- }
9448
- if (typeof date === 'string') {
9449
- date = new Date(date);
9450
- }
9451
- return date.getMonth() + 1;
9452
- };
9453
-
9419
+ */
9420
+ var getMonth = function getMonth(date) {
9421
+ if (!date) {
9422
+ return new Date().getMonth() + 1;
9423
+ }
9424
+ if (typeof date === 'string') {
9425
+ date = new Date(date);
9426
+ }
9427
+ return date.getMonth() + 1;
9428
+ };
9429
+
9454
9430
  /**
9455
9431
  * 获取秒
9456
9432
  * @date 2022年5月7日
9457
9433
  * @param {Date|string} [date] - 日期对象或日期字符串
9458
9434
  * @returns {number} 秒数(0-59)
9459
- */
9460
- const getSecond = function (date) {
9461
- if (!date) {
9462
- return new Date().getSeconds();
9463
- }
9464
- if (typeof date === 'string') {
9465
- date = new Date(date);
9466
- }
9467
- return date.getSeconds();
9468
- };
9469
-
9435
+ */
9436
+ var getSecond = function getSecond(date) {
9437
+ if (!date) {
9438
+ return new Date().getSeconds();
9439
+ }
9440
+ if (typeof date === 'string') {
9441
+ date = new Date(date);
9442
+ }
9443
+ return date.getSeconds();
9444
+ };
9445
+
9470
9446
  /**
9471
9447
  * 获取星期几
9472
9448
  * @date 2022年5月7日
9473
9449
  * @param {Date|string} [date] - 日期对象或日期字符串
9474
9450
  * @returns {number} 星期几(0-6,0表示星期日)
9475
- */
9476
- const getWeekday = function (date) {
9477
- if (!date) {
9478
- return new Date().getDay();
9479
- }
9480
- if (typeof date === 'string') {
9481
- date = new Date(date);
9482
- }
9483
- return date.getDay();
9484
- };
9485
-
9486
-
9451
+ */
9452
+ var getWeekday = function getWeekday(date) {
9453
+ if (!date) {
9454
+ return new Date().getDay();
9455
+ }
9456
+ if (typeof date === 'string') {
9457
+ date = new Date(date);
9458
+ }
9459
+ return date.getDay();
9460
+ };
9461
+
9487
9462
  /**
9488
9463
  * @desc 获取上午/下午/晚上
9489
9464
  * @author huangbo
9490
9465
  * @date 2022年5月7日
9491
9466
  * @param {String} [time] - 时间
9492
- **/
9493
- const timeCycle = function (time) {
9494
- let hour = 0;
9495
- if (!time) {
9496
- hour = new Date().getHours();
9497
- } else if (typeof time === 'string') {
9498
- // 从时间字符串中提取小时
9499
- const match = time.match(/^(\d{1,2})/);
9500
- if (match) {
9501
- hour = parseInt(match[1], 10);
9502
- }
9503
- } else if (typeof time === 'number') {
9504
- hour = time;
9505
- }
9506
- // 判断时间段
9507
- if (hour >= 5 && hour < 12) {
9508
- return '上午';
9509
- } else if (hour >= 12 && hour < 18) {
9510
- return '下午';
9511
- } else {
9512
- return '晚上';
9513
- }
9467
+ **/
9468
+ var timeCycle = function timeCycle(time) {
9469
+ var hour = 0;
9470
+ if (!time) {
9471
+ hour = new Date().getHours();
9472
+ } else if (typeof time === 'string') {
9473
+ // 从时间字符串中提取小时
9474
+ var match = time.match(/^(\d{1,2})/);
9475
+ if (match) {
9476
+ hour = parseInt(match[1], 10);
9477
+ }
9478
+ } else if (typeof time === 'number') {
9479
+ hour = time;
9480
+ }
9481
+ // 判断时间段
9482
+ if (hour >= 5 && hour < 12) {
9483
+ return '上午';
9484
+ } else if (hour >= 12 && hour < 18) {
9485
+ return '下午';
9486
+ } else {
9487
+ return '晚上';
9488
+ }
9514
9489
  };
9515
9490
 
9516
9491
  /***/ }),