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/form-item.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 = 162);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 166);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3285,12 +3285,12 @@ var warning = function warning(content, _callback3) {
3285
3285
 
3286
3286
  /***/ }),
3287
3287
 
3288
- /***/ 102:
3288
+ /***/ 104:
3289
3289
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3290
3290
 
3291
3291
  "use strict";
3292
3292
 
3293
- // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/form/src/form-item.vue?vue&type=template&id=5f256888&
3293
+ // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/form/src/form-item.vue?vue&type=template&id=53ae977c&
3294
3294
  var render = function () {
3295
3295
  var _vm = this
3296
3296
  var _h = _vm.$createElement
@@ -3391,10 +3391,10 @@ var staticRenderFns = []
3391
3391
  render._withStripped = true
3392
3392
 
3393
3393
 
3394
- // CONCATENATED MODULE: ./packages/form/src/form-item.vue?vue&type=template&id=5f256888&
3394
+ // CONCATENATED MODULE: ./packages/form/src/form-item.vue?vue&type=template&id=53ae977c&
3395
3395
 
3396
3396
  // EXTERNAL MODULE: external "async-validator"
3397
- var external_async_validator_ = __webpack_require__(118);
3397
+ var external_async_validator_ = __webpack_require__(122);
3398
3398
  var external_async_validator_default = /*#__PURE__*/__webpack_require__.n(external_async_validator_);
3399
3399
 
3400
3400
  // EXTERNAL MODULE: ./src/mixins/emitter.js
@@ -3484,7 +3484,7 @@ var icon_ = __webpack_require__(26);
3484
3484
  var icon_default = /*#__PURE__*/__webpack_require__.n(icon_);
3485
3485
 
3486
3486
  // EXTERNAL MODULE: external "eoss/lib/tips"
3487
- var tips_ = __webpack_require__(119);
3487
+ var tips_ = __webpack_require__(123);
3488
3488
  var tips_default = /*#__PURE__*/__webpack_require__.n(tips_);
3489
3489
 
3490
3490
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/form/src/label-wrap.vue?vue&type=script&lang=js&
@@ -3946,10 +3946,10 @@ function debounce(fn) {
3946
3946
  width: this.span / 12 * 100 + '%'
3947
3947
  };
3948
3948
  }
3949
- var col = this.esForm.col;
3950
- if (col > 1) {
3949
+ var columns = this.esForm.columns;
3950
+ if (columns > 1) {
3951
3951
  return {
3952
- width: 100 / col + '%'
3952
+ width: 100 / columns + '%'
3953
3953
  };
3954
3954
  }
3955
3955
  return {};
@@ -4279,20 +4279,6 @@ var form_item_component = Object(componentNormalizer["a" /* default */])(
4279
4279
 
4280
4280
  /***/ }),
4281
4281
 
4282
- /***/ 118:
4283
- /***/ (function(module, exports) {
4284
-
4285
- module.exports = require("async-validator");
4286
-
4287
- /***/ }),
4288
-
4289
- /***/ 119:
4290
- /***/ (function(module, exports) {
4291
-
4292
- module.exports = require("eoss/lib/tips");
4293
-
4294
- /***/ }),
4295
-
4296
4282
  /***/ 12:
4297
4283
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4298
4284
 
@@ -4494,6 +4480,20 @@ var getRgb = function getRgb($color) {
4494
4480
 
4495
4481
  /***/ }),
4496
4482
 
4483
+ /***/ 122:
4484
+ /***/ (function(module, exports) {
4485
+
4486
+ module.exports = require("async-validator");
4487
+
4488
+ /***/ }),
4489
+
4490
+ /***/ 123:
4491
+ /***/ (function(module, exports) {
4492
+
4493
+ module.exports = require("eoss/lib/tips");
4494
+
4495
+ /***/ }),
4496
+
4497
4497
  /***/ 15:
4498
4498
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4499
4499
 
@@ -4541,12 +4541,12 @@ module.exports = require("eoss/lib/loading");
4541
4541
 
4542
4542
  /***/ }),
4543
4543
 
4544
- /***/ 162:
4544
+ /***/ 166:
4545
4545
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4546
4546
 
4547
4547
  "use strict";
4548
4548
  __webpack_require__.r(__webpack_exports__);
4549
- /* harmony import */ var _form_src_form_item__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(102);
4549
+ /* harmony import */ var _form_src_form_item__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(104);
4550
4550
 
4551
4551
 
4552
4552
  /* istanbul ignore next */
@@ -4837,759 +4837,736 @@ function normalizeComponent(
4837
4837
  /* unused harmony export getSecond */
4838
4838
  /* unused harmony export getWeekday */
4839
4839
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
4840
- /* Modified from https://github.com/taylorhakes/fecha
4841
- *
4842
- * The MIT License (MIT)
4843
- *
4844
- * Copyright (c) 2015 Taylor Hakes
4845
- *
4846
- * Permission is hereby granted, free of charge, to any person obtaining a copy
4847
- * of this software and associated documentation files (the "Software"), to deal
4848
- * in the Software without restriction, including without limitation the rights
4849
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4850
- * copies of the Software, and to permit persons to whom the Software is
4851
- * furnished to do so, subject to the following conditions:
4852
- *
4853
- * The above copyright notice and this permission notice shall be included in all
4854
- * copies or substantial portions of the Software.
4855
- *
4856
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4857
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4858
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4859
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4860
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4861
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4862
- * SOFTWARE.
4863
- */
4864
-
4865
- /*eslint-disable*/
4866
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
4867
-
4868
-
4840
+
4841
+
4869
4842
  /**
4870
4843
  * Parse or format dates
4871
4844
  * @class fecha
4872
- */
4873
- const fecha = {};
4874
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4875
- const twoDigits = '\\d\\d?';
4876
- const threeDigits = '\\d{3}';
4877
- const fourDigits = '\\d{4}';
4878
- const word = '[^\\s]+';
4879
- const literal = /\[([^]*?)\]/gm;
4880
- const noop = function () {};
4881
-
4882
- function regexEscape(str) {
4883
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
4884
- }
4885
-
4886
- function shorten(arr, sLen) {
4887
- const newArr = [];
4888
- for (let i = 0, len = arr.length; i < len; i++) {
4889
- newArr.push(arr[i].substr(0, sLen));
4890
- }
4891
- return newArr;
4892
- }
4893
-
4894
- function monthUpdate() {
4895
- return function (d, v) {
4896
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
4897
- if (~index) {
4898
- d.month = index;
4899
- }
4900
- };
4901
- }
4902
-
4903
- function pad(val, len) {
4904
- val = String(val);
4905
- len = len || 2;
4906
- while (val.length < len) {
4907
- val = '0' + val;
4908
- }
4909
- return val;
4910
- }
4911
-
4912
- // 直接使用中文日期名称常量
4913
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
4914
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
4915
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
4916
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
4917
- const amPm = ['上午', '下午'];
4918
- const DoFn = function DoFn(D) {
4919
- return D + '日';
4920
- };
4921
-
4922
- const formatFlags = {
4923
- D: function(dateObj) {
4924
- return dateObj.getDay();
4925
- },
4926
- DD: function(dateObj) {
4927
- return pad(dateObj.getDay());
4928
- },
4929
- Do: function(dateObj) {
4930
- return DoFn(dateObj.getDate());
4931
- },
4932
- d: function(dateObj) {
4933
- return dateObj.getDate();
4934
- },
4935
- dd: function(dateObj) {
4936
- return pad(dateObj.getDate());
4937
- },
4938
- ddd: function(dateObj) {
4939
- return dayNamesShort[dateObj.getDay()];
4940
- },
4941
- dddd: function(dateObj) {
4942
- return dayNames[dateObj.getDay()];
4943
- },
4944
- M: function(dateObj) {
4945
- return dateObj.getMonth() + 1;
4946
- },
4947
- MM: function(dateObj) {
4948
- return pad(dateObj.getMonth() + 1);
4949
- },
4950
- MMM: function(dateObj) {
4951
- return monthNamesShort[dateObj.getMonth()];
4952
- },
4953
- MMMM: function(dateObj) {
4954
- return monthNames[dateObj.getMonth()];
4955
- },
4956
- yy: function(dateObj) {
4957
- return pad(String(dateObj.getFullYear()), 4).substr(2);
4958
- },
4959
- yyyy: function(dateObj) {
4960
- return pad(dateObj.getFullYear(), 4);
4961
- },
4962
- h: function(dateObj) {
4963
- return dateObj.getHours() % 12 || 12;
4964
- },
4965
- hh: function(dateObj) {
4966
- return pad(dateObj.getHours() % 12 || 12);
4967
- },
4968
- H: function(dateObj) {
4969
- return dateObj.getHours();
4970
- },
4971
- HH: function(dateObj) {
4972
- return pad(dateObj.getHours());
4973
- },
4974
- m: function(dateObj) {
4975
- return dateObj.getMinutes();
4976
- },
4977
- mm: function(dateObj) {
4978
- return pad(dateObj.getMinutes());
4979
- },
4980
- s: function(dateObj) {
4981
- return dateObj.getSeconds();
4982
- },
4983
- ss: function(dateObj) {
4984
- return pad(dateObj.getSeconds());
4985
- },
4986
- S: function(dateObj) {
4987
- return Math.round(dateObj.getMilliseconds() / 100);
4988
- },
4989
- SS: function(dateObj) {
4990
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
4991
- },
4992
- SSS: function(dateObj) {
4993
- return pad(dateObj.getMilliseconds(), 3);
4994
- },
4995
- a: function(dateObj) {
4996
- return dateObj.getHours() < 12 ? '上午' : '下午';
4997
- },
4998
- A: function(dateObj) {
4999
- return dateObj.getHours() < 12 ? '上午' : '下午';
5000
- },
5001
- ZZ: function(dateObj) {
5002
- const o = dateObj.getTimezoneOffset();
5003
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5004
- }
5005
- };
5006
-
5007
- const parseFlags = {
5008
- d: [twoDigits, function (d, v) {
5009
- d.day = v;
5010
- }],
5011
- Do: [twoDigits + word, function (d, v) {
5012
- d.day = parseInt(v, 10);
5013
- }],
5014
- M: [twoDigits, function (d, v) {
5015
- d.month = v - 1;
5016
- }],
5017
- yy: [twoDigits, function (d, v) {
5018
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
5019
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5020
- }],
5021
- h: [twoDigits, function (d, v) {
5022
- d.hour = v;
5023
- }],
5024
- m: [twoDigits, function (d, v) {
5025
- d.minute = v;
5026
- }],
5027
- s: [twoDigits, function (d, v) {
5028
- d.second = v;
5029
- }],
5030
- yyyy: [fourDigits, function (d, v) {
5031
- d.year = v;
5032
- }],
5033
- S: ['\\d', function (d, v) {
5034
- d.millisecond = v * 100;
5035
- }],
5036
- SS: ['\\d{2}', function (d, v) {
5037
- d.millisecond = v * 10;
5038
- }],
5039
- SSS: [threeDigits, function (d, v) {
5040
- d.millisecond = v;
5041
- }],
5042
- D: [twoDigits, noop],
5043
- ddd: [word, noop],
5044
- MMM: [word, monthUpdate('monthNamesShort')],
5045
- MMMM: [word, monthUpdate('monthNames')],
5046
- a: [word, function (d, v) {
5047
- const val = v.toLowerCase();
5048
- if (val === '上午') {
5049
- d.isPm = false;
5050
- } else if (val === '下午') {
5051
- d.isPm = true;
5052
- }
5053
- }],
5054
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5055
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
5056
-
5057
- if (parts) {
5058
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5059
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5060
- }
5061
- }]
5062
- };
5063
- parseFlags.dd = parseFlags.d;
5064
- parseFlags.dddd = parseFlags.ddd;
5065
- parseFlags.DD = parseFlags.D;
5066
- parseFlags.mm = parseFlags.m;
5067
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5068
- parseFlags.MM = parseFlags.M;
5069
- parseFlags.ss = parseFlags.s;
5070
- parseFlags.A = parseFlags.a;
5071
-
5072
-
5073
- // Some common format strings
5074
- fecha.masks = {
5075
- default: 'ddd MMM dd yyyy HH:mm:ss',
5076
- shortDate: 'M/D/yy',
5077
- mediumDate: 'MMM d, yyyy',
5078
- longDate: 'MMMM d, yyyy',
5079
- fullDate: 'dddd, MMMM d, yyyy',
5080
- shortTime: 'HH:mm',
5081
- mediumTime: 'HH:mm:ss',
5082
- longTime: 'HH:mm:ss.SSS'
5083
- };
5084
-
4845
+ */
4846
+ var fecha = {};
4847
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4848
+ var twoDigits = '\\d\\d?';
4849
+ var threeDigits = '\\d{3}';
4850
+ var fourDigits = '\\d{4}';
4851
+ var word = '[^\\s]+';
4852
+ var literal = /\[([^]*?)\]/gm;
4853
+ var noop = function noop() {};
4854
+
4855
+ function regexEscape(str) {
4856
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
4857
+ }
4858
+
4859
+ function shorten(arr, sLen) {
4860
+ var newArr = [];
4861
+ for (var i = 0, len = arr.length; i < len; i++) {
4862
+ newArr.push(arr[i].substr(0, sLen));
4863
+ }
4864
+ return newArr;
4865
+ }
4866
+
4867
+ function monthUpdate() {
4868
+ return function (d, v) {
4869
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
4870
+ if (~index) {
4871
+ d.month = index;
4872
+ }
4873
+ };
4874
+ }
4875
+
4876
+ function pad(val, len) {
4877
+ val = String(val);
4878
+ len = len || 2;
4879
+ while (val.length < len) {
4880
+ val = '0' + val;
4881
+ }
4882
+ return val;
4883
+ }
4884
+
4885
+ // 直接使用中文日期名称常量
4886
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
4887
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
4888
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
4889
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
4890
+ var amPm = ['上午', '下午'];
4891
+ var DoFn = function DoFn(D) {
4892
+ return D + '日';
4893
+ };
4894
+
4895
+ var formatFlags = {
4896
+ D: function D(dateObj) {
4897
+ return dateObj.getDay();
4898
+ },
4899
+ DD: function DD(dateObj) {
4900
+ return pad(dateObj.getDay());
4901
+ },
4902
+ Do: function Do(dateObj) {
4903
+ return DoFn(dateObj.getDate());
4904
+ },
4905
+ d: function d(dateObj) {
4906
+ return dateObj.getDate();
4907
+ },
4908
+ dd: function dd(dateObj) {
4909
+ return pad(dateObj.getDate());
4910
+ },
4911
+ ddd: function ddd(dateObj) {
4912
+ return dayNamesShort[dateObj.getDay()];
4913
+ },
4914
+ dddd: function dddd(dateObj) {
4915
+ return dayNames[dateObj.getDay()];
4916
+ },
4917
+ M: function M(dateObj) {
4918
+ return dateObj.getMonth() + 1;
4919
+ },
4920
+ MM: function MM(dateObj) {
4921
+ return pad(dateObj.getMonth() + 1);
4922
+ },
4923
+ MMM: function MMM(dateObj) {
4924
+ return monthNamesShort[dateObj.getMonth()];
4925
+ },
4926
+ MMMM: function MMMM(dateObj) {
4927
+ return monthNames[dateObj.getMonth()];
4928
+ },
4929
+ yy: function yy(dateObj) {
4930
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
4931
+ },
4932
+ yyyy: function yyyy(dateObj) {
4933
+ return pad(dateObj.getFullYear(), 4);
4934
+ },
4935
+ h: function h(dateObj) {
4936
+ return dateObj.getHours() % 12 || 12;
4937
+ },
4938
+ hh: function hh(dateObj) {
4939
+ return pad(dateObj.getHours() % 12 || 12);
4940
+ },
4941
+ H: function H(dateObj) {
4942
+ return dateObj.getHours();
4943
+ },
4944
+ HH: function HH(dateObj) {
4945
+ return pad(dateObj.getHours());
4946
+ },
4947
+ m: function m(dateObj) {
4948
+ return dateObj.getMinutes();
4949
+ },
4950
+ mm: function mm(dateObj) {
4951
+ return pad(dateObj.getMinutes());
4952
+ },
4953
+ s: function s(dateObj) {
4954
+ return dateObj.getSeconds();
4955
+ },
4956
+ ss: function ss(dateObj) {
4957
+ return pad(dateObj.getSeconds());
4958
+ },
4959
+ S: function S(dateObj) {
4960
+ return Math.round(dateObj.getMilliseconds() / 100);
4961
+ },
4962
+ SS: function SS(dateObj) {
4963
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
4964
+ },
4965
+ SSS: function SSS(dateObj) {
4966
+ return pad(dateObj.getMilliseconds(), 3);
4967
+ },
4968
+ a: function a(dateObj) {
4969
+ return dateObj.getHours() < 12 ? '上午' : '下午';
4970
+ },
4971
+ A: function A(dateObj) {
4972
+ return dateObj.getHours() < 12 ? '上午' : '下午';
4973
+ },
4974
+ ZZ: function ZZ(dateObj) {
4975
+ var o = dateObj.getTimezoneOffset();
4976
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
4977
+ }
4978
+ };
4979
+
4980
+ var parseFlags = {
4981
+ d: [twoDigits, function (d, v) {
4982
+ d.day = v;
4983
+ }],
4984
+ Do: [twoDigits + word, function (d, v) {
4985
+ d.day = parseInt(v, 10);
4986
+ }],
4987
+ M: [twoDigits, function (d, v) {
4988
+ d.month = v - 1;
4989
+ }],
4990
+ yy: [twoDigits, function (d, v) {
4991
+ var da = new Date(),
4992
+ cent = +('' + da.getFullYear()).substr(0, 2);
4993
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
4994
+ }],
4995
+ h: [twoDigits, function (d, v) {
4996
+ d.hour = v;
4997
+ }],
4998
+ m: [twoDigits, function (d, v) {
4999
+ d.minute = v;
5000
+ }],
5001
+ s: [twoDigits, function (d, v) {
5002
+ d.second = v;
5003
+ }],
5004
+ yyyy: [fourDigits, function (d, v) {
5005
+ d.year = v;
5006
+ }],
5007
+ S: ['\\d', function (d, v) {
5008
+ d.millisecond = v * 100;
5009
+ }],
5010
+ SS: ['\\d{2}', function (d, v) {
5011
+ d.millisecond = v * 10;
5012
+ }],
5013
+ SSS: [threeDigits, function (d, v) {
5014
+ d.millisecond = v;
5015
+ }],
5016
+ D: [twoDigits, noop],
5017
+ ddd: [word, noop],
5018
+ MMM: [word, monthUpdate('monthNamesShort')],
5019
+ MMMM: [word, monthUpdate('monthNames')],
5020
+ a: [word, function (d, v) {
5021
+ var val = v.toLowerCase();
5022
+ if (val === '上午') {
5023
+ d.isPm = false;
5024
+ } else if (val === '下午') {
5025
+ d.isPm = true;
5026
+ }
5027
+ }],
5028
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5029
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
5030
+ minutes = void 0;
5031
+
5032
+ if (parts) {
5033
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5034
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5035
+ }
5036
+ }]
5037
+ };
5038
+ parseFlags.dd = parseFlags.d;
5039
+ parseFlags.dddd = parseFlags.ddd;
5040
+ parseFlags.DD = parseFlags.D;
5041
+ parseFlags.mm = parseFlags.m;
5042
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5043
+ parseFlags.MM = parseFlags.M;
5044
+ parseFlags.ss = parseFlags.s;
5045
+ parseFlags.A = parseFlags.a;
5046
+
5047
+ // Some common format strings
5048
+ fecha.masks = {
5049
+ default: 'ddd MMM dd yyyy HH:mm:ss',
5050
+ shortDate: 'M/D/yy',
5051
+ mediumDate: 'MMM d, yyyy',
5052
+ longDate: 'MMMM d, yyyy',
5053
+ fullDate: 'dddd, MMMM d, yyyy',
5054
+ shortTime: 'HH:mm',
5055
+ mediumTime: 'HH:mm:ss',
5056
+ longTime: 'HH:mm:ss.SSS'
5057
+ };
5058
+
5085
5059
  /***
5086
5060
  * Format a date
5087
5061
  * @method format
5088
5062
  * @param {Date|number} dateObj
5089
5063
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
5090
- */
5091
- fecha.format = function (dateObj, mask) {
5092
- if (typeof dateObj === 'number') {
5093
- dateObj = new Date(dateObj);
5094
- }
5095
-
5096
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5097
- throw new Error('Invalid Date in fecha.format');
5098
- }
5099
-
5100
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
5101
-
5102
- const literals = [];
5103
-
5104
- // Make literals inactive by replacing them with ??
5105
- mask = mask.replace(literal, function($0, $1) {
5106
- literals.push($1);
5107
- return '@@@';
5108
- });
5109
- // Apply formatting rules
5110
- mask = mask.replace(token, function ($0) {
5111
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5112
- });
5113
- // Inline literal values back into the formatted value
5114
- return mask.replace(/@@@/g, function() {
5115
- return literals.shift();
5116
- });
5117
- };
5118
-
5064
+ */
5065
+ fecha.format = function (dateObj, mask) {
5066
+ if (typeof dateObj === 'number') {
5067
+ dateObj = new Date(dateObj);
5068
+ }
5069
+
5070
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5071
+ throw new Error('Invalid Date in fecha.format');
5072
+ }
5073
+
5074
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
5075
+
5076
+ var literals = [];
5077
+
5078
+ // Make literals inactive by replacing them with ??
5079
+ mask = mask.replace(literal, function ($0, $1) {
5080
+ literals.push($1);
5081
+ return '@@@';
5082
+ });
5083
+ // Apply formatting rules
5084
+ mask = mask.replace(token, function ($0) {
5085
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5086
+ });
5087
+ // Inline literal values back into the formatted value
5088
+ return mask.replace(/@@@/g, function () {
5089
+ return literals.shift();
5090
+ });
5091
+ };
5092
+
5119
5093
  /**
5120
5094
  * Parse a date string into an object, changes - into /
5121
5095
  * @method parse
5122
5096
  * @param {string} dateStr Date string
5123
5097
  * @param {string} format Date parse format
5124
5098
  * @returns {Date|boolean}
5125
- */
5126
- fecha.parse = function (dateStr, format) {
5127
- if (typeof format !== 'string') {
5128
- throw new Error('Invalid format in fecha.parse');
5129
- }
5130
-
5131
- format = fecha.masks[format] || format;
5132
-
5133
- // Avoid regular expression denial of service, fail early for really long strings
5134
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5135
- if (dateStr.length > 1000) {
5136
- return null;
5137
- }
5138
-
5139
- const dateInfo = {};
5140
- const parseInfo = [];
5141
- const literals = [];
5142
- format = format.replace(literal, function($0, $1) {
5143
- literals.push($1);
5144
- return '@@@';
5145
- });
5146
- let newFormat = regexEscape(format).replace(token, function ($0) {
5147
- if (parseFlags[$0]) {
5148
- const info = parseFlags[$0];
5149
- parseInfo.push(info[1]);
5150
- return '(' + info[0] + ')';
5151
- }
5152
-
5153
- return $0;
5154
- });
5155
- newFormat = newFormat.replace(/@@@/g, function() {
5156
- return literals.shift();
5157
- });
5158
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
5159
- if (!matches) {
5160
- return null;
5161
- }
5162
-
5163
- for (let i = 1; i < matches.length; i++) {
5164
- parseInfo[i - 1](dateInfo, matches[i]);
5165
- }
5166
-
5167
- const today = new Date();
5168
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5169
- dateInfo.hour = +dateInfo.hour + 12;
5170
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5171
- dateInfo.hour = 0;
5172
- }
5173
-
5174
- let date;
5175
- if (dateInfo.timezoneOffset != null) {
5176
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5177
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5178
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
5179
- } else {
5180
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5181
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
5182
- }
5183
- return date;
5184
- };
5185
-
5186
- // 导出fecha对象
5187
-
5188
-
5189
- // 以下是从date-util.js合并的函数
5190
- const newArray = function(start, end) {
5191
- let result = [];
5192
- for (let i = start; i <= end; i++) {
5193
- result.push(i);
5194
- }
5195
- return result;
5196
- };
5197
-
5198
- const getSettings = () => {
5199
- return {
5200
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5201
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5202
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5203
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5204
- amPm: ['上午', '下午']
5205
- };
5206
- };
5207
-
5208
- const toDate = function(date) {
5209
- return isDate(date) ? new Date(date) : null;
5210
- };
5211
-
5212
- const isDate = function(date) {
5213
- if (date === null || date === undefined) return false;
5214
- if (isNaN(new Date(date).getTime())) return false;
5215
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5216
- return true;
5217
- };
5218
-
5219
- const isDateObject = function(val) {
5220
- return val instanceof Date;
5221
- };
5222
-
5223
- const formatDate = function (date, format = 'yyyy-MM-dd') {
5224
- // 处理多种输入类型
5225
- if (!date) return '';
5226
-
5227
- // 如果是时间戳,转成日期对象
5228
- if (typeof date === 'number') {
5229
- date = new Date(date);
5230
- }
5231
- // 如果是字符串,转成日期对象
5232
- if (typeof date === 'string') {
5233
- date = new Date(date);
5234
- }
5235
-
5236
- // 调用toDate进一步验证和转换
5237
- date = toDate(date);
5238
- if (!date) return '';
5239
-
5240
- // 兼容大写和小写的格式标记
5241
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5242
- const lowercaseFormat = format
5243
- .replace(/YYYY/g, 'yyyy')
5244
- .replace(/D/g, 'd')
5245
-
5246
- // 使用fecha库进行格式化,支持中文配置
5247
- const str = fecha.format(date, lowercaseFormat, getSettings());
5248
- return str;
5249
- };
5250
-
5251
- const parseDate = function(string, format) {
5252
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5253
- };
5254
-
5255
- const getDayCountOfMonth = function(year, month) {
5256
- if (month === 3 || month === 5 || month === 8 || month === 10) {
5257
- return 30;
5258
- }
5259
-
5260
- if (month === 1) {
5261
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5262
- return 29;
5263
- } else {
5264
- return 28;
5265
- }
5266
- }
5267
-
5268
- return 31;
5269
- };
5270
-
5271
- const getDayCountOfYear = function(year) {
5272
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
5273
- return isLeapYear ? 366 : 365;
5274
- };
5275
-
5276
- const getFirstDayOfMonth = function(date) {
5277
- const temp = new Date(date.getTime());
5278
- temp.setDate(1);
5279
- return temp.getDay();
5280
- };
5281
-
5282
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5283
- // {prev, next} Date should work for Daylight Saving Time
5284
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5285
- const prevDate = function(date, amount = 1) {
5286
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5287
- };
5288
-
5289
- const nextDate = function(date, amount = 1) {
5290
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5291
- };
5292
-
5293
- const getStartDateOfMonth = function(year, month) {
5294
- const result = new Date(year, month, 1);
5295
- const day = result.getDay();
5296
-
5297
- if (day === 0) {
5298
- return prevDate(result, 7);
5299
- } else {
5300
- return prevDate(result, day);
5301
- }
5302
- };
5303
-
5304
- const getWeekNumber = function(date) {
5305
- // 支持多种输入类型
5306
- if (!date||!isDate(date)) {
5307
- date = new Date();
5308
- }
5309
- if (typeof date === 'string') {
5310
- date = new Date(date);
5311
- }
5312
-
5313
- // 验证日期有效性
5314
- if (!isDate(date)) return null;
5315
-
5316
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5317
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5318
- // 将星期日的星期数设为7
5319
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5320
- // 获取当年的第一天
5321
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5322
- // 计算到最近的星期四的完整周数
5323
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
5324
- // 返回周数
5325
- return weekNo;
5326
- };
5327
-
5328
- const getRangeHours = function(ranges) {
5329
- const hours = [];
5330
- let disabledHours = [];
5331
-
5332
- (ranges || []).forEach(range => {
5333
- const value = range.map(date => date.getHours());
5334
-
5335
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5336
- });
5337
-
5338
- if (disabledHours.length) {
5339
- for (let i = 0; i < 24; i++) {
5340
- hours[i] = disabledHours.indexOf(i) === -1;
5341
- }
5342
- } else {
5343
- for (let i = 0; i < 24; i++) {
5344
- hours[i] = false;
5345
- }
5346
- }
5347
-
5348
- return hours;
5349
- };
5350
-
5351
- const getPrevMonthLastDays = (date, amount) => {
5352
- if (amount <= 0) return [];
5353
- const temp = new Date(date.getTime());
5354
- temp.setDate(0);
5355
- const lastDay = temp.getDate();
5356
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
5357
- };
5358
-
5359
- const getMonthDays = (date) => {
5360
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5361
- const days = temp.getDate();
5362
- return range(days).map((_, index) => index + 1);
5363
- };
5364
-
5365
- function setRangeData(arr, start, end, value) {
5366
- for (let i = start; i < end; i++) {
5367
- arr[i] = value;
5368
- }
5369
- }
5370
-
5371
- const getRangeMinutes = function(ranges, hour) {
5372
- const minutes = new Array(60);
5373
-
5374
- if (ranges.length > 0) {
5375
- ranges.forEach(range => {
5376
- const start = range[0];
5377
- const end = range[1];
5378
- const startHour = start.getHours();
5379
- const startMinute = start.getMinutes();
5380
- const endHour = end.getHours();
5381
- const endMinute = end.getMinutes();
5382
- if (startHour === hour && endHour !== hour) {
5383
- setRangeData(minutes, startMinute, 60, true);
5384
- } else if (startHour === hour && endHour === hour) {
5385
- setRangeData(minutes, startMinute, endMinute + 1, true);
5386
- } else if (startHour !== hour && endHour === hour) {
5387
- setRangeData(minutes, 0, endMinute + 1, true);
5388
- } else if (startHour < hour && endHour > hour) {
5389
- setRangeData(minutes, 0, 60, true);
5390
- }
5391
- });
5392
- } else {
5393
- setRangeData(minutes, 0, 60, true);
5394
- }
5395
- return minutes;
5396
- };
5397
-
5398
- const range = function(n) {
5399
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5400
- return Array.apply(null, {length: n}).map((_, n) => n);
5401
- };
5402
-
5403
- const modifyDate = function(date, y, m, d) {
5404
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5405
- };
5406
-
5407
- const modifyTime = function(date, h, m, s) {
5408
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5409
- };
5410
-
5411
- const modifyWithTimeString = (date, time) => {
5412
- if (date == null || !time) {
5413
- return date;
5414
- }
5415
- time = parseDate(time, 'HH:mm:ss');
5416
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5417
- };
5418
-
5419
- const clearTime = function(date) {
5420
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5421
- };
5422
-
5423
- const clearMilliseconds = function(date) {
5424
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5425
- };
5426
-
5427
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
5428
- // TODO: refactory a more elegant solution
5429
- if (ranges.length === 0) return date;
5430
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
5431
- const ndate = normalizeDate(date);
5432
- const nranges = ranges.map(range => range.map(normalizeDate));
5433
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
5434
-
5435
- let minDate = nranges[0][0];
5436
- let maxDate = nranges[0][0];
5437
-
5438
- nranges.forEach(nrange => {
5439
- minDate = new Date(Math.min(nrange[0], minDate));
5440
- maxDate = new Date(Math.max(nrange[1], minDate));
5441
- });
5442
-
5443
- const ret = ndate < minDate ? minDate : maxDate;
5444
- // preserve Year/Month/Date
5445
- return modifyDate(
5446
- ret,
5447
- date.getFullYear(),
5448
- date.getMonth(),
5449
- date.getDate()
5450
- );
5451
- };
5452
-
5453
- const timeWithinRange = function(date, selectableRange, format) {
5454
- const limitedDate = limitTimeRange(date, selectableRange, format);
5455
- return limitedDate.getTime() === date.getTime();
5456
- };
5457
-
5458
- const changeYearMonthAndClampDate = function(date, year, month) {
5459
- // clamp date to the number of days in `year`, `month`
5460
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
5461
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5462
- return modifyDate(date, year, month, monthDate);
5463
- };
5464
-
5465
- const prevMonth = function(date) {
5466
- const year = date.getFullYear();
5467
- const month = date.getMonth();
5468
- return month === 0
5469
- ? changeYearMonthAndClampDate(date, year - 1, 11)
5470
- : changeYearMonthAndClampDate(date, year, month - 1);
5471
- };
5472
-
5473
- const nextMonth = function(date) {
5474
- const year = date.getFullYear();
5475
- const month = date.getMonth();
5476
- return month === 11
5477
- ? changeYearMonthAndClampDate(date, year + 1, 0)
5478
- : changeYearMonthAndClampDate(date, year, month + 1);
5479
- };
5480
-
5481
- const prevYear = function(date, amount = 1) {
5482
- const year = date.getFullYear();
5483
- const month = date.getMonth();
5484
- return changeYearMonthAndClampDate(date, year - amount, month);
5485
- };
5486
-
5487
- const nextYear = function(date, amount = 1) {
5488
- const year = date.getFullYear();
5489
- const month = date.getMonth();
5490
- return changeYearMonthAndClampDate(date, year + amount, month);
5491
- };
5492
-
5493
- const extractDateFormat = function(format) {
5494
- return format
5495
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
5496
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
5497
- .trim();
5498
- };
5499
-
5500
- const extractTimeFormat = function(format) {
5501
- return format
5502
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
5503
- .trim();
5504
- };
5505
-
5506
- const validateRangeInOneMonth = function(start, end) {
5507
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
5508
- };
5509
-
5099
+ */
5100
+ fecha.parse = function (dateStr, format) {
5101
+ if (typeof format !== 'string') {
5102
+ throw new Error('Invalid format in fecha.parse');
5103
+ }
5104
+
5105
+ format = fecha.masks[format] || format;
5106
+
5107
+ // Avoid regular expression denial of service, fail early for really long strings
5108
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5109
+ if (dateStr.length > 1000) {
5110
+ return null;
5111
+ }
5112
+
5113
+ var dateInfo = {};
5114
+ var parseInfo = [];
5115
+ var literals = [];
5116
+ format = format.replace(literal, function ($0, $1) {
5117
+ literals.push($1);
5118
+ return '@@@';
5119
+ });
5120
+ var newFormat = regexEscape(format).replace(token, function ($0) {
5121
+ if (parseFlags[$0]) {
5122
+ var info = parseFlags[$0];
5123
+ parseInfo.push(info[1]);
5124
+ return '(' + info[0] + ')';
5125
+ }
5126
+
5127
+ return $0;
5128
+ });
5129
+ newFormat = newFormat.replace(/@@@/g, function () {
5130
+ return literals.shift();
5131
+ });
5132
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
5133
+ if (!matches) {
5134
+ return null;
5135
+ }
5136
+
5137
+ for (var i = 1; i < matches.length; i++) {
5138
+ parseInfo[i - 1](dateInfo, matches[i]);
5139
+ }
5140
+
5141
+ var today = new Date();
5142
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5143
+ dateInfo.hour = +dateInfo.hour + 12;
5144
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5145
+ dateInfo.hour = 0;
5146
+ }
5147
+
5148
+ var date = void 0;
5149
+ if (dateInfo.timezoneOffset != null) {
5150
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5151
+ 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));
5152
+ } else {
5153
+ 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);
5154
+ }
5155
+ return date;
5156
+ };
5157
+
5158
+ // 导出fecha对象
5159
+
5160
+
5161
+ // 以下是从date-util.js合并的函数
5162
+ var newArray = function newArray(start, end) {
5163
+ var result = [];
5164
+ for (var i = start; i <= end; i++) {
5165
+ result.push(i);
5166
+ }
5167
+ return result;
5168
+ };
5169
+
5170
+ var getSettings = function getSettings() {
5171
+ return {
5172
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5173
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5174
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5175
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5176
+ amPm: ['上午', '下午']
5177
+ };
5178
+ };
5179
+
5180
+ var toDate = function toDate(date) {
5181
+ return isDate(date) ? new Date(date) : null;
5182
+ };
5183
+
5184
+ var isDate = function isDate(date) {
5185
+ if (date === null || date === undefined) return false;
5186
+ if (isNaN(new Date(date).getTime())) return false;
5187
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5188
+ return true;
5189
+ };
5190
+
5191
+ var isDateObject = function isDateObject(val) {
5192
+ return val instanceof Date;
5193
+ };
5194
+
5195
+ var formatDate = function formatDate(date) {
5196
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
5197
+
5198
+ // 处理多种输入类型
5199
+ if (!date) return '';
5200
+
5201
+ // 如果是时间戳,转成日期对象
5202
+ if (typeof date === 'number') {
5203
+ date = new Date(date);
5204
+ }
5205
+ // 如果是字符串,转成日期对象
5206
+ if (typeof date === 'string') {
5207
+ date = new Date(date);
5208
+ }
5209
+
5210
+ // 调用toDate进一步验证和转换
5211
+ date = toDate(date);
5212
+ if (!date) return '';
5213
+
5214
+ // 兼容大写和小写的格式标记
5215
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5216
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
5217
+
5218
+ // 使用fecha库进行格式化,支持中文配置
5219
+ var str = fecha.format(date, lowercaseFormat, getSettings());
5220
+ return str;
5221
+ };
5222
+
5223
+ var parseDate = function parseDate(string, format) {
5224
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5225
+ };
5226
+
5227
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
5228
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
5229
+ return 30;
5230
+ }
5231
+
5232
+ if (month === 1) {
5233
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5234
+ return 29;
5235
+ } else {
5236
+ return 28;
5237
+ }
5238
+ }
5239
+
5240
+ return 31;
5241
+ };
5242
+
5243
+ var getDayCountOfYear = function getDayCountOfYear(year) {
5244
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
5245
+ return isLeapYear ? 366 : 365;
5246
+ };
5247
+
5248
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
5249
+ var temp = new Date(date.getTime());
5250
+ temp.setDate(1);
5251
+ return temp.getDay();
5252
+ };
5253
+
5254
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5255
+ // {prev, next} Date should work for Daylight Saving Time
5256
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5257
+ var prevDate = function prevDate(date) {
5258
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5259
+
5260
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5261
+ };
5262
+
5263
+ var nextDate = function nextDate(date) {
5264
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5265
+
5266
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5267
+ };
5268
+
5269
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
5270
+ var result = new Date(year, month, 1);
5271
+ var day = result.getDay();
5272
+
5273
+ if (day === 0) {
5274
+ return prevDate(result, 7);
5275
+ } else {
5276
+ return prevDate(result, day);
5277
+ }
5278
+ };
5279
+
5280
+ var getWeekNumber = function getWeekNumber(date) {
5281
+ // 支持多种输入类型
5282
+ if (!date || !isDate(date)) {
5283
+ date = new Date();
5284
+ }
5285
+ if (typeof date === 'string') {
5286
+ date = new Date(date);
5287
+ }
5288
+
5289
+ // 验证日期有效性
5290
+ if (!isDate(date)) return null;
5291
+
5292
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5293
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5294
+ // 将星期日的星期数设为7
5295
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5296
+ // 获取当年的第一天
5297
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5298
+ // 计算到最近的星期四的完整周数
5299
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
5300
+ // 返回周数
5301
+ return weekNo;
5302
+ };
5303
+
5304
+ var getRangeHours = function getRangeHours(ranges) {
5305
+ var hours = [];
5306
+ var disabledHours = [];
5307
+
5308
+ (ranges || []).forEach(function (range) {
5309
+ var value = range.map(function (date) {
5310
+ return date.getHours();
5311
+ });
5312
+
5313
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5314
+ });
5315
+
5316
+ if (disabledHours.length) {
5317
+ for (var i = 0; i < 24; i++) {
5318
+ hours[i] = disabledHours.indexOf(i) === -1;
5319
+ }
5320
+ } else {
5321
+ for (var _i = 0; _i < 24; _i++) {
5322
+ hours[_i] = false;
5323
+ }
5324
+ }
5325
+
5326
+ return hours;
5327
+ };
5328
+
5329
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
5330
+ if (amount <= 0) return [];
5331
+ var temp = new Date(date.getTime());
5332
+ temp.setDate(0);
5333
+ var lastDay = temp.getDate();
5334
+ return range(amount).map(function (_, index) {
5335
+ return lastDay - (amount - index - 1);
5336
+ });
5337
+ };
5338
+
5339
+ var getMonthDays = function getMonthDays(date) {
5340
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5341
+ var days = temp.getDate();
5342
+ return range(days).map(function (_, index) {
5343
+ return index + 1;
5344
+ });
5345
+ };
5346
+
5347
+ function setRangeData(arr, start, end, value) {
5348
+ for (var i = start; i < end; i++) {
5349
+ arr[i] = value;
5350
+ }
5351
+ }
5352
+
5353
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
5354
+ var minutes = new Array(60);
5355
+
5356
+ if (ranges.length > 0) {
5357
+ ranges.forEach(function (range) {
5358
+ var start = range[0];
5359
+ var end = range[1];
5360
+ var startHour = start.getHours();
5361
+ var startMinute = start.getMinutes();
5362
+ var endHour = end.getHours();
5363
+ var endMinute = end.getMinutes();
5364
+ if (startHour === hour && endHour !== hour) {
5365
+ setRangeData(minutes, startMinute, 60, true);
5366
+ } else if (startHour === hour && endHour === hour) {
5367
+ setRangeData(minutes, startMinute, endMinute + 1, true);
5368
+ } else if (startHour !== hour && endHour === hour) {
5369
+ setRangeData(minutes, 0, endMinute + 1, true);
5370
+ } else if (startHour < hour && endHour > hour) {
5371
+ setRangeData(minutes, 0, 60, true);
5372
+ }
5373
+ });
5374
+ } else {
5375
+ setRangeData(minutes, 0, 60, true);
5376
+ }
5377
+ return minutes;
5378
+ };
5379
+
5380
+ var range = function range(n) {
5381
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5382
+ return Array.apply(null, { length: n }).map(function (_, n) {
5383
+ return n;
5384
+ });
5385
+ };
5386
+
5387
+ var modifyDate = function modifyDate(date, y, m, d) {
5388
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5389
+ };
5390
+
5391
+ var modifyTime = function modifyTime(date, h, m, s) {
5392
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5393
+ };
5394
+
5395
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
5396
+ if (date == null || !time) {
5397
+ return date;
5398
+ }
5399
+ time = parseDate(time, 'HH:mm:ss');
5400
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5401
+ };
5402
+
5403
+ var clearTime = function clearTime(date) {
5404
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5405
+ };
5406
+
5407
+ var clearMilliseconds = function clearMilliseconds(date) {
5408
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5409
+ };
5410
+
5411
+ var limitTimeRange = function limitTimeRange(date, ranges) {
5412
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
5413
+
5414
+ // TODO: refactory a more elegant solution
5415
+ if (ranges.length === 0) return date;
5416
+ var normalizeDate = function normalizeDate(date) {
5417
+ return fecha.parse(fecha.format(date, format), format);
5418
+ };
5419
+ var ndate = normalizeDate(date);
5420
+ var nranges = ranges.map(function (range) {
5421
+ return range.map(normalizeDate);
5422
+ });
5423
+ if (nranges.some(function (nrange) {
5424
+ return ndate >= nrange[0] && ndate <= nrange[1];
5425
+ })) return date;
5426
+
5427
+ var minDate = nranges[0][0];
5428
+ var maxDate = nranges[0][0];
5429
+
5430
+ nranges.forEach(function (nrange) {
5431
+ minDate = new Date(Math.min(nrange[0], minDate));
5432
+ maxDate = new Date(Math.max(nrange[1], minDate));
5433
+ });
5434
+
5435
+ var ret = ndate < minDate ? minDate : maxDate;
5436
+ // preserve Year/Month/Date
5437
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
5438
+ };
5439
+
5440
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
5441
+ var limitedDate = limitTimeRange(date, selectableRange, format);
5442
+ return limitedDate.getTime() === date.getTime();
5443
+ };
5444
+
5445
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
5446
+ // clamp date to the number of days in `year`, `month`
5447
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
5448
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5449
+ return modifyDate(date, year, month, monthDate);
5450
+ };
5451
+
5452
+ var prevMonth = function prevMonth(date) {
5453
+ var year = date.getFullYear();
5454
+ var month = date.getMonth();
5455
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
5456
+ };
5457
+
5458
+ var nextMonth = function nextMonth(date) {
5459
+ var year = date.getFullYear();
5460
+ var month = date.getMonth();
5461
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
5462
+ };
5463
+
5464
+ var prevYear = function prevYear(date) {
5465
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5466
+
5467
+ var year = date.getFullYear();
5468
+ var month = date.getMonth();
5469
+ return changeYearMonthAndClampDate(date, year - amount, month);
5470
+ };
5471
+
5472
+ var nextYear = function nextYear(date) {
5473
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5474
+
5475
+ var year = date.getFullYear();
5476
+ var month = date.getMonth();
5477
+ return changeYearMonthAndClampDate(date, year + amount, month);
5478
+ };
5479
+
5480
+ var extractDateFormat = function extractDateFormat(format) {
5481
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
5482
+ };
5483
+
5484
+ var extractTimeFormat = function extractTimeFormat(format) {
5485
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
5486
+ };
5487
+
5488
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
5489
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
5490
+ };
5491
+
5510
5492
  /**
5511
5493
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
5512
5494
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
5513
5495
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
5514
5496
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
5515
5497
  * @returns {number} 工作日数量
5516
- */
5517
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
5518
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5519
- throw new Error(
5520
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
5521
- );
5522
- }
5523
-
5524
- const startDateObj = new Date(start_date);
5525
- const endDateObj = new Date(end_date);
5526
-
5527
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5528
- throw new Error(
5529
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
5530
- );
5531
- }
5532
-
5533
- if (startDateObj > endDateObj) {
5534
- throw new Error('Start date should be earlier than or equal to end date.');
5535
- }
5536
-
5537
- let workdays = 0;
5538
-
5539
- // Iterate through each day in the date range
5540
- for (
5541
- let currentDate = new Date(startDateObj);
5542
- currentDate <= endDateObj;
5543
- currentDate.setDate(currentDate.getDate() + 1)
5544
- ) {
5545
- // Check if the current day is a weekend (Saturday or Sunday)
5546
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5547
-
5548
- // Check if the current day is a holiday
5549
- const isHoliday = holidays.some((holiday) => {
5550
- const holidayDate = new Date(holiday);
5551
- return currentDate.toDateString() === holidayDate.toDateString();
5552
- });
5553
-
5554
- // If it's a workday (not a weekend or holiday), increment the workdays count
5555
- if (!isWeekend && !isHoliday) {
5556
- workdays++;
5557
- }
5558
- }
5559
-
5560
- return workdays;
5561
- };
5562
-
5498
+ */
5499
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
5500
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5501
+
5502
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5503
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5504
+ }
5505
+
5506
+ var startDateObj = new Date(start_date);
5507
+ var endDateObj = new Date(end_date);
5508
+
5509
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5510
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5511
+ }
5512
+
5513
+ if (startDateObj > endDateObj) {
5514
+ throw new Error('Start date should be earlier than or equal to end date.');
5515
+ }
5516
+
5517
+ var workdays = 0;
5518
+
5519
+ // Iterate through each day in the date range
5520
+
5521
+ var _loop = function _loop(currentDate) {
5522
+ // Check if the current day is a weekend (Saturday or Sunday)
5523
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5524
+
5525
+ // Check if the current day is a holiday
5526
+ var isHoliday = holidays.some(function (holiday) {
5527
+ var holidayDate = new Date(holiday);
5528
+ return currentDate.toDateString() === holidayDate.toDateString();
5529
+ });
5530
+
5531
+ // If it's a workday (not a weekend or holiday), increment the workdays count
5532
+ if (!isWeekend && !isHoliday) {
5533
+ workdays++;
5534
+ }
5535
+ };
5536
+
5537
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
5538
+ _loop(currentDate);
5539
+ }
5540
+
5541
+ return workdays;
5542
+ };
5543
+
5563
5544
  /**
5564
5545
  * 日期加减天数
5565
5546
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
5566
5547
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
5567
5548
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
5568
- */
5569
- const dateAddDays = function (start_date, days) {
5570
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5571
- throw new Error(
5572
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
5573
- );
5574
- }
5575
-
5576
- const startDateObj = new Date(start_date);
5577
- if (isNaN(startDateObj.getTime())) {
5578
- throw new Error(
5579
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5580
- );
5581
- }
5582
-
5583
- const resultDateObj = new Date(startDateObj);
5584
- resultDateObj.setDate(resultDateObj.getDate() + days);
5585
-
5586
- const resultYear = resultDateObj.getFullYear();
5587
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5588
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5589
-
5590
- return `${resultYear}-${resultMonth}-${resultDay}`;
5591
- };
5592
-
5549
+ */
5550
+ var dateAddDays = function dateAddDays(start_date, days) {
5551
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5552
+ 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.");
5553
+ }
5554
+
5555
+ var startDateObj = new Date(start_date);
5556
+ if (isNaN(startDateObj.getTime())) {
5557
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5558
+ }
5559
+
5560
+ var resultDateObj = new Date(startDateObj);
5561
+ resultDateObj.setDate(resultDateObj.getDate() + days);
5562
+
5563
+ var resultYear = resultDateObj.getFullYear();
5564
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5565
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5566
+
5567
+ return resultYear + '-' + resultMonth + '-' + resultDay;
5568
+ };
5569
+
5593
5570
  /**
5594
5571
  * 计算两个日期之间的差值
5595
5572
  * @date 2023年12月14日
@@ -5597,182 +5574,180 @@ const dateAddDays = function (start_date, days) {
5597
5574
  * @param {String} end_date - 结束日期字符串
5598
5575
  * @param {String} unit - 单位:year/month/day
5599
5576
  * @returns {Number} 差值
5600
- */
5601
- const dateDiff = function (start_date, end_date, unit = 'day') {
5602
- // Assuming date strings are in "YYYY-MM-DD" format
5603
- var startDate = new Date(start_date);
5604
- var endDate = new Date(end_date);
5605
-
5606
- // If the date is invalid, return 0
5607
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5608
- return 0;
5609
- }
5610
-
5611
- if (unit === 'year') {
5612
- return endDate.getFullYear() - startDate.getFullYear();
5613
- } else if (unit === 'month') {
5614
- return (
5615
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
5616
- (endDate.getMonth() - startDate.getMonth())
5617
- );
5618
- } else {
5619
- // Default to day
5620
- var timeDifference = endDate - startDate;
5621
- // Calculate days (86400000 milliseconds per day)
5622
- return Math.floor(timeDifference / 86400000);
5623
- }
5624
- };
5625
-
5577
+ */
5578
+ var dateDiff = function dateDiff(start_date, end_date) {
5579
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
5580
+
5581
+ // Assuming date strings are in "YYYY-MM-DD" format
5582
+ var startDate = new Date(start_date);
5583
+ var endDate = new Date(end_date);
5584
+
5585
+ // If the date is invalid, return 0
5586
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5587
+ return 0;
5588
+ }
5589
+
5590
+ if (unit === 'year') {
5591
+ return endDate.getFullYear() - startDate.getFullYear();
5592
+ } else if (unit === 'month') {
5593
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
5594
+ } else {
5595
+ // Default to day
5596
+ var timeDifference = endDate - startDate;
5597
+ // Calculate days (86400000 milliseconds per day)
5598
+ return Math.floor(timeDifference / 86400000);
5599
+ }
5600
+ };
5601
+
5626
5602
  /**
5627
5603
  * 获取月份中的日期
5628
5604
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
5629
5605
  * @returns {number} 月份中的日期(1-31)
5630
- */
5631
- const dayOfMonth = function (date) {
5632
- if (typeof date !== 'string') {
5633
- throw new Error(
5634
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
5635
- );
5636
- }
5637
-
5638
- const dateObj = new Date(date);
5639
- if (isNaN(dateObj.getTime())) {
5640
- throw new Error(
5641
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5642
- );
5643
- }
5644
-
5645
- return dateObj.getDate();
5646
- };
5647
-
5606
+ */
5607
+ var dayOfMonth = function dayOfMonth(date) {
5608
+ if (typeof date !== 'string') {
5609
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5610
+ }
5611
+
5612
+ var dateObj = new Date(date);
5613
+ if (isNaN(dateObj.getTime())) {
5614
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5615
+ }
5616
+
5617
+ return dateObj.getDate();
5618
+ };
5619
+
5648
5620
  /**
5649
5621
  * 获取当前日期
5650
5622
  * @date 2022年5月7日
5651
5623
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
5652
5624
  * @returns {string} 当前日期的格式化字符串
5653
- */
5654
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
5655
- return formatDate(new Date(), format);
5656
- };
5657
-
5625
+ */
5626
+ var getCurrentDate = function getCurrentDate() {
5627
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
5628
+
5629
+ return formatDate(new Date(), format);
5630
+ };
5631
+
5658
5632
  /**
5659
5633
  * 获取当前日期时间
5660
5634
  * @date 2022年5月7日
5661
5635
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
5662
5636
  * @returns {string} 当前日期时间的格式化字符串
5663
- */
5664
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
5665
- return formatDate(new Date(), format);
5666
- };
5667
-
5637
+ */
5638
+ var getCurrentDateTime = function getCurrentDateTime() {
5639
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
5640
+
5641
+ return formatDate(new Date(), format);
5642
+ };
5643
+
5668
5644
  /**
5669
5645
  * 获取小时
5670
5646
  * @date 2022年5月7日
5671
5647
  * @param {Date|string} [date] - 日期对象或日期字符串
5672
5648
  * @returns {number} 小时数(0-23)
5673
- */
5674
- const getHour = function (date) {
5675
- if (!date) {
5676
- return new Date().getHours();
5677
- }
5678
- if (typeof date === 'string') {
5679
- date = new Date(date);
5680
- }
5681
- return date.getHours();
5682
- };
5683
-
5649
+ */
5650
+ var getHour = function getHour(date) {
5651
+ if (!date) {
5652
+ return new Date().getHours();
5653
+ }
5654
+ if (typeof date === 'string') {
5655
+ date = new Date(date);
5656
+ }
5657
+ return date.getHours();
5658
+ };
5659
+
5684
5660
  /**
5685
5661
  * 获取分钟
5686
5662
  * @date 2022年5月7日
5687
5663
  * @param {Date|string} [date] - 日期对象或日期字符串
5688
5664
  * @returns {number} 分钟数(0-59)
5689
- */
5690
- const getMinute = function (date) {
5691
- if (!date) {
5692
- return new Date().getMinutes();
5693
- }
5694
- if (typeof date === 'string') {
5695
- date = new Date(date);
5696
- }
5697
- return date.getMinutes();
5698
- };
5699
-
5665
+ */
5666
+ var getMinute = function getMinute(date) {
5667
+ if (!date) {
5668
+ return new Date().getMinutes();
5669
+ }
5670
+ if (typeof date === 'string') {
5671
+ date = new Date(date);
5672
+ }
5673
+ return date.getMinutes();
5674
+ };
5675
+
5700
5676
  /**
5701
5677
  * 获取月份
5702
5678
  * @date 2022年5月7日
5703
5679
  * @param {Date|string} [date] - 日期对象或日期字符串
5704
5680
  * @returns {number} 月份数(1-12)
5705
- */
5706
- const getMonth = function (date) {
5707
- if (!date) {
5708
- return new Date().getMonth() + 1;
5709
- }
5710
- if (typeof date === 'string') {
5711
- date = new Date(date);
5712
- }
5713
- return date.getMonth() + 1;
5714
- };
5715
-
5681
+ */
5682
+ var getMonth = function getMonth(date) {
5683
+ if (!date) {
5684
+ return new Date().getMonth() + 1;
5685
+ }
5686
+ if (typeof date === 'string') {
5687
+ date = new Date(date);
5688
+ }
5689
+ return date.getMonth() + 1;
5690
+ };
5691
+
5716
5692
  /**
5717
5693
  * 获取秒
5718
5694
  * @date 2022年5月7日
5719
5695
  * @param {Date|string} [date] - 日期对象或日期字符串
5720
5696
  * @returns {number} 秒数(0-59)
5721
- */
5722
- const getSecond = function (date) {
5723
- if (!date) {
5724
- return new Date().getSeconds();
5725
- }
5726
- if (typeof date === 'string') {
5727
- date = new Date(date);
5728
- }
5729
- return date.getSeconds();
5730
- };
5731
-
5697
+ */
5698
+ var getSecond = function getSecond(date) {
5699
+ if (!date) {
5700
+ return new Date().getSeconds();
5701
+ }
5702
+ if (typeof date === 'string') {
5703
+ date = new Date(date);
5704
+ }
5705
+ return date.getSeconds();
5706
+ };
5707
+
5732
5708
  /**
5733
5709
  * 获取星期几
5734
5710
  * @date 2022年5月7日
5735
5711
  * @param {Date|string} [date] - 日期对象或日期字符串
5736
5712
  * @returns {number} 星期几(0-6,0表示星期日)
5737
- */
5738
- const getWeekday = function (date) {
5739
- if (!date) {
5740
- return new Date().getDay();
5741
- }
5742
- if (typeof date === 'string') {
5743
- date = new Date(date);
5744
- }
5745
- return date.getDay();
5746
- };
5747
-
5748
-
5713
+ */
5714
+ var getWeekday = function getWeekday(date) {
5715
+ if (!date) {
5716
+ return new Date().getDay();
5717
+ }
5718
+ if (typeof date === 'string') {
5719
+ date = new Date(date);
5720
+ }
5721
+ return date.getDay();
5722
+ };
5723
+
5749
5724
  /**
5750
5725
  * @desc 获取上午/下午/晚上
5751
5726
  * @author huangbo
5752
5727
  * @date 2022年5月7日
5753
5728
  * @param {String} [time] - 时间
5754
- **/
5755
- const timeCycle = function (time) {
5756
- let hour = 0;
5757
- if (!time) {
5758
- hour = new Date().getHours();
5759
- } else if (typeof time === 'string') {
5760
- // 从时间字符串中提取小时
5761
- const match = time.match(/^(\d{1,2})/);
5762
- if (match) {
5763
- hour = parseInt(match[1], 10);
5764
- }
5765
- } else if (typeof time === 'number') {
5766
- hour = time;
5767
- }
5768
- // 判断时间段
5769
- if (hour >= 5 && hour < 12) {
5770
- return '上午';
5771
- } else if (hour >= 12 && hour < 18) {
5772
- return '下午';
5773
- } else {
5774
- return '晚上';
5775
- }
5729
+ **/
5730
+ var timeCycle = function timeCycle(time) {
5731
+ var hour = 0;
5732
+ if (!time) {
5733
+ hour = new Date().getHours();
5734
+ } else if (typeof time === 'string') {
5735
+ // 从时间字符串中提取小时
5736
+ var match = time.match(/^(\d{1,2})/);
5737
+ if (match) {
5738
+ hour = parseInt(match[1], 10);
5739
+ }
5740
+ } else if (typeof time === 'number') {
5741
+ hour = time;
5742
+ }
5743
+ // 判断时间段
5744
+ if (hour >= 5 && hour < 12) {
5745
+ return '上午';
5746
+ } else if (hour >= 12 && hour < 18) {
5747
+ return '下午';
5748
+ } else {
5749
+ return '晚上';
5750
+ }
5776
5751
  };
5777
5752
 
5778
5753
  /***/ }),