eoss 0.1.0-alpha.35 → 0.1.0-alpha.37

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 (228) 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 +1101 -1035
  83. package/lib/alert.js +2 -2
  84. package/lib/aside.js +2 -2
  85. package/lib/audit-trajectory.js +150 -150
  86. package/lib/autocomplete.js +2095 -1871
  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 +862 -837
  95. package/lib/calendar.js +864 -839
  96. package/lib/card.js +2 -2
  97. package/lib/carousel-item.js +864 -839
  98. package/lib/carousel.js +866 -841
  99. package/lib/cascader-panel.js +878 -853
  100. package/lib/cascader.js +2325 -2101
  101. package/lib/checkbox-button.js +4 -4
  102. package/lib/checkbox-group.js +1060 -1025
  103. package/lib/checkbox.js +6 -6
  104. package/lib/col.js +2 -2
  105. package/lib/collapse-item.js +920 -895
  106. package/lib/collapse.js +913 -888
  107. package/lib/color-picker.js +1155 -956
  108. package/lib/container.js +2 -2
  109. package/lib/cron.js +18 -18
  110. package/lib/data-table.js +1053 -1018
  111. package/lib/date-picker.js +2094 -1870
  112. package/lib/descriptions-item.js +144 -0
  113. package/lib/descriptions.js +561 -0
  114. package/lib/dialog.js +943 -918
  115. package/lib/divider.js +2 -2
  116. package/lib/drawer.js +12 -12
  117. package/lib/dropdown-item.js +6 -6
  118. package/lib/dropdown-menu.js +1157 -958
  119. package/lib/dropdown.js +870 -845
  120. package/lib/email-login.js +1047 -1012
  121. package/lib/empty.js +2 -2
  122. package/lib/eoss.common.js +3493 -2313
  123. package/lib/flip.js +2 -2
  124. package/lib/flow-group.js +876 -851
  125. package/lib/flow.js +1184 -1149
  126. package/lib/flows.js +1080 -1045
  127. package/lib/footer.js +2 -2
  128. package/lib/form-item.js +877 -852
  129. package/lib/form.js +1123 -1087
  130. package/lib/guide.js +2 -2
  131. package/lib/header.js +2 -2
  132. package/lib/icon.js +1009 -984
  133. package/lib/icons.js +6 -6
  134. package/lib/image-viewer.js +862 -837
  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 +870 -845
  140. package/lib/link.js +2 -2
  141. package/lib/loading.js +13 -13
  142. package/lib/login.js +1116 -1066
  143. package/lib/lowcode-view.js +1078 -1043
  144. package/lib/lowcode.js +1131 -1096
  145. package/lib/main.js +1185 -1148
  146. package/lib/marquee.js +862 -837
  147. package/lib/menu-item-group.js +20 -17
  148. package/lib/menu-item.js +8 -8
  149. package/lib/menu.js +2390 -2164
  150. package/lib/message-box.js +950 -925
  151. package/lib/message.js +941 -916
  152. package/lib/notification.js +962 -937
  153. package/lib/option-group.js +4 -4
  154. package/lib/option.js +871 -846
  155. package/lib/page-header.js +2 -2
  156. package/lib/pagination.js +866 -841
  157. package/lib/phone-login.js +1049 -1014
  158. package/lib/popconfirm.js +4 -4
  159. package/lib/popover.js +2100 -1876
  160. package/lib/process-config.js +1065 -1030
  161. package/lib/process-module.js +1053 -1018
  162. package/lib/process-rule.js +1062 -1027
  163. package/lib/progress.js +2 -2
  164. package/lib/qr-code.js +4 -4
  165. package/lib/qrcode-login.js +1052 -1017
  166. package/lib/radio-button.js +4 -4
  167. package/lib/radio-group.js +2608 -2573
  168. package/lib/radio.js +6 -6
  169. package/lib/rate.js +864 -839
  170. package/lib/retrial-auth.js +7063 -0
  171. package/lib/row.js +2 -2
  172. package/lib/scrollbar.js +868 -843
  173. package/lib/select.js +2591 -2357
  174. package/lib/selector-panel.js +2659 -2624
  175. package/lib/selector.js +1068 -1033
  176. package/lib/slider.js +6 -6
  177. package/lib/step.js +44 -44
  178. package/lib/steps.js +911 -886
  179. package/lib/submenu.js +1439 -1236
  180. package/lib/switch.js +866 -841
  181. package/lib/tab-pane.js +4 -4
  182. package/lib/table-column.js +936 -911
  183. package/lib/table.js +2318 -2084
  184. package/lib/tabs.js +866 -841
  185. package/lib/tag.js +2 -2
  186. package/lib/theme-chalk/base.css +1 -1
  187. package/lib/theme-chalk/descriptions.css +1 -1
  188. package/lib/theme-chalk/index.css +1 -1
  189. package/lib/theme-chalk/main.css +1 -1
  190. package/lib/theme-chalk/retrial-auth.css +1 -0
  191. package/lib/time-picker.js +2047 -1823
  192. package/lib/time-select.js +2041 -1817
  193. package/lib/timeline-item.js +2 -2
  194. package/lib/timeline.js +2 -2
  195. package/lib/tips.js +1047 -1012
  196. package/lib/toolbar.js +36 -17
  197. package/lib/tooltip.js +2080 -1856
  198. package/lib/transfer.js +881 -856
  199. package/lib/tree-group.js +1020 -995
  200. package/lib/tree.js +1062 -1027
  201. package/lib/update-history.js +151 -151
  202. package/lib/upload.js +1082 -1047
  203. package/lib/utils/ajax.js +5 -1
  204. package/lib/utils/popper.js +97 -48
  205. package/lib/wujie.js +866 -841
  206. package/package.json +1 -1
  207. package/packages/account-login/src/account-login.vue +29 -0
  208. package/packages/descriptions/index.js +8 -0
  209. package/packages/descriptions/src/index.js +181 -0
  210. package/packages/descriptions/src/item.js +30 -0
  211. package/packages/descriptions/src/row.js +120 -0
  212. package/packages/descriptions-item/index.js +8 -0
  213. package/packages/login/src/login.vue +8 -0
  214. package/packages/login/src/mixins.js +3 -1
  215. package/packages/main/src/minxs.js +1 -0
  216. package/packages/menu/src/menu.vue +0 -1
  217. package/packages/menu/src/mixins.js +4 -3
  218. package/packages/menu/src/submenu.vue +4 -4
  219. package/packages/retrial-auth/index.js +5 -0
  220. package/packages/retrial-auth/src/main.vue +300 -0
  221. package/packages/theme-chalk/src/base.scss +2 -1
  222. package/packages/theme-chalk/src/descriptions.scss +0 -1
  223. package/packages/theme-chalk/src/index.scss +3 -0
  224. package/packages/theme-chalk/src/retrial-auth.scss +38 -0
  225. package/packages/toolbar/src/toolbar.vue +5 -0
  226. package/src/index.js +336 -327
  227. package/src/utils/ajax.js +2 -1
  228. package/src/utils/popper.js +109 -70
package/lib/flow-group.js CHANGED
@@ -82,7 +82,7 @@ module.exports =
82
82
  /******/
83
83
  /******/
84
84
  /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 237);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 240);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3486,14 +3486,14 @@ var getRgb = function getRgb($color) {
3486
3486
 
3487
3487
  /***/ }),
3488
3488
 
3489
- /***/ 133:
3489
+ /***/ 135:
3490
3490
  /***/ (function(module, exports) {
3491
3491
 
3492
3492
  module.exports = require("eoss/lib/flow");
3493
3493
 
3494
3494
  /***/ }),
3495
3495
 
3496
- /***/ 134:
3496
+ /***/ 136:
3497
3497
  /***/ (function(module, exports) {
3498
3498
 
3499
3499
  module.exports = require("eoss/lib/tree-group");
@@ -3535,7 +3535,7 @@ module.exports = require("vue");
3535
3535
 
3536
3536
  /***/ }),
3537
3537
 
3538
- /***/ 237:
3538
+ /***/ 240:
3539
3539
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3540
3540
 
3541
3541
  "use strict";
@@ -4865,15 +4865,15 @@ render._withStripped = true
4865
4865
  var util = __webpack_require__(1);
4866
4866
 
4867
4867
  // EXTERNAL MODULE: external "eoss/lib/data-table"
4868
- var data_table_ = __webpack_require__(46);
4868
+ var data_table_ = __webpack_require__(47);
4869
4869
  var data_table_default = /*#__PURE__*/__webpack_require__.n(data_table_);
4870
4870
 
4871
4871
  // EXTERNAL MODULE: external "eoss/lib/dialog"
4872
- var dialog_ = __webpack_require__(36);
4872
+ var dialog_ = __webpack_require__(37);
4873
4873
  var dialog_default = /*#__PURE__*/__webpack_require__.n(dialog_);
4874
4874
 
4875
4875
  // EXTERNAL MODULE: external "eoss/lib/flow"
4876
- var flow_ = __webpack_require__(133);
4876
+ var flow_ = __webpack_require__(135);
4877
4877
  var flow_default = /*#__PURE__*/__webpack_require__.n(flow_);
4878
4878
 
4879
4879
  // EXTERNAL MODULE: external "eoss/lib/form"
@@ -4881,19 +4881,19 @@ var form_ = __webpack_require__(25);
4881
4881
  var form_default = /*#__PURE__*/__webpack_require__.n(form_);
4882
4882
 
4883
4883
  // EXTERNAL MODULE: external "eoss/lib/tab-pane"
4884
- var tab_pane_ = __webpack_require__(58);
4884
+ var tab_pane_ = __webpack_require__(59);
4885
4885
  var tab_pane_default = /*#__PURE__*/__webpack_require__.n(tab_pane_);
4886
4886
 
4887
4887
  // EXTERNAL MODULE: external "eoss/lib/tabs"
4888
- var tabs_ = __webpack_require__(54);
4888
+ var tabs_ = __webpack_require__(55);
4889
4889
  var tabs_default = /*#__PURE__*/__webpack_require__.n(tabs_);
4890
4890
 
4891
4891
  // EXTERNAL MODULE: external "eoss/lib/tree-group"
4892
- var tree_group_ = __webpack_require__(134);
4892
+ var tree_group_ = __webpack_require__(136);
4893
4893
  var tree_group_default = /*#__PURE__*/__webpack_require__.n(tree_group_);
4894
4894
 
4895
4895
  // EXTERNAL MODULE: external "eoss/lib/upload"
4896
- var upload_ = __webpack_require__(48);
4896
+ var upload_ = __webpack_require__(49);
4897
4897
  var upload_default = /*#__PURE__*/__webpack_require__.n(upload_);
4898
4898
 
4899
4899
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/flow-group/src/main.vue?vue&type=script&lang=js&
@@ -5761,7 +5761,7 @@ function isDefined(val) {
5761
5761
 
5762
5762
  /***/ }),
5763
5763
 
5764
- /***/ 36:
5764
+ /***/ 37:
5765
5765
  /***/ (function(module, exports) {
5766
5766
 
5767
5767
  module.exports = require("eoss/lib/dialog");
@@ -5873,28 +5873,28 @@ function normalizeComponent(
5873
5873
 
5874
5874
  /***/ }),
5875
5875
 
5876
- /***/ 46:
5876
+ /***/ 47:
5877
5877
  /***/ (function(module, exports) {
5878
5878
 
5879
5879
  module.exports = require("eoss/lib/data-table");
5880
5880
 
5881
5881
  /***/ }),
5882
5882
 
5883
- /***/ 48:
5883
+ /***/ 49:
5884
5884
  /***/ (function(module, exports) {
5885
5885
 
5886
5886
  module.exports = require("eoss/lib/upload");
5887
5887
 
5888
5888
  /***/ }),
5889
5889
 
5890
- /***/ 54:
5890
+ /***/ 55:
5891
5891
  /***/ (function(module, exports) {
5892
5892
 
5893
5893
  module.exports = require("eoss/lib/tabs");
5894
5894
 
5895
5895
  /***/ }),
5896
5896
 
5897
- /***/ 58:
5897
+ /***/ 59:
5898
5898
  /***/ (function(module, exports) {
5899
5899
 
5900
5900
  module.exports = require("eoss/lib/tab-pane");
@@ -5951,736 +5951,759 @@ module.exports = require("eoss/lib/tab-pane");
5951
5951
  /* unused harmony export getSecond */
5952
5952
  /* unused harmony export getWeekday */
5953
5953
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
5954
-
5955
-
5954
+ /* Modified from https://github.com/taylorhakes/fecha
5955
+ *
5956
+ * The MIT License (MIT)
5957
+ *
5958
+ * Copyright (c) 2015 Taylor Hakes
5959
+ *
5960
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5961
+ * of this software and associated documentation files (the "Software"), to deal
5962
+ * in the Software without restriction, including without limitation the rights
5963
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5964
+ * copies of the Software, and to permit persons to whom the Software is
5965
+ * furnished to do so, subject to the following conditions:
5966
+ *
5967
+ * The above copyright notice and this permission notice shall be included in all
5968
+ * copies or substantial portions of the Software.
5969
+ *
5970
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5971
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5972
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5973
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5974
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5975
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5976
+ * SOFTWARE.
5977
+ */
5978
+
5979
+ /*eslint-disable*/
5980
+ // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
5981
+
5982
+
5956
5983
  /**
5957
5984
  * Parse or format dates
5958
5985
  * @class fecha
5959
- */
5960
- var fecha = {};
5961
- var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5962
- var twoDigits = '\\d\\d?';
5963
- var threeDigits = '\\d{3}';
5964
- var fourDigits = '\\d{4}';
5965
- var word = '[^\\s]+';
5966
- var literal = /\[([^]*?)\]/gm;
5967
- var noop = function noop() {};
5968
-
5969
- function regexEscape(str) {
5970
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5971
- }
5972
-
5973
- function shorten(arr, sLen) {
5974
- var newArr = [];
5975
- for (var i = 0, len = arr.length; i < len; i++) {
5976
- newArr.push(arr[i].substr(0, sLen));
5977
- }
5978
- return newArr;
5979
- }
5980
-
5981
- function monthUpdate() {
5982
- return function (d, v) {
5983
- var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5984
- if (~index) {
5985
- d.month = index;
5986
- }
5987
- };
5988
- }
5989
-
5990
- function pad(val, len) {
5991
- val = String(val);
5992
- len = len || 2;
5993
- while (val.length < len) {
5994
- val = '0' + val;
5995
- }
5996
- return val;
5997
- }
5998
-
5999
- // 直接使用中文日期名称常量
6000
- var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
6001
- var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
6002
- var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
6003
- var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
6004
- var amPm = ['上午', '下午'];
6005
- var DoFn = function DoFn(D) {
6006
- return D + '日';
6007
- };
6008
-
6009
- var formatFlags = {
6010
- D: function D(dateObj) {
6011
- return dateObj.getDay();
6012
- },
6013
- DD: function DD(dateObj) {
6014
- return pad(dateObj.getDay());
6015
- },
6016
- Do: function Do(dateObj) {
6017
- return DoFn(dateObj.getDate());
6018
- },
6019
- d: function d(dateObj) {
6020
- return dateObj.getDate();
6021
- },
6022
- dd: function dd(dateObj) {
6023
- return pad(dateObj.getDate());
6024
- },
6025
- ddd: function ddd(dateObj) {
6026
- return dayNamesShort[dateObj.getDay()];
6027
- },
6028
- dddd: function dddd(dateObj) {
6029
- return dayNames[dateObj.getDay()];
6030
- },
6031
- M: function M(dateObj) {
6032
- return dateObj.getMonth() + 1;
6033
- },
6034
- MM: function MM(dateObj) {
6035
- return pad(dateObj.getMonth() + 1);
6036
- },
6037
- MMM: function MMM(dateObj) {
6038
- return monthNamesShort[dateObj.getMonth()];
6039
- },
6040
- MMMM: function MMMM(dateObj) {
6041
- return monthNames[dateObj.getMonth()];
6042
- },
6043
- yy: function yy(dateObj) {
6044
- return pad(String(dateObj.getFullYear()), 4).substr(2);
6045
- },
6046
- yyyy: function yyyy(dateObj) {
6047
- return pad(dateObj.getFullYear(), 4);
6048
- },
6049
- h: function h(dateObj) {
6050
- return dateObj.getHours() % 12 || 12;
6051
- },
6052
- hh: function hh(dateObj) {
6053
- return pad(dateObj.getHours() % 12 || 12);
6054
- },
6055
- H: function H(dateObj) {
6056
- return dateObj.getHours();
6057
- },
6058
- HH: function HH(dateObj) {
6059
- return pad(dateObj.getHours());
6060
- },
6061
- m: function m(dateObj) {
6062
- return dateObj.getMinutes();
6063
- },
6064
- mm: function mm(dateObj) {
6065
- return pad(dateObj.getMinutes());
6066
- },
6067
- s: function s(dateObj) {
6068
- return dateObj.getSeconds();
6069
- },
6070
- ss: function ss(dateObj) {
6071
- return pad(dateObj.getSeconds());
6072
- },
6073
- S: function S(dateObj) {
6074
- return Math.round(dateObj.getMilliseconds() / 100);
6075
- },
6076
- SS: function SS(dateObj) {
6077
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
6078
- },
6079
- SSS: function SSS(dateObj) {
6080
- return pad(dateObj.getMilliseconds(), 3);
6081
- },
6082
- a: function a(dateObj) {
6083
- return dateObj.getHours() < 12 ? '上午' : '下午';
6084
- },
6085
- A: function A(dateObj) {
6086
- return dateObj.getHours() < 12 ? '上午' : '下午';
6087
- },
6088
- ZZ: function ZZ(dateObj) {
6089
- var o = dateObj.getTimezoneOffset();
6090
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
6091
- }
6092
- };
6093
-
6094
- var parseFlags = {
6095
- d: [twoDigits, function (d, v) {
6096
- d.day = v;
6097
- }],
6098
- Do: [twoDigits + word, function (d, v) {
6099
- d.day = parseInt(v, 10);
6100
- }],
6101
- M: [twoDigits, function (d, v) {
6102
- d.month = v - 1;
6103
- }],
6104
- yy: [twoDigits, function (d, v) {
6105
- var da = new Date(),
6106
- cent = +('' + da.getFullYear()).substr(0, 2);
6107
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
6108
- }],
6109
- h: [twoDigits, function (d, v) {
6110
- d.hour = v;
6111
- }],
6112
- m: [twoDigits, function (d, v) {
6113
- d.minute = v;
6114
- }],
6115
- s: [twoDigits, function (d, v) {
6116
- d.second = v;
6117
- }],
6118
- yyyy: [fourDigits, function (d, v) {
6119
- d.year = v;
6120
- }],
6121
- S: ['\\d', function (d, v) {
6122
- d.millisecond = v * 100;
6123
- }],
6124
- SS: ['\\d{2}', function (d, v) {
6125
- d.millisecond = v * 10;
6126
- }],
6127
- SSS: [threeDigits, function (d, v) {
6128
- d.millisecond = v;
6129
- }],
6130
- D: [twoDigits, noop],
6131
- ddd: [word, noop],
6132
- MMM: [word, monthUpdate('monthNamesShort')],
6133
- MMMM: [word, monthUpdate('monthNames')],
6134
- a: [word, function (d, v) {
6135
- var val = v.toLowerCase();
6136
- if (val === '上午') {
6137
- d.isPm = false;
6138
- } else if (val === '下午') {
6139
- d.isPm = true;
6140
- }
6141
- }],
6142
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
6143
- var parts = (v + '').match(/([+-]|\d\d)/gi),
6144
- minutes = void 0;
6145
-
6146
- if (parts) {
6147
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
6148
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
6149
- }
6150
- }]
6151
- };
6152
- parseFlags.dd = parseFlags.d;
6153
- parseFlags.dddd = parseFlags.ddd;
6154
- parseFlags.DD = parseFlags.D;
6155
- parseFlags.mm = parseFlags.m;
6156
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
6157
- parseFlags.MM = parseFlags.M;
6158
- parseFlags.ss = parseFlags.s;
6159
- parseFlags.A = parseFlags.a;
6160
-
6161
- // Some common format strings
6162
- fecha.masks = {
6163
- default: 'ddd MMM dd yyyy HH:mm:ss',
6164
- shortDate: 'M/D/yy',
6165
- mediumDate: 'MMM d, yyyy',
6166
- longDate: 'MMMM d, yyyy',
6167
- fullDate: 'dddd, MMMM d, yyyy',
6168
- shortTime: 'HH:mm',
6169
- mediumTime: 'HH:mm:ss',
6170
- longTime: 'HH:mm:ss.SSS'
6171
- };
6172
-
5986
+ */
5987
+ const fecha = {};
5988
+ const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5989
+ const twoDigits = '\\d\\d?';
5990
+ const threeDigits = '\\d{3}';
5991
+ const fourDigits = '\\d{4}';
5992
+ const word = '[^\\s]+';
5993
+ const literal = /\[([^]*?)\]/gm;
5994
+ const noop = function () {};
5995
+
5996
+ function regexEscape(str) {
5997
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5998
+ }
5999
+
6000
+ function shorten(arr, sLen) {
6001
+ const newArr = [];
6002
+ for (let i = 0, len = arr.length; i < len; i++) {
6003
+ newArr.push(arr[i].substr(0, sLen));
6004
+ }
6005
+ return newArr;
6006
+ }
6007
+
6008
+ function monthUpdate() {
6009
+ return function (d, v) {
6010
+ const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
6011
+ if (~index) {
6012
+ d.month = index;
6013
+ }
6014
+ };
6015
+ }
6016
+
6017
+ function pad(val, len) {
6018
+ val = String(val);
6019
+ len = len || 2;
6020
+ while (val.length < len) {
6021
+ val = '0' + val;
6022
+ }
6023
+ return val;
6024
+ }
6025
+
6026
+ // 直接使用中文日期名称常量
6027
+ const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
6028
+ const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
6029
+ const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
6030
+ const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
6031
+ const amPm = ['上午', '下午'];
6032
+ const DoFn = function DoFn(D) {
6033
+ return D + '日';
6034
+ };
6035
+
6036
+ const formatFlags = {
6037
+ D: function(dateObj) {
6038
+ return dateObj.getDay();
6039
+ },
6040
+ DD: function(dateObj) {
6041
+ return pad(dateObj.getDay());
6042
+ },
6043
+ Do: function(dateObj) {
6044
+ return DoFn(dateObj.getDate());
6045
+ },
6046
+ d: function(dateObj) {
6047
+ return dateObj.getDate();
6048
+ },
6049
+ dd: function(dateObj) {
6050
+ return pad(dateObj.getDate());
6051
+ },
6052
+ ddd: function(dateObj) {
6053
+ return dayNamesShort[dateObj.getDay()];
6054
+ },
6055
+ dddd: function(dateObj) {
6056
+ return dayNames[dateObj.getDay()];
6057
+ },
6058
+ M: function(dateObj) {
6059
+ return dateObj.getMonth() + 1;
6060
+ },
6061
+ MM: function(dateObj) {
6062
+ return pad(dateObj.getMonth() + 1);
6063
+ },
6064
+ MMM: function(dateObj) {
6065
+ return monthNamesShort[dateObj.getMonth()];
6066
+ },
6067
+ MMMM: function(dateObj) {
6068
+ return monthNames[dateObj.getMonth()];
6069
+ },
6070
+ yy: function(dateObj) {
6071
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
6072
+ },
6073
+ yyyy: function(dateObj) {
6074
+ return pad(dateObj.getFullYear(), 4);
6075
+ },
6076
+ h: function(dateObj) {
6077
+ return dateObj.getHours() % 12 || 12;
6078
+ },
6079
+ hh: function(dateObj) {
6080
+ return pad(dateObj.getHours() % 12 || 12);
6081
+ },
6082
+ H: function(dateObj) {
6083
+ return dateObj.getHours();
6084
+ },
6085
+ HH: function(dateObj) {
6086
+ return pad(dateObj.getHours());
6087
+ },
6088
+ m: function(dateObj) {
6089
+ return dateObj.getMinutes();
6090
+ },
6091
+ mm: function(dateObj) {
6092
+ return pad(dateObj.getMinutes());
6093
+ },
6094
+ s: function(dateObj) {
6095
+ return dateObj.getSeconds();
6096
+ },
6097
+ ss: function(dateObj) {
6098
+ return pad(dateObj.getSeconds());
6099
+ },
6100
+ S: function(dateObj) {
6101
+ return Math.round(dateObj.getMilliseconds() / 100);
6102
+ },
6103
+ SS: function(dateObj) {
6104
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
6105
+ },
6106
+ SSS: function(dateObj) {
6107
+ return pad(dateObj.getMilliseconds(), 3);
6108
+ },
6109
+ a: function(dateObj) {
6110
+ return dateObj.getHours() < 12 ? '上午' : '下午';
6111
+ },
6112
+ A: function(dateObj) {
6113
+ return dateObj.getHours() < 12 ? '上午' : '下午';
6114
+ },
6115
+ ZZ: function(dateObj) {
6116
+ const o = dateObj.getTimezoneOffset();
6117
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
6118
+ }
6119
+ };
6120
+
6121
+ const parseFlags = {
6122
+ d: [twoDigits, function (d, v) {
6123
+ d.day = v;
6124
+ }],
6125
+ Do: [twoDigits + word, function (d, v) {
6126
+ d.day = parseInt(v, 10);
6127
+ }],
6128
+ M: [twoDigits, function (d, v) {
6129
+ d.month = v - 1;
6130
+ }],
6131
+ yy: [twoDigits, function (d, v) {
6132
+ const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
6133
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
6134
+ }],
6135
+ h: [twoDigits, function (d, v) {
6136
+ d.hour = v;
6137
+ }],
6138
+ m: [twoDigits, function (d, v) {
6139
+ d.minute = v;
6140
+ }],
6141
+ s: [twoDigits, function (d, v) {
6142
+ d.second = v;
6143
+ }],
6144
+ yyyy: [fourDigits, function (d, v) {
6145
+ d.year = v;
6146
+ }],
6147
+ S: ['\\d', function (d, v) {
6148
+ d.millisecond = v * 100;
6149
+ }],
6150
+ SS: ['\\d{2}', function (d, v) {
6151
+ d.millisecond = v * 10;
6152
+ }],
6153
+ SSS: [threeDigits, function (d, v) {
6154
+ d.millisecond = v;
6155
+ }],
6156
+ D: [twoDigits, noop],
6157
+ ddd: [word, noop],
6158
+ MMM: [word, monthUpdate('monthNamesShort')],
6159
+ MMMM: [word, monthUpdate('monthNames')],
6160
+ a: [word, function (d, v) {
6161
+ const val = v.toLowerCase();
6162
+ if (val === '上午') {
6163
+ d.isPm = false;
6164
+ } else if (val === '下午') {
6165
+ d.isPm = true;
6166
+ }
6167
+ }],
6168
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
6169
+ let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
6170
+
6171
+ if (parts) {
6172
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
6173
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
6174
+ }
6175
+ }]
6176
+ };
6177
+ parseFlags.dd = parseFlags.d;
6178
+ parseFlags.dddd = parseFlags.ddd;
6179
+ parseFlags.DD = parseFlags.D;
6180
+ parseFlags.mm = parseFlags.m;
6181
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
6182
+ parseFlags.MM = parseFlags.M;
6183
+ parseFlags.ss = parseFlags.s;
6184
+ parseFlags.A = parseFlags.a;
6185
+
6186
+
6187
+ // Some common format strings
6188
+ fecha.masks = {
6189
+ default: 'ddd MMM dd yyyy HH:mm:ss',
6190
+ shortDate: 'M/D/yy',
6191
+ mediumDate: 'MMM d, yyyy',
6192
+ longDate: 'MMMM d, yyyy',
6193
+ fullDate: 'dddd, MMMM d, yyyy',
6194
+ shortTime: 'HH:mm',
6195
+ mediumTime: 'HH:mm:ss',
6196
+ longTime: 'HH:mm:ss.SSS'
6197
+ };
6198
+
6173
6199
  /***
6174
6200
  * Format a date
6175
6201
  * @method format
6176
6202
  * @param {Date|number} dateObj
6177
6203
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
6178
- */
6179
- fecha.format = function (dateObj, mask) {
6180
- if (typeof dateObj === 'number') {
6181
- dateObj = new Date(dateObj);
6182
- }
6183
-
6184
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
6185
- throw new Error('Invalid Date in fecha.format');
6186
- }
6187
-
6188
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
6189
-
6190
- var literals = [];
6191
-
6192
- // Make literals inactive by replacing them with ??
6193
- mask = mask.replace(literal, function ($0, $1) {
6194
- literals.push($1);
6195
- return '@@@';
6196
- });
6197
- // Apply formatting rules
6198
- mask = mask.replace(token, function ($0) {
6199
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
6200
- });
6201
- // Inline literal values back into the formatted value
6202
- return mask.replace(/@@@/g, function () {
6203
- return literals.shift();
6204
- });
6205
- };
6206
-
6204
+ */
6205
+ fecha.format = function (dateObj, mask) {
6206
+ if (typeof dateObj === 'number') {
6207
+ dateObj = new Date(dateObj);
6208
+ }
6209
+
6210
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
6211
+ throw new Error('Invalid Date in fecha.format');
6212
+ }
6213
+
6214
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
6215
+
6216
+ const literals = [];
6217
+
6218
+ // Make literals inactive by replacing them with ??
6219
+ mask = mask.replace(literal, function($0, $1) {
6220
+ literals.push($1);
6221
+ return '@@@';
6222
+ });
6223
+ // Apply formatting rules
6224
+ mask = mask.replace(token, function ($0) {
6225
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
6226
+ });
6227
+ // Inline literal values back into the formatted value
6228
+ return mask.replace(/@@@/g, function() {
6229
+ return literals.shift();
6230
+ });
6231
+ };
6232
+
6207
6233
  /**
6208
6234
  * Parse a date string into an object, changes - into /
6209
6235
  * @method parse
6210
6236
  * @param {string} dateStr Date string
6211
6237
  * @param {string} format Date parse format
6212
6238
  * @returns {Date|boolean}
6213
- */
6214
- fecha.parse = function (dateStr, format) {
6215
- if (typeof format !== 'string') {
6216
- throw new Error('Invalid format in fecha.parse');
6217
- }
6218
-
6219
- format = fecha.masks[format] || format;
6220
-
6221
- // Avoid regular expression denial of service, fail early for really long strings
6222
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
6223
- if (dateStr.length > 1000) {
6224
- return null;
6225
- }
6226
-
6227
- var dateInfo = {};
6228
- var parseInfo = [];
6229
- var literals = [];
6230
- format = format.replace(literal, function ($0, $1) {
6231
- literals.push($1);
6232
- return '@@@';
6233
- });
6234
- var newFormat = regexEscape(format).replace(token, function ($0) {
6235
- if (parseFlags[$0]) {
6236
- var info = parseFlags[$0];
6237
- parseInfo.push(info[1]);
6238
- return '(' + info[0] + ')';
6239
- }
6240
-
6241
- return $0;
6242
- });
6243
- newFormat = newFormat.replace(/@@@/g, function () {
6244
- return literals.shift();
6245
- });
6246
- var matches = dateStr.match(new RegExp(newFormat, 'i'));
6247
- if (!matches) {
6248
- return null;
6249
- }
6250
-
6251
- for (var i = 1; i < matches.length; i++) {
6252
- parseInfo[i - 1](dateInfo, matches[i]);
6253
- }
6254
-
6255
- var today = new Date();
6256
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
6257
- dateInfo.hour = +dateInfo.hour + 12;
6258
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
6259
- dateInfo.hour = 0;
6260
- }
6261
-
6262
- var date = void 0;
6263
- if (dateInfo.timezoneOffset != null) {
6264
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
6265
- 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));
6266
- } else {
6267
- 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);
6268
- }
6269
- return date;
6270
- };
6271
-
6272
- // 导出fecha对象
6273
-
6274
-
6275
- // 以下是从date-util.js合并的函数
6276
- var newArray = function newArray(start, end) {
6277
- var result = [];
6278
- for (var i = start; i <= end; i++) {
6279
- result.push(i);
6280
- }
6281
- return result;
6282
- };
6283
-
6284
- var getSettings = function getSettings() {
6285
- return {
6286
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
6287
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
6288
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
6289
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
6290
- amPm: ['上午', '下午']
6291
- };
6292
- };
6293
-
6294
- var toDate = function toDate(date) {
6295
- return isDate(date) ? new Date(date) : null;
6296
- };
6297
-
6298
- var isDate = function isDate(date) {
6299
- if (date === null || date === undefined) return false;
6300
- if (isNaN(new Date(date).getTime())) return false;
6301
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
6302
- return true;
6303
- };
6304
-
6305
- var isDateObject = function isDateObject(val) {
6306
- return val instanceof Date;
6307
- };
6308
-
6309
- var formatDate = function formatDate(date) {
6310
- var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
6311
-
6312
- // 处理多种输入类型
6313
- if (!date) return '';
6314
-
6315
- // 如果是时间戳,转成日期对象
6316
- if (typeof date === 'number') {
6317
- date = new Date(date);
6318
- }
6319
- // 如果是字符串,转成日期对象
6320
- if (typeof date === 'string') {
6321
- date = new Date(date);
6322
- }
6323
-
6324
- // 调用toDate进一步验证和转换
6325
- date = toDate(date);
6326
- if (!date) return '';
6327
-
6328
- // 兼容大写和小写的格式标记
6329
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
6330
- var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
6331
-
6332
- // 使用fecha库进行格式化,支持中文配置
6333
- var str = fecha.format(date, lowercaseFormat, getSettings());
6334
- return str;
6335
- };
6336
-
6337
- var parseDate = function parseDate(string, format) {
6338
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
6339
- };
6340
-
6341
- var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
6342
- if (month === 3 || month === 5 || month === 8 || month === 10) {
6343
- return 30;
6344
- }
6345
-
6346
- if (month === 1) {
6347
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
6348
- return 29;
6349
- } else {
6350
- return 28;
6351
- }
6352
- }
6353
-
6354
- return 31;
6355
- };
6356
-
6357
- var getDayCountOfYear = function getDayCountOfYear(year) {
6358
- var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
6359
- return isLeapYear ? 366 : 365;
6360
- };
6361
-
6362
- var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
6363
- var temp = new Date(date.getTime());
6364
- temp.setDate(1);
6365
- return temp.getDay();
6366
- };
6367
-
6368
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
6369
- // {prev, next} Date should work for Daylight Saving Time
6370
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
6371
- var prevDate = function prevDate(date) {
6372
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6373
-
6374
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
6375
- };
6376
-
6377
- var nextDate = function nextDate(date) {
6378
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6379
-
6380
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
6381
- };
6382
-
6383
- var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
6384
- var result = new Date(year, month, 1);
6385
- var day = result.getDay();
6386
-
6387
- if (day === 0) {
6388
- return prevDate(result, 7);
6389
- } else {
6390
- return prevDate(result, day);
6391
- }
6392
- };
6393
-
6394
- var getWeekNumber = function getWeekNumber(date) {
6395
- // 支持多种输入类型
6396
- if (!date || !isDate(date)) {
6397
- date = new Date();
6398
- }
6399
- if (typeof date === 'string') {
6400
- date = new Date(date);
6401
- }
6402
-
6403
- // 验证日期有效性
6404
- if (!isDate(date)) return null;
6405
-
6406
- var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
6407
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
6408
- // 将星期日的星期数设为7
6409
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
6410
- // 获取当年的第一天
6411
- var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
6412
- // 计算到最近的星期四的完整周数
6413
- var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
6414
- // 返回周数
6415
- return weekNo;
6416
- };
6417
-
6418
- var getRangeHours = function getRangeHours(ranges) {
6419
- var hours = [];
6420
- var disabledHours = [];
6421
-
6422
- (ranges || []).forEach(function (range) {
6423
- var value = range.map(function (date) {
6424
- return date.getHours();
6425
- });
6426
-
6427
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
6428
- });
6429
-
6430
- if (disabledHours.length) {
6431
- for (var i = 0; i < 24; i++) {
6432
- hours[i] = disabledHours.indexOf(i) === -1;
6433
- }
6434
- } else {
6435
- for (var _i = 0; _i < 24; _i++) {
6436
- hours[_i] = false;
6437
- }
6438
- }
6439
-
6440
- return hours;
6441
- };
6442
-
6443
- var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
6444
- if (amount <= 0) return [];
6445
- var temp = new Date(date.getTime());
6446
- temp.setDate(0);
6447
- var lastDay = temp.getDate();
6448
- return range(amount).map(function (_, index) {
6449
- return lastDay - (amount - index - 1);
6450
- });
6451
- };
6452
-
6453
- var getMonthDays = function getMonthDays(date) {
6454
- var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
6455
- var days = temp.getDate();
6456
- return range(days).map(function (_, index) {
6457
- return index + 1;
6458
- });
6459
- };
6460
-
6461
- function setRangeData(arr, start, end, value) {
6462
- for (var i = start; i < end; i++) {
6463
- arr[i] = value;
6464
- }
6465
- }
6466
-
6467
- var getRangeMinutes = function getRangeMinutes(ranges, hour) {
6468
- var minutes = new Array(60);
6469
-
6470
- if (ranges.length > 0) {
6471
- ranges.forEach(function (range) {
6472
- var start = range[0];
6473
- var end = range[1];
6474
- var startHour = start.getHours();
6475
- var startMinute = start.getMinutes();
6476
- var endHour = end.getHours();
6477
- var endMinute = end.getMinutes();
6478
- if (startHour === hour && endHour !== hour) {
6479
- setRangeData(minutes, startMinute, 60, true);
6480
- } else if (startHour === hour && endHour === hour) {
6481
- setRangeData(minutes, startMinute, endMinute + 1, true);
6482
- } else if (startHour !== hour && endHour === hour) {
6483
- setRangeData(minutes, 0, endMinute + 1, true);
6484
- } else if (startHour < hour && endHour > hour) {
6485
- setRangeData(minutes, 0, 60, true);
6486
- }
6487
- });
6488
- } else {
6489
- setRangeData(minutes, 0, 60, true);
6490
- }
6491
- return minutes;
6492
- };
6493
-
6494
- var range = function range(n) {
6495
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
6496
- return Array.apply(null, { length: n }).map(function (_, n) {
6497
- return n;
6498
- });
6499
- };
6500
-
6501
- var modifyDate = function modifyDate(date, y, m, d) {
6502
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
6503
- };
6504
-
6505
- var modifyTime = function modifyTime(date, h, m, s) {
6506
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
6507
- };
6508
-
6509
- var modifyWithTimeString = function modifyWithTimeString(date, time) {
6510
- if (date == null || !time) {
6511
- return date;
6512
- }
6513
- time = parseDate(time, 'HH:mm:ss');
6514
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
6515
- };
6516
-
6517
- var clearTime = function clearTime(date) {
6518
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
6519
- };
6520
-
6521
- var clearMilliseconds = function clearMilliseconds(date) {
6522
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
6523
- };
6524
-
6525
- var limitTimeRange = function limitTimeRange(date, ranges) {
6526
- var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
6527
-
6528
- // TODO: refactory a more elegant solution
6529
- if (ranges.length === 0) return date;
6530
- var normalizeDate = function normalizeDate(date) {
6531
- return fecha.parse(fecha.format(date, format), format);
6532
- };
6533
- var ndate = normalizeDate(date);
6534
- var nranges = ranges.map(function (range) {
6535
- return range.map(normalizeDate);
6536
- });
6537
- if (nranges.some(function (nrange) {
6538
- return ndate >= nrange[0] && ndate <= nrange[1];
6539
- })) return date;
6540
-
6541
- var minDate = nranges[0][0];
6542
- var maxDate = nranges[0][0];
6543
-
6544
- nranges.forEach(function (nrange) {
6545
- minDate = new Date(Math.min(nrange[0], minDate));
6546
- maxDate = new Date(Math.max(nrange[1], minDate));
6547
- });
6548
-
6549
- var ret = ndate < minDate ? minDate : maxDate;
6550
- // preserve Year/Month/Date
6551
- return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
6552
- };
6553
-
6554
- var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
6555
- var limitedDate = limitTimeRange(date, selectableRange, format);
6556
- return limitedDate.getTime() === date.getTime();
6557
- };
6558
-
6559
- var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
6560
- // clamp date to the number of days in `year`, `month`
6561
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
6562
- var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
6563
- return modifyDate(date, year, month, monthDate);
6564
- };
6565
-
6566
- var prevMonth = function prevMonth(date) {
6567
- var year = date.getFullYear();
6568
- var month = date.getMonth();
6569
- return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
6570
- };
6571
-
6572
- var nextMonth = function nextMonth(date) {
6573
- var year = date.getFullYear();
6574
- var month = date.getMonth();
6575
- return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
6576
- };
6577
-
6578
- var prevYear = function prevYear(date) {
6579
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6580
-
6581
- var year = date.getFullYear();
6582
- var month = date.getMonth();
6583
- return changeYearMonthAndClampDate(date, year - amount, month);
6584
- };
6585
-
6586
- var nextYear = function nextYear(date) {
6587
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6588
-
6589
- var year = date.getFullYear();
6590
- var month = date.getMonth();
6591
- return changeYearMonthAndClampDate(date, year + amount, month);
6592
- };
6593
-
6594
- var extractDateFormat = function extractDateFormat(format) {
6595
- return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
6596
- };
6597
-
6598
- var extractTimeFormat = function extractTimeFormat(format) {
6599
- return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
6600
- };
6601
-
6602
- var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
6603
- return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
6604
- };
6605
-
6239
+ */
6240
+ fecha.parse = function (dateStr, format) {
6241
+ if (typeof format !== 'string') {
6242
+ throw new Error('Invalid format in fecha.parse');
6243
+ }
6244
+
6245
+ format = fecha.masks[format] || format;
6246
+
6247
+ // Avoid regular expression denial of service, fail early for really long strings
6248
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
6249
+ if (dateStr.length > 1000) {
6250
+ return null;
6251
+ }
6252
+
6253
+ const dateInfo = {};
6254
+ const parseInfo = [];
6255
+ const literals = [];
6256
+ format = format.replace(literal, function($0, $1) {
6257
+ literals.push($1);
6258
+ return '@@@';
6259
+ });
6260
+ let newFormat = regexEscape(format).replace(token, function ($0) {
6261
+ if (parseFlags[$0]) {
6262
+ const info = parseFlags[$0];
6263
+ parseInfo.push(info[1]);
6264
+ return '(' + info[0] + ')';
6265
+ }
6266
+
6267
+ return $0;
6268
+ });
6269
+ newFormat = newFormat.replace(/@@@/g, function() {
6270
+ return literals.shift();
6271
+ });
6272
+ const matches = dateStr.match(new RegExp(newFormat, 'i'));
6273
+ if (!matches) {
6274
+ return null;
6275
+ }
6276
+
6277
+ for (let i = 1; i < matches.length; i++) {
6278
+ parseInfo[i - 1](dateInfo, matches[i]);
6279
+ }
6280
+
6281
+ const today = new Date();
6282
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
6283
+ dateInfo.hour = +dateInfo.hour + 12;
6284
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
6285
+ dateInfo.hour = 0;
6286
+ }
6287
+
6288
+ let date;
6289
+ if (dateInfo.timezoneOffset != null) {
6290
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
6291
+ date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
6292
+ dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
6293
+ } else {
6294
+ date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
6295
+ dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
6296
+ }
6297
+ return date;
6298
+ };
6299
+
6300
+ // 导出fecha对象
6301
+
6302
+
6303
+ // 以下是从date-util.js合并的函数
6304
+ const newArray = function(start, end) {
6305
+ let result = [];
6306
+ for (let i = start; i <= end; i++) {
6307
+ result.push(i);
6308
+ }
6309
+ return result;
6310
+ };
6311
+
6312
+ const getSettings = () => {
6313
+ return {
6314
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
6315
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
6316
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
6317
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
6318
+ amPm: ['上午', '下午']
6319
+ };
6320
+ };
6321
+
6322
+ const toDate = function(date) {
6323
+ return isDate(date) ? new Date(date) : null;
6324
+ };
6325
+
6326
+ const isDate = function(date) {
6327
+ if (date === null || date === undefined) return false;
6328
+ if (isNaN(new Date(date).getTime())) return false;
6329
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
6330
+ return true;
6331
+ };
6332
+
6333
+ const isDateObject = function(val) {
6334
+ return val instanceof Date;
6335
+ };
6336
+
6337
+ const formatDate = function (date, format = 'yyyy-MM-dd') {
6338
+ // 处理多种输入类型
6339
+ if (!date) return '';
6340
+
6341
+ // 如果是时间戳,转成日期对象
6342
+ if (typeof date === 'number') {
6343
+ date = new Date(date);
6344
+ }
6345
+ // 如果是字符串,转成日期对象
6346
+ if (typeof date === 'string') {
6347
+ date = new Date(date);
6348
+ }
6349
+
6350
+ // 调用toDate进一步验证和转换
6351
+ date = toDate(date);
6352
+ if (!date) return '';
6353
+
6354
+ // 兼容大写和小写的格式标记
6355
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
6356
+ const lowercaseFormat = format
6357
+ .replace(/YYYY/g, 'yyyy')
6358
+ .replace(/D/g, 'd')
6359
+
6360
+ // 使用fecha库进行格式化,支持中文配置
6361
+ const str = fecha.format(date, lowercaseFormat, getSettings());
6362
+ return str;
6363
+ };
6364
+
6365
+ const parseDate = function(string, format) {
6366
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
6367
+ };
6368
+
6369
+ const getDayCountOfMonth = function(year, month) {
6370
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
6371
+ return 30;
6372
+ }
6373
+
6374
+ if (month === 1) {
6375
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
6376
+ return 29;
6377
+ } else {
6378
+ return 28;
6379
+ }
6380
+ }
6381
+
6382
+ return 31;
6383
+ };
6384
+
6385
+ const getDayCountOfYear = function(year) {
6386
+ const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
6387
+ return isLeapYear ? 366 : 365;
6388
+ };
6389
+
6390
+ const getFirstDayOfMonth = function(date) {
6391
+ const temp = new Date(date.getTime());
6392
+ temp.setDate(1);
6393
+ return temp.getDay();
6394
+ };
6395
+
6396
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
6397
+ // {prev, next} Date should work for Daylight Saving Time
6398
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
6399
+ const prevDate = function(date, amount = 1) {
6400
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
6401
+ };
6402
+
6403
+ const nextDate = function(date, amount = 1) {
6404
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
6405
+ };
6406
+
6407
+ const getStartDateOfMonth = function(year, month) {
6408
+ const result = new Date(year, month, 1);
6409
+ const day = result.getDay();
6410
+
6411
+ if (day === 0) {
6412
+ return prevDate(result, 7);
6413
+ } else {
6414
+ return prevDate(result, day);
6415
+ }
6416
+ };
6417
+
6418
+ const getWeekNumber = function(date) {
6419
+ // 支持多种输入类型
6420
+ if (!date||!isDate(date)) {
6421
+ date = new Date();
6422
+ }
6423
+ if (typeof date === 'string') {
6424
+ date = new Date(date);
6425
+ }
6426
+
6427
+ // 验证日期有效性
6428
+ if (!isDate(date)) return null;
6429
+
6430
+ const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
6431
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
6432
+ // 将星期日的星期数设为7
6433
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
6434
+ // 获取当年的第一天
6435
+ const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
6436
+ // 计算到最近的星期四的完整周数
6437
+ const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
6438
+ // 返回周数
6439
+ return weekNo;
6440
+ };
6441
+
6442
+ const getRangeHours = function(ranges) {
6443
+ const hours = [];
6444
+ let disabledHours = [];
6445
+
6446
+ (ranges || []).forEach(range => {
6447
+ const value = range.map(date => date.getHours());
6448
+
6449
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
6450
+ });
6451
+
6452
+ if (disabledHours.length) {
6453
+ for (let i = 0; i < 24; i++) {
6454
+ hours[i] = disabledHours.indexOf(i) === -1;
6455
+ }
6456
+ } else {
6457
+ for (let i = 0; i < 24; i++) {
6458
+ hours[i] = false;
6459
+ }
6460
+ }
6461
+
6462
+ return hours;
6463
+ };
6464
+
6465
+ const getPrevMonthLastDays = (date, amount) => {
6466
+ if (amount <= 0) return [];
6467
+ const temp = new Date(date.getTime());
6468
+ temp.setDate(0);
6469
+ const lastDay = temp.getDate();
6470
+ return range(amount).map((_, index) => lastDay - (amount - index - 1));
6471
+ };
6472
+
6473
+ const getMonthDays = (date) => {
6474
+ const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
6475
+ const days = temp.getDate();
6476
+ return range(days).map((_, index) => index + 1);
6477
+ };
6478
+
6479
+ function setRangeData(arr, start, end, value) {
6480
+ for (let i = start; i < end; i++) {
6481
+ arr[i] = value;
6482
+ }
6483
+ }
6484
+
6485
+ const getRangeMinutes = function(ranges, hour) {
6486
+ const minutes = new Array(60);
6487
+
6488
+ if (ranges.length > 0) {
6489
+ ranges.forEach(range => {
6490
+ const start = range[0];
6491
+ const end = range[1];
6492
+ const startHour = start.getHours();
6493
+ const startMinute = start.getMinutes();
6494
+ const endHour = end.getHours();
6495
+ const endMinute = end.getMinutes();
6496
+ if (startHour === hour && endHour !== hour) {
6497
+ setRangeData(minutes, startMinute, 60, true);
6498
+ } else if (startHour === hour && endHour === hour) {
6499
+ setRangeData(minutes, startMinute, endMinute + 1, true);
6500
+ } else if (startHour !== hour && endHour === hour) {
6501
+ setRangeData(minutes, 0, endMinute + 1, true);
6502
+ } else if (startHour < hour && endHour > hour) {
6503
+ setRangeData(minutes, 0, 60, true);
6504
+ }
6505
+ });
6506
+ } else {
6507
+ setRangeData(minutes, 0, 60, true);
6508
+ }
6509
+ return minutes;
6510
+ };
6511
+
6512
+ const range = function(n) {
6513
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
6514
+ return Array.apply(null, {length: n}).map((_, n) => n);
6515
+ };
6516
+
6517
+ const modifyDate = function(date, y, m, d) {
6518
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
6519
+ };
6520
+
6521
+ const modifyTime = function(date, h, m, s) {
6522
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
6523
+ };
6524
+
6525
+ const modifyWithTimeString = (date, time) => {
6526
+ if (date == null || !time) {
6527
+ return date;
6528
+ }
6529
+ time = parseDate(time, 'HH:mm:ss');
6530
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
6531
+ };
6532
+
6533
+ const clearTime = function(date) {
6534
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
6535
+ };
6536
+
6537
+ const clearMilliseconds = function(date) {
6538
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
6539
+ };
6540
+
6541
+ const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
6542
+ // TODO: refactory a more elegant solution
6543
+ if (ranges.length === 0) return date;
6544
+ const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
6545
+ const ndate = normalizeDate(date);
6546
+ const nranges = ranges.map(range => range.map(normalizeDate));
6547
+ if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
6548
+
6549
+ let minDate = nranges[0][0];
6550
+ let maxDate = nranges[0][0];
6551
+
6552
+ nranges.forEach(nrange => {
6553
+ minDate = new Date(Math.min(nrange[0], minDate));
6554
+ maxDate = new Date(Math.max(nrange[1], minDate));
6555
+ });
6556
+
6557
+ const ret = ndate < minDate ? minDate : maxDate;
6558
+ // preserve Year/Month/Date
6559
+ return modifyDate(
6560
+ ret,
6561
+ date.getFullYear(),
6562
+ date.getMonth(),
6563
+ date.getDate()
6564
+ );
6565
+ };
6566
+
6567
+ const timeWithinRange = function(date, selectableRange, format) {
6568
+ const limitedDate = limitTimeRange(date, selectableRange, format);
6569
+ return limitedDate.getTime() === date.getTime();
6570
+ };
6571
+
6572
+ const changeYearMonthAndClampDate = function(date, year, month) {
6573
+ // clamp date to the number of days in `year`, `month`
6574
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
6575
+ const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
6576
+ return modifyDate(date, year, month, monthDate);
6577
+ };
6578
+
6579
+ const prevMonth = function(date) {
6580
+ const year = date.getFullYear();
6581
+ const month = date.getMonth();
6582
+ return month === 0
6583
+ ? changeYearMonthAndClampDate(date, year - 1, 11)
6584
+ : changeYearMonthAndClampDate(date, year, month - 1);
6585
+ };
6586
+
6587
+ const nextMonth = function(date) {
6588
+ const year = date.getFullYear();
6589
+ const month = date.getMonth();
6590
+ return month === 11
6591
+ ? changeYearMonthAndClampDate(date, year + 1, 0)
6592
+ : changeYearMonthAndClampDate(date, year, month + 1);
6593
+ };
6594
+
6595
+ const prevYear = function(date, amount = 1) {
6596
+ const year = date.getFullYear();
6597
+ const month = date.getMonth();
6598
+ return changeYearMonthAndClampDate(date, year - amount, month);
6599
+ };
6600
+
6601
+ const nextYear = function(date, amount = 1) {
6602
+ const year = date.getFullYear();
6603
+ const month = date.getMonth();
6604
+ return changeYearMonthAndClampDate(date, year + amount, month);
6605
+ };
6606
+
6607
+ const extractDateFormat = function(format) {
6608
+ return format
6609
+ .replace(/\W?m{1,2}|\W?ZZ/g, '')
6610
+ .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
6611
+ .trim();
6612
+ };
6613
+
6614
+ const extractTimeFormat = function(format) {
6615
+ return format
6616
+ .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
6617
+ .trim();
6618
+ };
6619
+
6620
+ const validateRangeInOneMonth = function(start, end) {
6621
+ return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
6622
+ };
6623
+
6606
6624
  /**
6607
6625
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
6608
6626
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
6609
6627
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
6610
6628
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
6611
6629
  * @returns {number} 工作日数量
6612
- */
6613
- var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
6614
- var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
6615
-
6616
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
6617
- throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
6618
- }
6619
-
6620
- var startDateObj = new Date(start_date);
6621
- var endDateObj = new Date(end_date);
6622
-
6623
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
6624
- throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
6625
- }
6626
-
6627
- if (startDateObj > endDateObj) {
6628
- throw new Error('Start date should be earlier than or equal to end date.');
6629
- }
6630
-
6631
- var workdays = 0;
6632
-
6633
- // Iterate through each day in the date range
6634
-
6635
- var _loop = function _loop(currentDate) {
6636
- // Check if the current day is a weekend (Saturday or Sunday)
6637
- var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
6638
-
6639
- // Check if the current day is a holiday
6640
- var isHoliday = holidays.some(function (holiday) {
6641
- var holidayDate = new Date(holiday);
6642
- return currentDate.toDateString() === holidayDate.toDateString();
6643
- });
6644
-
6645
- // If it's a workday (not a weekend or holiday), increment the workdays count
6646
- if (!isWeekend && !isHoliday) {
6647
- workdays++;
6648
- }
6649
- };
6650
-
6651
- for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
6652
- _loop(currentDate);
6653
- }
6654
-
6655
- return workdays;
6656
- };
6657
-
6630
+ */
6631
+ const calculateNetworkDays = function (start_date, end_date, holidays = []) {
6632
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
6633
+ throw new Error(
6634
+ "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
6635
+ );
6636
+ }
6637
+
6638
+ const startDateObj = new Date(start_date);
6639
+ const endDateObj = new Date(end_date);
6640
+
6641
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
6642
+ throw new Error(
6643
+ "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
6644
+ );
6645
+ }
6646
+
6647
+ if (startDateObj > endDateObj) {
6648
+ throw new Error('Start date should be earlier than or equal to end date.');
6649
+ }
6650
+
6651
+ let workdays = 0;
6652
+
6653
+ // Iterate through each day in the date range
6654
+ for (
6655
+ let currentDate = new Date(startDateObj);
6656
+ currentDate <= endDateObj;
6657
+ currentDate.setDate(currentDate.getDate() + 1)
6658
+ ) {
6659
+ // Check if the current day is a weekend (Saturday or Sunday)
6660
+ const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
6661
+
6662
+ // Check if the current day is a holiday
6663
+ const isHoliday = holidays.some((holiday) => {
6664
+ const holidayDate = new Date(holiday);
6665
+ return currentDate.toDateString() === holidayDate.toDateString();
6666
+ });
6667
+
6668
+ // If it's a workday (not a weekend or holiday), increment the workdays count
6669
+ if (!isWeekend && !isHoliday) {
6670
+ workdays++;
6671
+ }
6672
+ }
6673
+
6674
+ return workdays;
6675
+ };
6676
+
6658
6677
  /**
6659
6678
  * 日期加减天数
6660
6679
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
6661
6680
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
6662
6681
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
6663
- */
6664
- var dateAddDays = function dateAddDays(start_date, days) {
6665
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6666
- 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.");
6667
- }
6668
-
6669
- var startDateObj = new Date(start_date);
6670
- if (isNaN(startDateObj.getTime())) {
6671
- throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6672
- }
6673
-
6674
- var resultDateObj = new Date(startDateObj);
6675
- resultDateObj.setDate(resultDateObj.getDate() + days);
6676
-
6677
- var resultYear = resultDateObj.getFullYear();
6678
- var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6679
- var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6680
-
6681
- return resultYear + '-' + resultMonth + '-' + resultDay;
6682
- };
6683
-
6682
+ */
6683
+ const dateAddDays = function (start_date, days) {
6684
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6685
+ throw new Error(
6686
+ "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
6687
+ );
6688
+ }
6689
+
6690
+ const startDateObj = new Date(start_date);
6691
+ if (isNaN(startDateObj.getTime())) {
6692
+ throw new Error(
6693
+ "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6694
+ );
6695
+ }
6696
+
6697
+ const resultDateObj = new Date(startDateObj);
6698
+ resultDateObj.setDate(resultDateObj.getDate() + days);
6699
+
6700
+ const resultYear = resultDateObj.getFullYear();
6701
+ const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6702
+ const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6703
+
6704
+ return `${resultYear}-${resultMonth}-${resultDay}`;
6705
+ };
6706
+
6684
6707
  /**
6685
6708
  * 计算两个日期之间的差值
6686
6709
  * @date 2023年12月14日
@@ -6688,180 +6711,182 @@ var dateAddDays = function dateAddDays(start_date, days) {
6688
6711
  * @param {String} end_date - 结束日期字符串
6689
6712
  * @param {String} unit - 单位:year/month/day
6690
6713
  * @returns {Number} 差值
6691
- */
6692
- var dateDiff = function dateDiff(start_date, end_date) {
6693
- var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
6694
-
6695
- // Assuming date strings are in "YYYY-MM-DD" format
6696
- var startDate = new Date(start_date);
6697
- var endDate = new Date(end_date);
6698
-
6699
- // If the date is invalid, return 0
6700
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6701
- return 0;
6702
- }
6703
-
6704
- if (unit === 'year') {
6705
- return endDate.getFullYear() - startDate.getFullYear();
6706
- } else if (unit === 'month') {
6707
- return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
6708
- } else {
6709
- // Default to day
6710
- var timeDifference = endDate - startDate;
6711
- // Calculate days (86400000 milliseconds per day)
6712
- return Math.floor(timeDifference / 86400000);
6713
- }
6714
- };
6715
-
6714
+ */
6715
+ const dateDiff = function (start_date, end_date, unit = 'day') {
6716
+ // Assuming date strings are in "YYYY-MM-DD" format
6717
+ var startDate = new Date(start_date);
6718
+ var endDate = new Date(end_date);
6719
+
6720
+ // If the date is invalid, return 0
6721
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6722
+ return 0;
6723
+ }
6724
+
6725
+ if (unit === 'year') {
6726
+ return endDate.getFullYear() - startDate.getFullYear();
6727
+ } else if (unit === 'month') {
6728
+ return (
6729
+ (endDate.getFullYear() - startDate.getFullYear()) * 12 +
6730
+ (endDate.getMonth() - startDate.getMonth())
6731
+ );
6732
+ } else {
6733
+ // Default to day
6734
+ var timeDifference = endDate - startDate;
6735
+ // Calculate days (86400000 milliseconds per day)
6736
+ return Math.floor(timeDifference / 86400000);
6737
+ }
6738
+ };
6739
+
6716
6740
  /**
6717
6741
  * 获取月份中的日期
6718
6742
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
6719
6743
  * @returns {number} 月份中的日期(1-31)
6720
- */
6721
- var dayOfMonth = function dayOfMonth(date) {
6722
- if (typeof date !== 'string') {
6723
- throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6724
- }
6725
-
6726
- var dateObj = new Date(date);
6727
- if (isNaN(dateObj.getTime())) {
6728
- throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6729
- }
6730
-
6731
- return dateObj.getDate();
6732
- };
6733
-
6744
+ */
6745
+ const dayOfMonth = function (date) {
6746
+ if (typeof date !== 'string') {
6747
+ throw new Error(
6748
+ "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
6749
+ );
6750
+ }
6751
+
6752
+ const dateObj = new Date(date);
6753
+ if (isNaN(dateObj.getTime())) {
6754
+ throw new Error(
6755
+ "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6756
+ );
6757
+ }
6758
+
6759
+ return dateObj.getDate();
6760
+ };
6761
+
6734
6762
  /**
6735
6763
  * 获取当前日期
6736
6764
  * @date 2022年5月7日
6737
6765
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
6738
6766
  * @returns {string} 当前日期的格式化字符串
6739
- */
6740
- var getCurrentDate = function getCurrentDate() {
6741
- var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
6742
-
6743
- return formatDate(new Date(), format);
6744
- };
6745
-
6767
+ */
6768
+ const getCurrentDate = function (format = 'YYYY-MM-DD') {
6769
+ return formatDate(new Date(), format);
6770
+ };
6771
+
6746
6772
  /**
6747
6773
  * 获取当前日期时间
6748
6774
  * @date 2022年5月7日
6749
6775
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
6750
6776
  * @returns {string} 当前日期时间的格式化字符串
6751
- */
6752
- var getCurrentDateTime = function getCurrentDateTime() {
6753
- var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
6754
-
6755
- return formatDate(new Date(), format);
6756
- };
6757
-
6777
+ */
6778
+ const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
6779
+ return formatDate(new Date(), format);
6780
+ };
6781
+
6758
6782
  /**
6759
6783
  * 获取小时
6760
6784
  * @date 2022年5月7日
6761
6785
  * @param {Date|string} [date] - 日期对象或日期字符串
6762
6786
  * @returns {number} 小时数(0-23)
6763
- */
6764
- var getHour = function getHour(date) {
6765
- if (!date) {
6766
- return new Date().getHours();
6767
- }
6768
- if (typeof date === 'string') {
6769
- date = new Date(date);
6770
- }
6771
- return date.getHours();
6772
- };
6773
-
6787
+ */
6788
+ const getHour = function (date) {
6789
+ if (!date) {
6790
+ return new Date().getHours();
6791
+ }
6792
+ if (typeof date === 'string') {
6793
+ date = new Date(date);
6794
+ }
6795
+ return date.getHours();
6796
+ };
6797
+
6774
6798
  /**
6775
6799
  * 获取分钟
6776
6800
  * @date 2022年5月7日
6777
6801
  * @param {Date|string} [date] - 日期对象或日期字符串
6778
6802
  * @returns {number} 分钟数(0-59)
6779
- */
6780
- var getMinute = function getMinute(date) {
6781
- if (!date) {
6782
- return new Date().getMinutes();
6783
- }
6784
- if (typeof date === 'string') {
6785
- date = new Date(date);
6786
- }
6787
- return date.getMinutes();
6788
- };
6789
-
6803
+ */
6804
+ const getMinute = function (date) {
6805
+ if (!date) {
6806
+ return new Date().getMinutes();
6807
+ }
6808
+ if (typeof date === 'string') {
6809
+ date = new Date(date);
6810
+ }
6811
+ return date.getMinutes();
6812
+ };
6813
+
6790
6814
  /**
6791
6815
  * 获取月份
6792
6816
  * @date 2022年5月7日
6793
6817
  * @param {Date|string} [date] - 日期对象或日期字符串
6794
6818
  * @returns {number} 月份数(1-12)
6795
- */
6796
- var getMonth = function getMonth(date) {
6797
- if (!date) {
6798
- return new Date().getMonth() + 1;
6799
- }
6800
- if (typeof date === 'string') {
6801
- date = new Date(date);
6802
- }
6803
- return date.getMonth() + 1;
6804
- };
6805
-
6819
+ */
6820
+ const getMonth = function (date) {
6821
+ if (!date) {
6822
+ return new Date().getMonth() + 1;
6823
+ }
6824
+ if (typeof date === 'string') {
6825
+ date = new Date(date);
6826
+ }
6827
+ return date.getMonth() + 1;
6828
+ };
6829
+
6806
6830
  /**
6807
6831
  * 获取秒
6808
6832
  * @date 2022年5月7日
6809
6833
  * @param {Date|string} [date] - 日期对象或日期字符串
6810
6834
  * @returns {number} 秒数(0-59)
6811
- */
6812
- var getSecond = function getSecond(date) {
6813
- if (!date) {
6814
- return new Date().getSeconds();
6815
- }
6816
- if (typeof date === 'string') {
6817
- date = new Date(date);
6818
- }
6819
- return date.getSeconds();
6820
- };
6821
-
6835
+ */
6836
+ const getSecond = function (date) {
6837
+ if (!date) {
6838
+ return new Date().getSeconds();
6839
+ }
6840
+ if (typeof date === 'string') {
6841
+ date = new Date(date);
6842
+ }
6843
+ return date.getSeconds();
6844
+ };
6845
+
6822
6846
  /**
6823
6847
  * 获取星期几
6824
6848
  * @date 2022年5月7日
6825
6849
  * @param {Date|string} [date] - 日期对象或日期字符串
6826
6850
  * @returns {number} 星期几(0-6,0表示星期日)
6827
- */
6828
- var getWeekday = function getWeekday(date) {
6829
- if (!date) {
6830
- return new Date().getDay();
6831
- }
6832
- if (typeof date === 'string') {
6833
- date = new Date(date);
6834
- }
6835
- return date.getDay();
6836
- };
6837
-
6851
+ */
6852
+ const getWeekday = function (date) {
6853
+ if (!date) {
6854
+ return new Date().getDay();
6855
+ }
6856
+ if (typeof date === 'string') {
6857
+ date = new Date(date);
6858
+ }
6859
+ return date.getDay();
6860
+ };
6861
+
6862
+
6838
6863
  /**
6839
6864
  * @desc 获取上午/下午/晚上
6840
6865
  * @author huangbo
6841
6866
  * @date 2022年5月7日
6842
6867
  * @param {String} [time] - 时间
6843
- **/
6844
- var timeCycle = function timeCycle(time) {
6845
- var hour = 0;
6846
- if (!time) {
6847
- hour = new Date().getHours();
6848
- } else if (typeof time === 'string') {
6849
- // 从时间字符串中提取小时
6850
- var match = time.match(/^(\d{1,2})/);
6851
- if (match) {
6852
- hour = parseInt(match[1], 10);
6853
- }
6854
- } else if (typeof time === 'number') {
6855
- hour = time;
6856
- }
6857
- // 判断时间段
6858
- if (hour >= 5 && hour < 12) {
6859
- return '上午';
6860
- } else if (hour >= 12 && hour < 18) {
6861
- return '下午';
6862
- } else {
6863
- return '晚上';
6864
- }
6868
+ **/
6869
+ const timeCycle = function (time) {
6870
+ let hour = 0;
6871
+ if (!time) {
6872
+ hour = new Date().getHours();
6873
+ } else if (typeof time === 'string') {
6874
+ // 从时间字符串中提取小时
6875
+ const match = time.match(/^(\d{1,2})/);
6876
+ if (match) {
6877
+ hour = parseInt(match[1], 10);
6878
+ }
6879
+ } else if (typeof time === 'number') {
6880
+ hour = time;
6881
+ }
6882
+ // 判断时间段
6883
+ if (hour >= 5 && hour < 12) {
6884
+ return '上午';
6885
+ } else if (hour >= 12 && hour < 18) {
6886
+ return '下午';
6887
+ } else {
6888
+ return '晚上';
6889
+ }
6865
6890
  };
6866
6891
 
6867
6892
  /***/ }),