eoss 0.1.0-alpha.39 → 0.1.0-alpha.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/lib/0.js +1 -1
  2. package/lib/1.js +1 -1
  3. package/lib/10.js +1 -1
  4. package/lib/11.js +1 -1
  5. package/lib/12.js +1 -1
  6. package/lib/13.js +1 -1
  7. package/lib/14.js +1 -1
  8. package/lib/15.js +1 -1
  9. package/lib/16.js +1 -1
  10. package/lib/17.js +1 -1
  11. package/lib/18.js +1 -1
  12. package/lib/19.js +1 -1
  13. package/lib/20.js +1 -1
  14. package/lib/21.js +1 -1
  15. package/lib/22.js +1 -1
  16. package/lib/23.js +1 -1
  17. package/lib/24.js +1 -1
  18. package/lib/25.js +1 -1
  19. package/lib/26.js +1 -1
  20. package/lib/27.js +1 -1
  21. package/lib/28.js +1 -1
  22. package/lib/29.js +1 -1
  23. package/lib/3.js +1 -1
  24. package/lib/30.js +1 -1
  25. package/lib/31.js +1 -1
  26. package/lib/32.js +1 -1
  27. package/lib/33.js +1 -1
  28. package/lib/34.js +1 -1
  29. package/lib/35.js +1 -1
  30. package/lib/36.js +1 -1
  31. package/lib/37.js +1 -1
  32. package/lib/38.js +1 -1
  33. package/lib/39.js +1 -1
  34. package/lib/4.js +1 -1
  35. package/lib/40.js +1 -1
  36. package/lib/41.js +1 -1
  37. package/lib/42.js +1 -1
  38. package/lib/43.js +1 -1
  39. package/lib/44.js +1 -1
  40. package/lib/45.js +1 -1
  41. package/lib/46.js +1 -1
  42. package/lib/47.js +1 -1
  43. package/lib/48.js +1 -1
  44. package/lib/49.js +1 -1
  45. package/lib/5.js +1 -1
  46. package/lib/50.js +1 -1
  47. package/lib/51.js +1 -1
  48. package/lib/52.js +1 -1
  49. package/lib/53.js +1 -1
  50. package/lib/54.js +1 -1
  51. package/lib/55.js +1 -1
  52. package/lib/56.js +1 -1
  53. package/lib/57.js +1 -1
  54. package/lib/58.js +1 -1
  55. package/lib/59.js +1 -1
  56. package/lib/6.js +1 -1
  57. package/lib/60.js +1 -1
  58. package/lib/61.js +1 -1
  59. package/lib/62.js +1 -1
  60. package/lib/63.js +1 -1
  61. package/lib/64.js +1 -1
  62. package/lib/65.js +1 -1
  63. package/lib/66.js +1 -1
  64. package/lib/67.js +1 -1
  65. package/lib/68.js +1 -1
  66. package/lib/69.js +1 -1
  67. package/lib/7.js +1 -1
  68. package/lib/70.js +1 -1
  69. package/lib/71.js +1 -1
  70. package/lib/72.js +1 -1
  71. package/lib/73.js +1 -1
  72. package/lib/74.js +1 -1
  73. package/lib/75.js +1 -1
  74. package/lib/76.js +1 -1
  75. package/lib/77.js +1 -1
  76. package/lib/78.js +1 -1
  77. package/lib/79.js +1 -1
  78. package/lib/8.js +1 -1
  79. package/lib/80.js +1 -1
  80. package/lib/81.js +1 -1
  81. package/lib/9.js +1 -1
  82. package/lib/account-login.js +837 -862
  83. package/lib/alert.js +2 -2
  84. package/lib/aside.js +2 -2
  85. package/lib/audit-trajectory.js +4 -4
  86. package/lib/autocomplete.js +1813 -1988
  87. package/lib/avatar.js +2 -2
  88. package/lib/backtop.js +2 -2
  89. package/lib/badge.js +2 -2
  90. package/lib/breadcrumb-item.js +4 -4
  91. package/lib/breadcrumb.js +4 -4
  92. package/lib/button-group.js +4 -4
  93. package/lib/button.js +2 -2
  94. package/lib/ca-login.js +837 -862
  95. package/lib/calendar.js +839 -864
  96. package/lib/card.js +2 -2
  97. package/lib/carousel-item.js +846 -871
  98. package/lib/carousel.js +839 -864
  99. package/lib/cascader-panel.js +852 -877
  100. package/lib/cascader.js +2048 -2223
  101. package/lib/checkbox-button.js +4 -4
  102. package/lib/checkbox-group.js +859 -884
  103. package/lib/checkbox.js +4 -4
  104. package/lib/col.js +2 -2
  105. package/lib/collapse-item.js +1040 -1065
  106. package/lib/collapse.js +1040 -1065
  107. package/lib/color-picker.js +972 -1122
  108. package/lib/container.js +2 -2
  109. package/lib/cron.js +12 -12
  110. package/lib/data-table.js +843 -868
  111. package/lib/date-picker.js +10520 -10695
  112. package/lib/descriptions-item.js +4 -4
  113. package/lib/descriptions.js +4 -4
  114. package/lib/dialog.js +837 -862
  115. package/lib/divider.js +2 -2
  116. package/lib/drawer.js +2 -2
  117. package/lib/dropdown-item.js +4 -4
  118. package/lib/dropdown-menu.js +974 -1124
  119. package/lib/dropdown.js +841 -866
  120. package/lib/email-login.js +837 -862
  121. package/lib/empty.js +2 -2
  122. package/lib/eoss.common.js +4023 -2668
  123. package/lib/flip.js +2 -2
  124. package/lib/flow-group.js +853 -878
  125. package/lib/flow.js +868 -893
  126. package/lib/flows.js +854 -879
  127. package/lib/footer.js +2 -2
  128. package/lib/form-item.js +860 -885
  129. package/lib/form.js +933 -950
  130. package/lib/guide.js +2 -2
  131. package/lib/header.js +2 -2
  132. package/lib/icon.js +837 -862
  133. package/lib/icons.js +2 -2
  134. package/lib/image-viewer.js +837 -862
  135. package/lib/image.js +4 -4
  136. package/lib/index.js +1 -1
  137. package/lib/infinite-scroll.js +2 -2
  138. package/lib/input-number.js +6 -6
  139. package/lib/input.js +839 -864
  140. package/lib/link.js +2 -2
  141. package/lib/loading.js +2 -2
  142. package/lib/login.js +867 -891
  143. package/lib/lowcode-view.js +1843 -1185
  144. package/lib/lowcode.js +3050 -1569
  145. package/lib/main.js +970 -988
  146. package/lib/marquee.js +837 -862
  147. package/lib/menu-item-group.js +15 -15
  148. package/lib/menu-item.js +6 -6
  149. package/lib/menu.js +2227 -2368
  150. package/lib/message-box.js +843 -868
  151. package/lib/message.js +839 -864
  152. package/lib/notification.js +861 -886
  153. package/lib/option-group.js +4 -4
  154. package/lib/option.js +839 -864
  155. package/lib/page-header.js +2 -2
  156. package/lib/pagination.js +839 -864
  157. package/lib/phone-login.js +847 -866
  158. package/lib/popconfirm.js +4 -4
  159. package/lib/popover.js +1831 -2006
  160. package/lib/process-config.js +839 -864
  161. package/lib/process-module.js +846 -871
  162. package/lib/process-rule.js +905 -930
  163. package/lib/progress.js +2 -2
  164. package/lib/qr-code.js +4 -4
  165. package/lib/qrcode-login.js +839 -864
  166. package/lib/radio-button.js +4 -4
  167. package/lib/radio-group.js +850 -875
  168. package/lib/radio.js +4 -4
  169. package/lib/rate.js +837 -862
  170. package/lib/retrial-auth.js +837 -862
  171. package/lib/row.js +2 -2
  172. package/lib/scrollbar.js +839 -864
  173. package/lib/select.js +2139 -2314
  174. package/lib/selector-panel.js +940 -965
  175. package/lib/selector.js +852 -877
  176. package/lib/slider.js +4 -4
  177. package/lib/step.js +32 -32
  178. package/lib/steps.js +874 -899
  179. package/lib/submenu.js +1269 -1385
  180. package/lib/switch.js +839 -864
  181. package/lib/tab-pane.js +4 -4
  182. package/lib/table-column.js +840 -865
  183. package/lib/table.js +1825 -2000
  184. package/lib/tabs.js +846 -871
  185. package/lib/tag.js +2 -2
  186. package/lib/theme-chalk/fonts/iconfont.ttf +0 -0
  187. package/lib/theme-chalk/fonts/iconfont.woff +0 -0
  188. package/lib/theme-chalk/index.css +1 -1
  189. package/lib/theme-chalk/lowcode.css +1 -1
  190. package/lib/time-picker.js +6471 -6646
  191. package/lib/time-select.js +5039 -5214
  192. package/lib/timeline-item.js +2 -2
  193. package/lib/timeline.js +2 -2
  194. package/lib/tips.js +837 -862
  195. package/lib/toolbar.js +4 -4
  196. package/lib/tooltip.js +1813 -1988
  197. package/lib/transfer.js +837 -862
  198. package/lib/tree-group.js +853 -878
  199. package/lib/tree.js +1026 -1051
  200. package/lib/update-history.js +4 -4
  201. package/lib/upload.js +859 -884
  202. package/lib/wujie.js +841 -866
  203. package/package.json +1 -1
  204. package/packages/flow-group/src/main.vue +2 -2
  205. package/packages/form/src/form-item-render.vue +1 -0
  206. package/packages/form/src/form-item.vue +12 -6
  207. package/packages/form/src/form.vue +5 -5
  208. package/packages/login/src/login.vue +1 -0
  209. package/packages/lowcode/src/attribute/function.vue +28 -9
  210. package/packages/lowcode/src/attribute/props.vue +202 -0
  211. package/packages/lowcode/src/attribute/styles.vue +79 -5
  212. package/packages/lowcode/src/attribute.vue +61 -4
  213. package/packages/lowcode/src/canvas.vue +159 -2
  214. package/packages/lowcode/src/form-render.vue +305 -0
  215. package/packages/lowcode/src/lowcode.vue +33 -13
  216. package/packages/lowcode/src/modules.vue +53 -37
  217. package/packages/lowcode/src/render.vue +80 -25
  218. package/packages/lowcode/src/util/components.js +100 -0
  219. package/packages/lowcode/src/util/props-util.js +67 -0
  220. package/packages/lowcode/src/util/source-generator.js +69 -9
  221. package/packages/lowcode/src/util/source-parser.js +64 -10
  222. package/packages/lowcode-view/src/render.vue +48 -18
  223. package/packages/main/src/components/userinfo.vue +0 -1
  224. package/packages/menu/src/menu-item-group.vue +1 -1
  225. package/packages/menu/src/mixins.js +8 -4
  226. package/packages/menu/src/submenu.vue +35 -5
  227. package/packages/phone-login/src/phone-login.vue +5 -2
  228. package/packages/theme-chalk/dist/fonts/iconfont.ttf +0 -0
  229. package/packages/theme-chalk/dist/fonts/iconfont.woff +0 -0
  230. package/packages/theme-chalk/src/fonts/iconfont.ttf +0 -0
  231. package/packages/theme-chalk/src/fonts/iconfont.woff +0 -0
  232. package/packages/theme-chalk/src/lowcode.scss +21 -2
  233. package/src/index.js +336 -336
@@ -82,7 +82,7 @@ module.exports =
82
82
  /******/
83
83
  /******/
84
84
  /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 250);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 257);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -4790,14 +4790,14 @@ module.exports = require("eoss/lib/form");
4790
4790
 
4791
4791
  /***/ }),
4792
4792
 
4793
- /***/ 250:
4793
+ /***/ 257:
4794
4794
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4795
4795
 
4796
4796
  "use strict";
4797
4797
  // ESM COMPAT FLAG
4798
4798
  __webpack_require__.r(__webpack_exports__);
4799
4799
 
4800
- // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/phone-login/src/phone-login.vue?vue&type=template&id=430868e6&
4800
+ // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/phone-login/src/phone-login.vue?vue&type=template&id=31014cfa&
4801
4801
  var render = function () {
4802
4802
  var _vm = this
4803
4803
  var _h = _vm.$createElement
@@ -4928,7 +4928,7 @@ var staticRenderFns = []
4928
4928
  render._withStripped = true
4929
4929
 
4930
4930
 
4931
- // CONCATENATED MODULE: ./packages/phone-login/src/phone-login.vue?vue&type=template&id=430868e6&
4931
+ // CONCATENATED MODULE: ./packages/phone-login/src/phone-login.vue?vue&type=template&id=31014cfa&
4932
4932
 
4933
4933
  // EXTERNAL MODULE: ./src/config/api.js
4934
4934
  var api = __webpack_require__(6);
@@ -4936,6 +4936,9 @@ var api = __webpack_require__(6);
4936
4936
  // EXTERNAL MODULE: ./src/utils/ajax.js
4937
4937
  var ajax = __webpack_require__(10);
4938
4938
 
4939
+ // EXTERNAL MODULE: ./src/utils/util.js
4940
+ var util = __webpack_require__(1);
4941
+
4939
4942
  // EXTERNAL MODULE: external "eoss/lib/button"
4940
4943
  var button_ = __webpack_require__(13);
4941
4944
  var button_default = /*#__PURE__*/__webpack_require__.n(button_);
@@ -5242,10 +5245,11 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
5242
5245
  handleSubmit: function handleSubmit() {
5243
5246
  var _this2 = this;
5244
5247
 
5248
+ console.log('18086814030', this.$refs.loginForm);
5245
5249
  this.$refs.loginForm && this.$refs.loginForm.validate().then(function () {
5246
5250
  _this2.submit = true;
5247
5251
  if (_this2.action) {
5248
- var loadingInstance = loading('登录中...');
5252
+ var loadingInstance = Object(util["K" /* loading */])('登录中...');
5249
5253
  Object(ajax["a" /* ajax */])({
5250
5254
  method: 'POST',
5251
5255
  url: _this2.action,
@@ -5269,7 +5273,9 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
5269
5273
  });
5270
5274
  }
5271
5275
  _this2.$emit('submit', _this2.formData);
5272
- }).catch(function () {});
5276
+ }).catch(function (e) {
5277
+ console.log('e', e);
5278
+ });
5273
5279
  },
5274
5280
 
5275
5281
  /**
@@ -6160,759 +6166,736 @@ var changeInTime = '/baseIssueRules/changeInTime';
6160
6166
  /* unused harmony export getSecond */
6161
6167
  /* unused harmony export getWeekday */
6162
6168
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
6163
- /* Modified from https://github.com/taylorhakes/fecha
6164
- *
6165
- * The MIT License (MIT)
6166
- *
6167
- * Copyright (c) 2015 Taylor Hakes
6168
- *
6169
- * Permission is hereby granted, free of charge, to any person obtaining a copy
6170
- * of this software and associated documentation files (the "Software"), to deal
6171
- * in the Software without restriction, including without limitation the rights
6172
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6173
- * copies of the Software, and to permit persons to whom the Software is
6174
- * furnished to do so, subject to the following conditions:
6175
- *
6176
- * The above copyright notice and this permission notice shall be included in all
6177
- * copies or substantial portions of the Software.
6178
- *
6179
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6180
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6181
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6182
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6183
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6184
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
6185
- * SOFTWARE.
6186
- */
6187
-
6188
- /*eslint-disable*/
6189
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
6190
-
6191
-
6169
+
6170
+
6192
6171
  /**
6193
6172
  * Parse or format dates
6194
6173
  * @class fecha
6195
- */
6196
- const fecha = {};
6197
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
6198
- const twoDigits = '\\d\\d?';
6199
- const threeDigits = '\\d{3}';
6200
- const fourDigits = '\\d{4}';
6201
- const word = '[^\\s]+';
6202
- const literal = /\[([^]*?)\]/gm;
6203
- const noop = function () {};
6204
-
6205
- function regexEscape(str) {
6206
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
6207
- }
6208
-
6209
- function shorten(arr, sLen) {
6210
- const newArr = [];
6211
- for (let i = 0, len = arr.length; i < len; i++) {
6212
- newArr.push(arr[i].substr(0, sLen));
6213
- }
6214
- return newArr;
6215
- }
6216
-
6217
- function monthUpdate() {
6218
- return function (d, v) {
6219
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
6220
- if (~index) {
6221
- d.month = index;
6222
- }
6223
- };
6224
- }
6225
-
6226
- function pad(val, len) {
6227
- val = String(val);
6228
- len = len || 2;
6229
- while (val.length < len) {
6230
- val = '0' + val;
6231
- }
6232
- return val;
6233
- }
6234
-
6235
- // 直接使用中文日期名称常量
6236
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
6237
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
6238
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
6239
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
6240
- const amPm = ['上午', '下午'];
6241
- const DoFn = function DoFn(D) {
6242
- return D + '日';
6243
- };
6244
-
6245
- const formatFlags = {
6246
- D: function(dateObj) {
6247
- return dateObj.getDay();
6248
- },
6249
- DD: function(dateObj) {
6250
- return pad(dateObj.getDay());
6251
- },
6252
- Do: function(dateObj) {
6253
- return DoFn(dateObj.getDate());
6254
- },
6255
- d: function(dateObj) {
6256
- return dateObj.getDate();
6257
- },
6258
- dd: function(dateObj) {
6259
- return pad(dateObj.getDate());
6260
- },
6261
- ddd: function(dateObj) {
6262
- return dayNamesShort[dateObj.getDay()];
6263
- },
6264
- dddd: function(dateObj) {
6265
- return dayNames[dateObj.getDay()];
6266
- },
6267
- M: function(dateObj) {
6268
- return dateObj.getMonth() + 1;
6269
- },
6270
- MM: function(dateObj) {
6271
- return pad(dateObj.getMonth() + 1);
6272
- },
6273
- MMM: function(dateObj) {
6274
- return monthNamesShort[dateObj.getMonth()];
6275
- },
6276
- MMMM: function(dateObj) {
6277
- return monthNames[dateObj.getMonth()];
6278
- },
6279
- yy: function(dateObj) {
6280
- return pad(String(dateObj.getFullYear()), 4).substr(2);
6281
- },
6282
- yyyy: function(dateObj) {
6283
- return pad(dateObj.getFullYear(), 4);
6284
- },
6285
- h: function(dateObj) {
6286
- return dateObj.getHours() % 12 || 12;
6287
- },
6288
- hh: function(dateObj) {
6289
- return pad(dateObj.getHours() % 12 || 12);
6290
- },
6291
- H: function(dateObj) {
6292
- return dateObj.getHours();
6293
- },
6294
- HH: function(dateObj) {
6295
- return pad(dateObj.getHours());
6296
- },
6297
- m: function(dateObj) {
6298
- return dateObj.getMinutes();
6299
- },
6300
- mm: function(dateObj) {
6301
- return pad(dateObj.getMinutes());
6302
- },
6303
- s: function(dateObj) {
6304
- return dateObj.getSeconds();
6305
- },
6306
- ss: function(dateObj) {
6307
- return pad(dateObj.getSeconds());
6308
- },
6309
- S: function(dateObj) {
6310
- return Math.round(dateObj.getMilliseconds() / 100);
6311
- },
6312
- SS: function(dateObj) {
6313
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
6314
- },
6315
- SSS: function(dateObj) {
6316
- return pad(dateObj.getMilliseconds(), 3);
6317
- },
6318
- a: function(dateObj) {
6319
- return dateObj.getHours() < 12 ? '上午' : '下午';
6320
- },
6321
- A: function(dateObj) {
6322
- return dateObj.getHours() < 12 ? '上午' : '下午';
6323
- },
6324
- ZZ: function(dateObj) {
6325
- const o = dateObj.getTimezoneOffset();
6326
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
6327
- }
6328
- };
6329
-
6330
- const parseFlags = {
6331
- d: [twoDigits, function (d, v) {
6332
- d.day = v;
6333
- }],
6334
- Do: [twoDigits + word, function (d, v) {
6335
- d.day = parseInt(v, 10);
6336
- }],
6337
- M: [twoDigits, function (d, v) {
6338
- d.month = v - 1;
6339
- }],
6340
- yy: [twoDigits, function (d, v) {
6341
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
6342
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
6343
- }],
6344
- h: [twoDigits, function (d, v) {
6345
- d.hour = v;
6346
- }],
6347
- m: [twoDigits, function (d, v) {
6348
- d.minute = v;
6349
- }],
6350
- s: [twoDigits, function (d, v) {
6351
- d.second = v;
6352
- }],
6353
- yyyy: [fourDigits, function (d, v) {
6354
- d.year = v;
6355
- }],
6356
- S: ['\\d', function (d, v) {
6357
- d.millisecond = v * 100;
6358
- }],
6359
- SS: ['\\d{2}', function (d, v) {
6360
- d.millisecond = v * 10;
6361
- }],
6362
- SSS: [threeDigits, function (d, v) {
6363
- d.millisecond = v;
6364
- }],
6365
- D: [twoDigits, noop],
6366
- ddd: [word, noop],
6367
- MMM: [word, monthUpdate('monthNamesShort')],
6368
- MMMM: [word, monthUpdate('monthNames')],
6369
- a: [word, function (d, v) {
6370
- const val = v.toLowerCase();
6371
- if (val === '上午') {
6372
- d.isPm = false;
6373
- } else if (val === '下午') {
6374
- d.isPm = true;
6375
- }
6376
- }],
6377
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
6378
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
6379
-
6380
- if (parts) {
6381
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
6382
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
6383
- }
6384
- }]
6385
- };
6386
- parseFlags.dd = parseFlags.d;
6387
- parseFlags.dddd = parseFlags.ddd;
6388
- parseFlags.DD = parseFlags.D;
6389
- parseFlags.mm = parseFlags.m;
6390
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
6391
- parseFlags.MM = parseFlags.M;
6392
- parseFlags.ss = parseFlags.s;
6393
- parseFlags.A = parseFlags.a;
6394
-
6395
-
6396
- // Some common format strings
6397
- fecha.masks = {
6398
- default: 'ddd MMM dd yyyy HH:mm:ss',
6399
- shortDate: 'M/D/yy',
6400
- mediumDate: 'MMM d, yyyy',
6401
- longDate: 'MMMM d, yyyy',
6402
- fullDate: 'dddd, MMMM d, yyyy',
6403
- shortTime: 'HH:mm',
6404
- mediumTime: 'HH:mm:ss',
6405
- longTime: 'HH:mm:ss.SSS'
6406
- };
6407
-
6174
+ */
6175
+ var fecha = {};
6176
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
6177
+ var twoDigits = '\\d\\d?';
6178
+ var threeDigits = '\\d{3}';
6179
+ var fourDigits = '\\d{4}';
6180
+ var word = '[^\\s]+';
6181
+ var literal = /\[([^]*?)\]/gm;
6182
+ var noop = function noop() {};
6183
+
6184
+ function regexEscape(str) {
6185
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
6186
+ }
6187
+
6188
+ function shorten(arr, sLen) {
6189
+ var newArr = [];
6190
+ for (var i = 0, len = arr.length; i < len; i++) {
6191
+ newArr.push(arr[i].substr(0, sLen));
6192
+ }
6193
+ return newArr;
6194
+ }
6195
+
6196
+ function monthUpdate() {
6197
+ return function (d, v) {
6198
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
6199
+ if (~index) {
6200
+ d.month = index;
6201
+ }
6202
+ };
6203
+ }
6204
+
6205
+ function pad(val, len) {
6206
+ val = String(val);
6207
+ len = len || 2;
6208
+ while (val.length < len) {
6209
+ val = '0' + val;
6210
+ }
6211
+ return val;
6212
+ }
6213
+
6214
+ // 直接使用中文日期名称常量
6215
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
6216
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
6217
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
6218
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
6219
+ var amPm = ['上午', '下午'];
6220
+ var DoFn = function DoFn(D) {
6221
+ return D + '日';
6222
+ };
6223
+
6224
+ var formatFlags = {
6225
+ D: function D(dateObj) {
6226
+ return dateObj.getDay();
6227
+ },
6228
+ DD: function DD(dateObj) {
6229
+ return pad(dateObj.getDay());
6230
+ },
6231
+ Do: function Do(dateObj) {
6232
+ return DoFn(dateObj.getDate());
6233
+ },
6234
+ d: function d(dateObj) {
6235
+ return dateObj.getDate();
6236
+ },
6237
+ dd: function dd(dateObj) {
6238
+ return pad(dateObj.getDate());
6239
+ },
6240
+ ddd: function ddd(dateObj) {
6241
+ return dayNamesShort[dateObj.getDay()];
6242
+ },
6243
+ dddd: function dddd(dateObj) {
6244
+ return dayNames[dateObj.getDay()];
6245
+ },
6246
+ M: function M(dateObj) {
6247
+ return dateObj.getMonth() + 1;
6248
+ },
6249
+ MM: function MM(dateObj) {
6250
+ return pad(dateObj.getMonth() + 1);
6251
+ },
6252
+ MMM: function MMM(dateObj) {
6253
+ return monthNamesShort[dateObj.getMonth()];
6254
+ },
6255
+ MMMM: function MMMM(dateObj) {
6256
+ return monthNames[dateObj.getMonth()];
6257
+ },
6258
+ yy: function yy(dateObj) {
6259
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
6260
+ },
6261
+ yyyy: function yyyy(dateObj) {
6262
+ return pad(dateObj.getFullYear(), 4);
6263
+ },
6264
+ h: function h(dateObj) {
6265
+ return dateObj.getHours() % 12 || 12;
6266
+ },
6267
+ hh: function hh(dateObj) {
6268
+ return pad(dateObj.getHours() % 12 || 12);
6269
+ },
6270
+ H: function H(dateObj) {
6271
+ return dateObj.getHours();
6272
+ },
6273
+ HH: function HH(dateObj) {
6274
+ return pad(dateObj.getHours());
6275
+ },
6276
+ m: function m(dateObj) {
6277
+ return dateObj.getMinutes();
6278
+ },
6279
+ mm: function mm(dateObj) {
6280
+ return pad(dateObj.getMinutes());
6281
+ },
6282
+ s: function s(dateObj) {
6283
+ return dateObj.getSeconds();
6284
+ },
6285
+ ss: function ss(dateObj) {
6286
+ return pad(dateObj.getSeconds());
6287
+ },
6288
+ S: function S(dateObj) {
6289
+ return Math.round(dateObj.getMilliseconds() / 100);
6290
+ },
6291
+ SS: function SS(dateObj) {
6292
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
6293
+ },
6294
+ SSS: function SSS(dateObj) {
6295
+ return pad(dateObj.getMilliseconds(), 3);
6296
+ },
6297
+ a: function a(dateObj) {
6298
+ return dateObj.getHours() < 12 ? '上午' : '下午';
6299
+ },
6300
+ A: function A(dateObj) {
6301
+ return dateObj.getHours() < 12 ? '上午' : '下午';
6302
+ },
6303
+ ZZ: function ZZ(dateObj) {
6304
+ var o = dateObj.getTimezoneOffset();
6305
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
6306
+ }
6307
+ };
6308
+
6309
+ var parseFlags = {
6310
+ d: [twoDigits, function (d, v) {
6311
+ d.day = v;
6312
+ }],
6313
+ Do: [twoDigits + word, function (d, v) {
6314
+ d.day = parseInt(v, 10);
6315
+ }],
6316
+ M: [twoDigits, function (d, v) {
6317
+ d.month = v - 1;
6318
+ }],
6319
+ yy: [twoDigits, function (d, v) {
6320
+ var da = new Date(),
6321
+ cent = +('' + da.getFullYear()).substr(0, 2);
6322
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
6323
+ }],
6324
+ h: [twoDigits, function (d, v) {
6325
+ d.hour = v;
6326
+ }],
6327
+ m: [twoDigits, function (d, v) {
6328
+ d.minute = v;
6329
+ }],
6330
+ s: [twoDigits, function (d, v) {
6331
+ d.second = v;
6332
+ }],
6333
+ yyyy: [fourDigits, function (d, v) {
6334
+ d.year = v;
6335
+ }],
6336
+ S: ['\\d', function (d, v) {
6337
+ d.millisecond = v * 100;
6338
+ }],
6339
+ SS: ['\\d{2}', function (d, v) {
6340
+ d.millisecond = v * 10;
6341
+ }],
6342
+ SSS: [threeDigits, function (d, v) {
6343
+ d.millisecond = v;
6344
+ }],
6345
+ D: [twoDigits, noop],
6346
+ ddd: [word, noop],
6347
+ MMM: [word, monthUpdate('monthNamesShort')],
6348
+ MMMM: [word, monthUpdate('monthNames')],
6349
+ a: [word, function (d, v) {
6350
+ var val = v.toLowerCase();
6351
+ if (val === '上午') {
6352
+ d.isPm = false;
6353
+ } else if (val === '下午') {
6354
+ d.isPm = true;
6355
+ }
6356
+ }],
6357
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
6358
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
6359
+ minutes = void 0;
6360
+
6361
+ if (parts) {
6362
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
6363
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
6364
+ }
6365
+ }]
6366
+ };
6367
+ parseFlags.dd = parseFlags.d;
6368
+ parseFlags.dddd = parseFlags.ddd;
6369
+ parseFlags.DD = parseFlags.D;
6370
+ parseFlags.mm = parseFlags.m;
6371
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
6372
+ parseFlags.MM = parseFlags.M;
6373
+ parseFlags.ss = parseFlags.s;
6374
+ parseFlags.A = parseFlags.a;
6375
+
6376
+ // Some common format strings
6377
+ fecha.masks = {
6378
+ default: 'ddd MMM dd yyyy HH:mm:ss',
6379
+ shortDate: 'M/D/yy',
6380
+ mediumDate: 'MMM d, yyyy',
6381
+ longDate: 'MMMM d, yyyy',
6382
+ fullDate: 'dddd, MMMM d, yyyy',
6383
+ shortTime: 'HH:mm',
6384
+ mediumTime: 'HH:mm:ss',
6385
+ longTime: 'HH:mm:ss.SSS'
6386
+ };
6387
+
6408
6388
  /***
6409
6389
  * Format a date
6410
6390
  * @method format
6411
6391
  * @param {Date|number} dateObj
6412
6392
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
6413
- */
6414
- fecha.format = function (dateObj, mask) {
6415
- if (typeof dateObj === 'number') {
6416
- dateObj = new Date(dateObj);
6417
- }
6418
-
6419
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
6420
- throw new Error('Invalid Date in fecha.format');
6421
- }
6422
-
6423
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
6424
-
6425
- const literals = [];
6426
-
6427
- // Make literals inactive by replacing them with ??
6428
- mask = mask.replace(literal, function($0, $1) {
6429
- literals.push($1);
6430
- return '@@@';
6431
- });
6432
- // Apply formatting rules
6433
- mask = mask.replace(token, function ($0) {
6434
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
6435
- });
6436
- // Inline literal values back into the formatted value
6437
- return mask.replace(/@@@/g, function() {
6438
- return literals.shift();
6439
- });
6440
- };
6441
-
6393
+ */
6394
+ fecha.format = function (dateObj, mask) {
6395
+ if (typeof dateObj === 'number') {
6396
+ dateObj = new Date(dateObj);
6397
+ }
6398
+
6399
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
6400
+ throw new Error('Invalid Date in fecha.format');
6401
+ }
6402
+
6403
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
6404
+
6405
+ var literals = [];
6406
+
6407
+ // Make literals inactive by replacing them with ??
6408
+ mask = mask.replace(literal, function ($0, $1) {
6409
+ literals.push($1);
6410
+ return '@@@';
6411
+ });
6412
+ // Apply formatting rules
6413
+ mask = mask.replace(token, function ($0) {
6414
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
6415
+ });
6416
+ // Inline literal values back into the formatted value
6417
+ return mask.replace(/@@@/g, function () {
6418
+ return literals.shift();
6419
+ });
6420
+ };
6421
+
6442
6422
  /**
6443
6423
  * Parse a date string into an object, changes - into /
6444
6424
  * @method parse
6445
6425
  * @param {string} dateStr Date string
6446
6426
  * @param {string} format Date parse format
6447
6427
  * @returns {Date|boolean}
6448
- */
6449
- fecha.parse = function (dateStr, format) {
6450
- if (typeof format !== 'string') {
6451
- throw new Error('Invalid format in fecha.parse');
6452
- }
6453
-
6454
- format = fecha.masks[format] || format;
6455
-
6456
- // Avoid regular expression denial of service, fail early for really long strings
6457
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
6458
- if (dateStr.length > 1000) {
6459
- return null;
6460
- }
6461
-
6462
- const dateInfo = {};
6463
- const parseInfo = [];
6464
- const literals = [];
6465
- format = format.replace(literal, function($0, $1) {
6466
- literals.push($1);
6467
- return '@@@';
6468
- });
6469
- let newFormat = regexEscape(format).replace(token, function ($0) {
6470
- if (parseFlags[$0]) {
6471
- const info = parseFlags[$0];
6472
- parseInfo.push(info[1]);
6473
- return '(' + info[0] + ')';
6474
- }
6475
-
6476
- return $0;
6477
- });
6478
- newFormat = newFormat.replace(/@@@/g, function() {
6479
- return literals.shift();
6480
- });
6481
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
6482
- if (!matches) {
6483
- return null;
6484
- }
6485
-
6486
- for (let i = 1; i < matches.length; i++) {
6487
- parseInfo[i - 1](dateInfo, matches[i]);
6488
- }
6489
-
6490
- const today = new Date();
6491
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
6492
- dateInfo.hour = +dateInfo.hour + 12;
6493
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
6494
- dateInfo.hour = 0;
6495
- }
6496
-
6497
- let date;
6498
- if (dateInfo.timezoneOffset != null) {
6499
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
6500
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
6501
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
6502
- } else {
6503
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
6504
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
6505
- }
6506
- return date;
6507
- };
6508
-
6509
- // 导出fecha对象
6510
-
6511
-
6512
- // 以下是从date-util.js合并的函数
6513
- const newArray = function(start, end) {
6514
- let result = [];
6515
- for (let i = start; i <= end; i++) {
6516
- result.push(i);
6517
- }
6518
- return result;
6519
- };
6520
-
6521
- const getSettings = () => {
6522
- return {
6523
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
6524
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
6525
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
6526
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
6527
- amPm: ['上午', '下午']
6528
- };
6529
- };
6530
-
6531
- const toDate = function(date) {
6532
- return isDate(date) ? new Date(date) : null;
6533
- };
6534
-
6535
- const isDate = function(date) {
6536
- if (date === null || date === undefined) return false;
6537
- if (isNaN(new Date(date).getTime())) return false;
6538
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
6539
- return true;
6540
- };
6541
-
6542
- const isDateObject = function(val) {
6543
- return val instanceof Date;
6544
- };
6545
-
6546
- const formatDate = function (date, format = 'yyyy-MM-dd') {
6547
- // 处理多种输入类型
6548
- if (!date) return '';
6549
-
6550
- // 如果是时间戳,转成日期对象
6551
- if (typeof date === 'number') {
6552
- date = new Date(date);
6553
- }
6554
- // 如果是字符串,转成日期对象
6555
- if (typeof date === 'string') {
6556
- date = new Date(date);
6557
- }
6558
-
6559
- // 调用toDate进一步验证和转换
6560
- date = toDate(date);
6561
- if (!date) return '';
6562
-
6563
- // 兼容大写和小写的格式标记
6564
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
6565
- const lowercaseFormat = format
6566
- .replace(/YYYY/g, 'yyyy')
6567
- .replace(/D/g, 'd')
6568
-
6569
- // 使用fecha库进行格式化,支持中文配置
6570
- const str = fecha.format(date, lowercaseFormat, getSettings());
6571
- return str;
6572
- };
6573
-
6574
- const parseDate = function(string, format) {
6575
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
6576
- };
6577
-
6578
- const getDayCountOfMonth = function(year, month) {
6579
- if (month === 3 || month === 5 || month === 8 || month === 10) {
6580
- return 30;
6581
- }
6582
-
6583
- if (month === 1) {
6584
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
6585
- return 29;
6586
- } else {
6587
- return 28;
6588
- }
6589
- }
6590
-
6591
- return 31;
6592
- };
6593
-
6594
- const getDayCountOfYear = function(year) {
6595
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
6596
- return isLeapYear ? 366 : 365;
6597
- };
6598
-
6599
- const getFirstDayOfMonth = function(date) {
6600
- const temp = new Date(date.getTime());
6601
- temp.setDate(1);
6602
- return temp.getDay();
6603
- };
6604
-
6605
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
6606
- // {prev, next} Date should work for Daylight Saving Time
6607
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
6608
- const prevDate = function(date, amount = 1) {
6609
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
6610
- };
6611
-
6612
- const nextDate = function(date, amount = 1) {
6613
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
6614
- };
6615
-
6616
- const getStartDateOfMonth = function(year, month) {
6617
- const result = new Date(year, month, 1);
6618
- const day = result.getDay();
6619
-
6620
- if (day === 0) {
6621
- return prevDate(result, 7);
6622
- } else {
6623
- return prevDate(result, day);
6624
- }
6625
- };
6626
-
6627
- const getWeekNumber = function(date) {
6628
- // 支持多种输入类型
6629
- if (!date||!isDate(date)) {
6630
- date = new Date();
6631
- }
6632
- if (typeof date === 'string') {
6633
- date = new Date(date);
6634
- }
6635
-
6636
- // 验证日期有效性
6637
- if (!isDate(date)) return null;
6638
-
6639
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
6640
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
6641
- // 将星期日的星期数设为7
6642
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
6643
- // 获取当年的第一天
6644
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
6645
- // 计算到最近的星期四的完整周数
6646
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
6647
- // 返回周数
6648
- return weekNo;
6649
- };
6650
-
6651
- const getRangeHours = function(ranges) {
6652
- const hours = [];
6653
- let disabledHours = [];
6654
-
6655
- (ranges || []).forEach(range => {
6656
- const value = range.map(date => date.getHours());
6657
-
6658
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
6659
- });
6660
-
6661
- if (disabledHours.length) {
6662
- for (let i = 0; i < 24; i++) {
6663
- hours[i] = disabledHours.indexOf(i) === -1;
6664
- }
6665
- } else {
6666
- for (let i = 0; i < 24; i++) {
6667
- hours[i] = false;
6668
- }
6669
- }
6670
-
6671
- return hours;
6672
- };
6673
-
6674
- const getPrevMonthLastDays = (date, amount) => {
6675
- if (amount <= 0) return [];
6676
- const temp = new Date(date.getTime());
6677
- temp.setDate(0);
6678
- const lastDay = temp.getDate();
6679
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
6680
- };
6681
-
6682
- const getMonthDays = (date) => {
6683
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
6684
- const days = temp.getDate();
6685
- return range(days).map((_, index) => index + 1);
6686
- };
6687
-
6688
- function setRangeData(arr, start, end, value) {
6689
- for (let i = start; i < end; i++) {
6690
- arr[i] = value;
6691
- }
6692
- }
6693
-
6694
- const getRangeMinutes = function(ranges, hour) {
6695
- const minutes = new Array(60);
6696
-
6697
- if (ranges.length > 0) {
6698
- ranges.forEach(range => {
6699
- const start = range[0];
6700
- const end = range[1];
6701
- const startHour = start.getHours();
6702
- const startMinute = start.getMinutes();
6703
- const endHour = end.getHours();
6704
- const endMinute = end.getMinutes();
6705
- if (startHour === hour && endHour !== hour) {
6706
- setRangeData(minutes, startMinute, 60, true);
6707
- } else if (startHour === hour && endHour === hour) {
6708
- setRangeData(minutes, startMinute, endMinute + 1, true);
6709
- } else if (startHour !== hour && endHour === hour) {
6710
- setRangeData(minutes, 0, endMinute + 1, true);
6711
- } else if (startHour < hour && endHour > hour) {
6712
- setRangeData(minutes, 0, 60, true);
6713
- }
6714
- });
6715
- } else {
6716
- setRangeData(minutes, 0, 60, true);
6717
- }
6718
- return minutes;
6719
- };
6720
-
6721
- const range = function(n) {
6722
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
6723
- return Array.apply(null, {length: n}).map((_, n) => n);
6724
- };
6725
-
6726
- const modifyDate = function(date, y, m, d) {
6727
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
6728
- };
6729
-
6730
- const modifyTime = function(date, h, m, s) {
6731
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
6732
- };
6733
-
6734
- const modifyWithTimeString = (date, time) => {
6735
- if (date == null || !time) {
6736
- return date;
6737
- }
6738
- time = parseDate(time, 'HH:mm:ss');
6739
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
6740
- };
6741
-
6742
- const clearTime = function(date) {
6743
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
6744
- };
6745
-
6746
- const clearMilliseconds = function(date) {
6747
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
6748
- };
6749
-
6750
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
6751
- // TODO: refactory a more elegant solution
6752
- if (ranges.length === 0) return date;
6753
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
6754
- const ndate = normalizeDate(date);
6755
- const nranges = ranges.map(range => range.map(normalizeDate));
6756
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
6757
-
6758
- let minDate = nranges[0][0];
6759
- let maxDate = nranges[0][0];
6760
-
6761
- nranges.forEach(nrange => {
6762
- minDate = new Date(Math.min(nrange[0], minDate));
6763
- maxDate = new Date(Math.max(nrange[1], minDate));
6764
- });
6765
-
6766
- const ret = ndate < minDate ? minDate : maxDate;
6767
- // preserve Year/Month/Date
6768
- return modifyDate(
6769
- ret,
6770
- date.getFullYear(),
6771
- date.getMonth(),
6772
- date.getDate()
6773
- );
6774
- };
6775
-
6776
- const timeWithinRange = function(date, selectableRange, format) {
6777
- const limitedDate = limitTimeRange(date, selectableRange, format);
6778
- return limitedDate.getTime() === date.getTime();
6779
- };
6780
-
6781
- const changeYearMonthAndClampDate = function(date, year, month) {
6782
- // clamp date to the number of days in `year`, `month`
6783
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
6784
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
6785
- return modifyDate(date, year, month, monthDate);
6786
- };
6787
-
6788
- const prevMonth = function(date) {
6789
- const year = date.getFullYear();
6790
- const month = date.getMonth();
6791
- return month === 0
6792
- ? changeYearMonthAndClampDate(date, year - 1, 11)
6793
- : changeYearMonthAndClampDate(date, year, month - 1);
6794
- };
6795
-
6796
- const nextMonth = function(date) {
6797
- const year = date.getFullYear();
6798
- const month = date.getMonth();
6799
- return month === 11
6800
- ? changeYearMonthAndClampDate(date, year + 1, 0)
6801
- : changeYearMonthAndClampDate(date, year, month + 1);
6802
- };
6803
-
6804
- const prevYear = function(date, amount = 1) {
6805
- const year = date.getFullYear();
6806
- const month = date.getMonth();
6807
- return changeYearMonthAndClampDate(date, year - amount, month);
6808
- };
6809
-
6810
- const nextYear = function(date, amount = 1) {
6811
- const year = date.getFullYear();
6812
- const month = date.getMonth();
6813
- return changeYearMonthAndClampDate(date, year + amount, month);
6814
- };
6815
-
6816
- const extractDateFormat = function(format) {
6817
- return format
6818
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
6819
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
6820
- .trim();
6821
- };
6822
-
6823
- const extractTimeFormat = function(format) {
6824
- return format
6825
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
6826
- .trim();
6827
- };
6828
-
6829
- const validateRangeInOneMonth = function(start, end) {
6830
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
6831
- };
6832
-
6428
+ */
6429
+ fecha.parse = function (dateStr, format) {
6430
+ if (typeof format !== 'string') {
6431
+ throw new Error('Invalid format in fecha.parse');
6432
+ }
6433
+
6434
+ format = fecha.masks[format] || format;
6435
+
6436
+ // Avoid regular expression denial of service, fail early for really long strings
6437
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
6438
+ if (dateStr.length > 1000) {
6439
+ return null;
6440
+ }
6441
+
6442
+ var dateInfo = {};
6443
+ var parseInfo = [];
6444
+ var literals = [];
6445
+ format = format.replace(literal, function ($0, $1) {
6446
+ literals.push($1);
6447
+ return '@@@';
6448
+ });
6449
+ var newFormat = regexEscape(format).replace(token, function ($0) {
6450
+ if (parseFlags[$0]) {
6451
+ var info = parseFlags[$0];
6452
+ parseInfo.push(info[1]);
6453
+ return '(' + info[0] + ')';
6454
+ }
6455
+
6456
+ return $0;
6457
+ });
6458
+ newFormat = newFormat.replace(/@@@/g, function () {
6459
+ return literals.shift();
6460
+ });
6461
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
6462
+ if (!matches) {
6463
+ return null;
6464
+ }
6465
+
6466
+ for (var i = 1; i < matches.length; i++) {
6467
+ parseInfo[i - 1](dateInfo, matches[i]);
6468
+ }
6469
+
6470
+ var today = new Date();
6471
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
6472
+ dateInfo.hour = +dateInfo.hour + 12;
6473
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
6474
+ dateInfo.hour = 0;
6475
+ }
6476
+
6477
+ var date = void 0;
6478
+ if (dateInfo.timezoneOffset != null) {
6479
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
6480
+ 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));
6481
+ } else {
6482
+ 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);
6483
+ }
6484
+ return date;
6485
+ };
6486
+
6487
+ // 导出fecha对象
6488
+
6489
+
6490
+ // 以下是从date-util.js合并的函数
6491
+ var newArray = function newArray(start, end) {
6492
+ var result = [];
6493
+ for (var i = start; i <= end; i++) {
6494
+ result.push(i);
6495
+ }
6496
+ return result;
6497
+ };
6498
+
6499
+ var getSettings = function getSettings() {
6500
+ return {
6501
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
6502
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
6503
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
6504
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
6505
+ amPm: ['上午', '下午']
6506
+ };
6507
+ };
6508
+
6509
+ var toDate = function toDate(date) {
6510
+ return isDate(date) ? new Date(date) : null;
6511
+ };
6512
+
6513
+ var isDate = function isDate(date) {
6514
+ if (date === null || date === undefined) return false;
6515
+ if (isNaN(new Date(date).getTime())) return false;
6516
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
6517
+ return true;
6518
+ };
6519
+
6520
+ var isDateObject = function isDateObject(val) {
6521
+ return val instanceof Date;
6522
+ };
6523
+
6524
+ var formatDate = function formatDate(date) {
6525
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
6526
+
6527
+ // 处理多种输入类型
6528
+ if (!date) return '';
6529
+
6530
+ // 如果是时间戳,转成日期对象
6531
+ if (typeof date === 'number') {
6532
+ date = new Date(date);
6533
+ }
6534
+ // 如果是字符串,转成日期对象
6535
+ if (typeof date === 'string') {
6536
+ date = new Date(date);
6537
+ }
6538
+
6539
+ // 调用toDate进一步验证和转换
6540
+ date = toDate(date);
6541
+ if (!date) return '';
6542
+
6543
+ // 兼容大写和小写的格式标记
6544
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
6545
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
6546
+
6547
+ // 使用fecha库进行格式化,支持中文配置
6548
+ var str = fecha.format(date, lowercaseFormat, getSettings());
6549
+ return str;
6550
+ };
6551
+
6552
+ var parseDate = function parseDate(string, format) {
6553
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
6554
+ };
6555
+
6556
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
6557
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
6558
+ return 30;
6559
+ }
6560
+
6561
+ if (month === 1) {
6562
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
6563
+ return 29;
6564
+ } else {
6565
+ return 28;
6566
+ }
6567
+ }
6568
+
6569
+ return 31;
6570
+ };
6571
+
6572
+ var getDayCountOfYear = function getDayCountOfYear(year) {
6573
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
6574
+ return isLeapYear ? 366 : 365;
6575
+ };
6576
+
6577
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
6578
+ var temp = new Date(date.getTime());
6579
+ temp.setDate(1);
6580
+ return temp.getDay();
6581
+ };
6582
+
6583
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
6584
+ // {prev, next} Date should work for Daylight Saving Time
6585
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
6586
+ var prevDate = function prevDate(date) {
6587
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6588
+
6589
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
6590
+ };
6591
+
6592
+ var nextDate = function nextDate(date) {
6593
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6594
+
6595
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
6596
+ };
6597
+
6598
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
6599
+ var result = new Date(year, month, 1);
6600
+ var day = result.getDay();
6601
+
6602
+ if (day === 0) {
6603
+ return prevDate(result, 7);
6604
+ } else {
6605
+ return prevDate(result, day);
6606
+ }
6607
+ };
6608
+
6609
+ var getWeekNumber = function getWeekNumber(date) {
6610
+ // 支持多种输入类型
6611
+ if (!date || !isDate(date)) {
6612
+ date = new Date();
6613
+ }
6614
+ if (typeof date === 'string') {
6615
+ date = new Date(date);
6616
+ }
6617
+
6618
+ // 验证日期有效性
6619
+ if (!isDate(date)) return null;
6620
+
6621
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
6622
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
6623
+ // 将星期日的星期数设为7
6624
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
6625
+ // 获取当年的第一天
6626
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
6627
+ // 计算到最近的星期四的完整周数
6628
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
6629
+ // 返回周数
6630
+ return weekNo;
6631
+ };
6632
+
6633
+ var getRangeHours = function getRangeHours(ranges) {
6634
+ var hours = [];
6635
+ var disabledHours = [];
6636
+
6637
+ (ranges || []).forEach(function (range) {
6638
+ var value = range.map(function (date) {
6639
+ return date.getHours();
6640
+ });
6641
+
6642
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
6643
+ });
6644
+
6645
+ if (disabledHours.length) {
6646
+ for (var i = 0; i < 24; i++) {
6647
+ hours[i] = disabledHours.indexOf(i) === -1;
6648
+ }
6649
+ } else {
6650
+ for (var _i = 0; _i < 24; _i++) {
6651
+ hours[_i] = false;
6652
+ }
6653
+ }
6654
+
6655
+ return hours;
6656
+ };
6657
+
6658
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
6659
+ if (amount <= 0) return [];
6660
+ var temp = new Date(date.getTime());
6661
+ temp.setDate(0);
6662
+ var lastDay = temp.getDate();
6663
+ return range(amount).map(function (_, index) {
6664
+ return lastDay - (amount - index - 1);
6665
+ });
6666
+ };
6667
+
6668
+ var getMonthDays = function getMonthDays(date) {
6669
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
6670
+ var days = temp.getDate();
6671
+ return range(days).map(function (_, index) {
6672
+ return index + 1;
6673
+ });
6674
+ };
6675
+
6676
+ function setRangeData(arr, start, end, value) {
6677
+ for (var i = start; i < end; i++) {
6678
+ arr[i] = value;
6679
+ }
6680
+ }
6681
+
6682
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
6683
+ var minutes = new Array(60);
6684
+
6685
+ if (ranges.length > 0) {
6686
+ ranges.forEach(function (range) {
6687
+ var start = range[0];
6688
+ var end = range[1];
6689
+ var startHour = start.getHours();
6690
+ var startMinute = start.getMinutes();
6691
+ var endHour = end.getHours();
6692
+ var endMinute = end.getMinutes();
6693
+ if (startHour === hour && endHour !== hour) {
6694
+ setRangeData(minutes, startMinute, 60, true);
6695
+ } else if (startHour === hour && endHour === hour) {
6696
+ setRangeData(minutes, startMinute, endMinute + 1, true);
6697
+ } else if (startHour !== hour && endHour === hour) {
6698
+ setRangeData(minutes, 0, endMinute + 1, true);
6699
+ } else if (startHour < hour && endHour > hour) {
6700
+ setRangeData(minutes, 0, 60, true);
6701
+ }
6702
+ });
6703
+ } else {
6704
+ setRangeData(minutes, 0, 60, true);
6705
+ }
6706
+ return minutes;
6707
+ };
6708
+
6709
+ var range = function range(n) {
6710
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
6711
+ return Array.apply(null, { length: n }).map(function (_, n) {
6712
+ return n;
6713
+ });
6714
+ };
6715
+
6716
+ var modifyDate = function modifyDate(date, y, m, d) {
6717
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
6718
+ };
6719
+
6720
+ var modifyTime = function modifyTime(date, h, m, s) {
6721
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
6722
+ };
6723
+
6724
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
6725
+ if (date == null || !time) {
6726
+ return date;
6727
+ }
6728
+ time = parseDate(time, 'HH:mm:ss');
6729
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
6730
+ };
6731
+
6732
+ var clearTime = function clearTime(date) {
6733
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
6734
+ };
6735
+
6736
+ var clearMilliseconds = function clearMilliseconds(date) {
6737
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
6738
+ };
6739
+
6740
+ var limitTimeRange = function limitTimeRange(date, ranges) {
6741
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
6742
+
6743
+ // TODO: refactory a more elegant solution
6744
+ if (ranges.length === 0) return date;
6745
+ var normalizeDate = function normalizeDate(date) {
6746
+ return fecha.parse(fecha.format(date, format), format);
6747
+ };
6748
+ var ndate = normalizeDate(date);
6749
+ var nranges = ranges.map(function (range) {
6750
+ return range.map(normalizeDate);
6751
+ });
6752
+ if (nranges.some(function (nrange) {
6753
+ return ndate >= nrange[0] && ndate <= nrange[1];
6754
+ })) return date;
6755
+
6756
+ var minDate = nranges[0][0];
6757
+ var maxDate = nranges[0][0];
6758
+
6759
+ nranges.forEach(function (nrange) {
6760
+ minDate = new Date(Math.min(nrange[0], minDate));
6761
+ maxDate = new Date(Math.max(nrange[1], minDate));
6762
+ });
6763
+
6764
+ var ret = ndate < minDate ? minDate : maxDate;
6765
+ // preserve Year/Month/Date
6766
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
6767
+ };
6768
+
6769
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
6770
+ var limitedDate = limitTimeRange(date, selectableRange, format);
6771
+ return limitedDate.getTime() === date.getTime();
6772
+ };
6773
+
6774
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
6775
+ // clamp date to the number of days in `year`, `month`
6776
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
6777
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
6778
+ return modifyDate(date, year, month, monthDate);
6779
+ };
6780
+
6781
+ var prevMonth = function prevMonth(date) {
6782
+ var year = date.getFullYear();
6783
+ var month = date.getMonth();
6784
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
6785
+ };
6786
+
6787
+ var nextMonth = function nextMonth(date) {
6788
+ var year = date.getFullYear();
6789
+ var month = date.getMonth();
6790
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
6791
+ };
6792
+
6793
+ var prevYear = function prevYear(date) {
6794
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6795
+
6796
+ var year = date.getFullYear();
6797
+ var month = date.getMonth();
6798
+ return changeYearMonthAndClampDate(date, year - amount, month);
6799
+ };
6800
+
6801
+ var nextYear = function nextYear(date) {
6802
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6803
+
6804
+ var year = date.getFullYear();
6805
+ var month = date.getMonth();
6806
+ return changeYearMonthAndClampDate(date, year + amount, month);
6807
+ };
6808
+
6809
+ var extractDateFormat = function extractDateFormat(format) {
6810
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
6811
+ };
6812
+
6813
+ var extractTimeFormat = function extractTimeFormat(format) {
6814
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
6815
+ };
6816
+
6817
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
6818
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
6819
+ };
6820
+
6833
6821
  /**
6834
6822
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
6835
6823
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
6836
6824
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
6837
6825
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
6838
6826
  * @returns {number} 工作日数量
6839
- */
6840
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
6841
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
6842
- throw new Error(
6843
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
6844
- );
6845
- }
6846
-
6847
- const startDateObj = new Date(start_date);
6848
- const endDateObj = new Date(end_date);
6849
-
6850
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
6851
- throw new Error(
6852
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
6853
- );
6854
- }
6855
-
6856
- if (startDateObj > endDateObj) {
6857
- throw new Error('Start date should be earlier than or equal to end date.');
6858
- }
6859
-
6860
- let workdays = 0;
6861
-
6862
- // Iterate through each day in the date range
6863
- for (
6864
- let currentDate = new Date(startDateObj);
6865
- currentDate <= endDateObj;
6866
- currentDate.setDate(currentDate.getDate() + 1)
6867
- ) {
6868
- // Check if the current day is a weekend (Saturday or Sunday)
6869
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
6870
-
6871
- // Check if the current day is a holiday
6872
- const isHoliday = holidays.some((holiday) => {
6873
- const holidayDate = new Date(holiday);
6874
- return currentDate.toDateString() === holidayDate.toDateString();
6875
- });
6876
-
6877
- // If it's a workday (not a weekend or holiday), increment the workdays count
6878
- if (!isWeekend && !isHoliday) {
6879
- workdays++;
6880
- }
6881
- }
6882
-
6883
- return workdays;
6884
- };
6885
-
6827
+ */
6828
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
6829
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
6830
+
6831
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
6832
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
6833
+ }
6834
+
6835
+ var startDateObj = new Date(start_date);
6836
+ var endDateObj = new Date(end_date);
6837
+
6838
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
6839
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
6840
+ }
6841
+
6842
+ if (startDateObj > endDateObj) {
6843
+ throw new Error('Start date should be earlier than or equal to end date.');
6844
+ }
6845
+
6846
+ var workdays = 0;
6847
+
6848
+ // Iterate through each day in the date range
6849
+
6850
+ var _loop = function _loop(currentDate) {
6851
+ // Check if the current day is a weekend (Saturday or Sunday)
6852
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
6853
+
6854
+ // Check if the current day is a holiday
6855
+ var isHoliday = holidays.some(function (holiday) {
6856
+ var holidayDate = new Date(holiday);
6857
+ return currentDate.toDateString() === holidayDate.toDateString();
6858
+ });
6859
+
6860
+ // If it's a workday (not a weekend or holiday), increment the workdays count
6861
+ if (!isWeekend && !isHoliday) {
6862
+ workdays++;
6863
+ }
6864
+ };
6865
+
6866
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
6867
+ _loop(currentDate);
6868
+ }
6869
+
6870
+ return workdays;
6871
+ };
6872
+
6886
6873
  /**
6887
6874
  * 日期加减天数
6888
6875
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
6889
6876
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
6890
6877
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
6891
- */
6892
- const dateAddDays = function (start_date, days) {
6893
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6894
- throw new Error(
6895
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
6896
- );
6897
- }
6898
-
6899
- const startDateObj = new Date(start_date);
6900
- if (isNaN(startDateObj.getTime())) {
6901
- throw new Error(
6902
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6903
- );
6904
- }
6905
-
6906
- const resultDateObj = new Date(startDateObj);
6907
- resultDateObj.setDate(resultDateObj.getDate() + days);
6908
-
6909
- const resultYear = resultDateObj.getFullYear();
6910
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6911
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6912
-
6913
- return `${resultYear}-${resultMonth}-${resultDay}`;
6914
- };
6915
-
6878
+ */
6879
+ var dateAddDays = function dateAddDays(start_date, days) {
6880
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6881
+ 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.");
6882
+ }
6883
+
6884
+ var startDateObj = new Date(start_date);
6885
+ if (isNaN(startDateObj.getTime())) {
6886
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6887
+ }
6888
+
6889
+ var resultDateObj = new Date(startDateObj);
6890
+ resultDateObj.setDate(resultDateObj.getDate() + days);
6891
+
6892
+ var resultYear = resultDateObj.getFullYear();
6893
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6894
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6895
+
6896
+ return resultYear + '-' + resultMonth + '-' + resultDay;
6897
+ };
6898
+
6916
6899
  /**
6917
6900
  * 计算两个日期之间的差值
6918
6901
  * @date 2023年12月14日
@@ -6920,182 +6903,180 @@ const dateAddDays = function (start_date, days) {
6920
6903
  * @param {String} end_date - 结束日期字符串
6921
6904
  * @param {String} unit - 单位:year/month/day
6922
6905
  * @returns {Number} 差值
6923
- */
6924
- const dateDiff = function (start_date, end_date, unit = 'day') {
6925
- // Assuming date strings are in "YYYY-MM-DD" format
6926
- var startDate = new Date(start_date);
6927
- var endDate = new Date(end_date);
6928
-
6929
- // If the date is invalid, return 0
6930
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6931
- return 0;
6932
- }
6933
-
6934
- if (unit === 'year') {
6935
- return endDate.getFullYear() - startDate.getFullYear();
6936
- } else if (unit === 'month') {
6937
- return (
6938
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
6939
- (endDate.getMonth() - startDate.getMonth())
6940
- );
6941
- } else {
6942
- // Default to day
6943
- var timeDifference = endDate - startDate;
6944
- // Calculate days (86400000 milliseconds per day)
6945
- return Math.floor(timeDifference / 86400000);
6946
- }
6947
- };
6948
-
6906
+ */
6907
+ var dateDiff = function dateDiff(start_date, end_date) {
6908
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
6909
+
6910
+ // Assuming date strings are in "YYYY-MM-DD" format
6911
+ var startDate = new Date(start_date);
6912
+ var endDate = new Date(end_date);
6913
+
6914
+ // If the date is invalid, return 0
6915
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6916
+ return 0;
6917
+ }
6918
+
6919
+ if (unit === 'year') {
6920
+ return endDate.getFullYear() - startDate.getFullYear();
6921
+ } else if (unit === 'month') {
6922
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
6923
+ } else {
6924
+ // Default to day
6925
+ var timeDifference = endDate - startDate;
6926
+ // Calculate days (86400000 milliseconds per day)
6927
+ return Math.floor(timeDifference / 86400000);
6928
+ }
6929
+ };
6930
+
6949
6931
  /**
6950
6932
  * 获取月份中的日期
6951
6933
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
6952
6934
  * @returns {number} 月份中的日期(1-31)
6953
- */
6954
- const dayOfMonth = function (date) {
6955
- if (typeof date !== 'string') {
6956
- throw new Error(
6957
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
6958
- );
6959
- }
6960
-
6961
- const dateObj = new Date(date);
6962
- if (isNaN(dateObj.getTime())) {
6963
- throw new Error(
6964
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6965
- );
6966
- }
6967
-
6968
- return dateObj.getDate();
6969
- };
6970
-
6935
+ */
6936
+ var dayOfMonth = function dayOfMonth(date) {
6937
+ if (typeof date !== 'string') {
6938
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6939
+ }
6940
+
6941
+ var dateObj = new Date(date);
6942
+ if (isNaN(dateObj.getTime())) {
6943
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6944
+ }
6945
+
6946
+ return dateObj.getDate();
6947
+ };
6948
+
6971
6949
  /**
6972
6950
  * 获取当前日期
6973
6951
  * @date 2022年5月7日
6974
6952
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
6975
6953
  * @returns {string} 当前日期的格式化字符串
6976
- */
6977
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
6978
- return formatDate(new Date(), format);
6979
- };
6980
-
6954
+ */
6955
+ var getCurrentDate = function getCurrentDate() {
6956
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
6957
+
6958
+ return formatDate(new Date(), format);
6959
+ };
6960
+
6981
6961
  /**
6982
6962
  * 获取当前日期时间
6983
6963
  * @date 2022年5月7日
6984
6964
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
6985
6965
  * @returns {string} 当前日期时间的格式化字符串
6986
- */
6987
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
6988
- return formatDate(new Date(), format);
6989
- };
6990
-
6966
+ */
6967
+ var getCurrentDateTime = function getCurrentDateTime() {
6968
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
6969
+
6970
+ return formatDate(new Date(), format);
6971
+ };
6972
+
6991
6973
  /**
6992
6974
  * 获取小时
6993
6975
  * @date 2022年5月7日
6994
6976
  * @param {Date|string} [date] - 日期对象或日期字符串
6995
6977
  * @returns {number} 小时数(0-23)
6996
- */
6997
- const getHour = function (date) {
6998
- if (!date) {
6999
- return new Date().getHours();
7000
- }
7001
- if (typeof date === 'string') {
7002
- date = new Date(date);
7003
- }
7004
- return date.getHours();
7005
- };
7006
-
6978
+ */
6979
+ var getHour = function getHour(date) {
6980
+ if (!date) {
6981
+ return new Date().getHours();
6982
+ }
6983
+ if (typeof date === 'string') {
6984
+ date = new Date(date);
6985
+ }
6986
+ return date.getHours();
6987
+ };
6988
+
7007
6989
  /**
7008
6990
  * 获取分钟
7009
6991
  * @date 2022年5月7日
7010
6992
  * @param {Date|string} [date] - 日期对象或日期字符串
7011
6993
  * @returns {number} 分钟数(0-59)
7012
- */
7013
- const getMinute = function (date) {
7014
- if (!date) {
7015
- return new Date().getMinutes();
7016
- }
7017
- if (typeof date === 'string') {
7018
- date = new Date(date);
7019
- }
7020
- return date.getMinutes();
7021
- };
7022
-
6994
+ */
6995
+ var getMinute = function getMinute(date) {
6996
+ if (!date) {
6997
+ return new Date().getMinutes();
6998
+ }
6999
+ if (typeof date === 'string') {
7000
+ date = new Date(date);
7001
+ }
7002
+ return date.getMinutes();
7003
+ };
7004
+
7023
7005
  /**
7024
7006
  * 获取月份
7025
7007
  * @date 2022年5月7日
7026
7008
  * @param {Date|string} [date] - 日期对象或日期字符串
7027
7009
  * @returns {number} 月份数(1-12)
7028
- */
7029
- const getMonth = function (date) {
7030
- if (!date) {
7031
- return new Date().getMonth() + 1;
7032
- }
7033
- if (typeof date === 'string') {
7034
- date = new Date(date);
7035
- }
7036
- return date.getMonth() + 1;
7037
- };
7038
-
7010
+ */
7011
+ var getMonth = function getMonth(date) {
7012
+ if (!date) {
7013
+ return new Date().getMonth() + 1;
7014
+ }
7015
+ if (typeof date === 'string') {
7016
+ date = new Date(date);
7017
+ }
7018
+ return date.getMonth() + 1;
7019
+ };
7020
+
7039
7021
  /**
7040
7022
  * 获取秒
7041
7023
  * @date 2022年5月7日
7042
7024
  * @param {Date|string} [date] - 日期对象或日期字符串
7043
7025
  * @returns {number} 秒数(0-59)
7044
- */
7045
- const getSecond = function (date) {
7046
- if (!date) {
7047
- return new Date().getSeconds();
7048
- }
7049
- if (typeof date === 'string') {
7050
- date = new Date(date);
7051
- }
7052
- return date.getSeconds();
7053
- };
7054
-
7026
+ */
7027
+ var getSecond = function getSecond(date) {
7028
+ if (!date) {
7029
+ return new Date().getSeconds();
7030
+ }
7031
+ if (typeof date === 'string') {
7032
+ date = new Date(date);
7033
+ }
7034
+ return date.getSeconds();
7035
+ };
7036
+
7055
7037
  /**
7056
7038
  * 获取星期几
7057
7039
  * @date 2022年5月7日
7058
7040
  * @param {Date|string} [date] - 日期对象或日期字符串
7059
7041
  * @returns {number} 星期几(0-6,0表示星期日)
7060
- */
7061
- const getWeekday = function (date) {
7062
- if (!date) {
7063
- return new Date().getDay();
7064
- }
7065
- if (typeof date === 'string') {
7066
- date = new Date(date);
7067
- }
7068
- return date.getDay();
7069
- };
7070
-
7071
-
7042
+ */
7043
+ var getWeekday = function getWeekday(date) {
7044
+ if (!date) {
7045
+ return new Date().getDay();
7046
+ }
7047
+ if (typeof date === 'string') {
7048
+ date = new Date(date);
7049
+ }
7050
+ return date.getDay();
7051
+ };
7052
+
7072
7053
  /**
7073
7054
  * @desc 获取上午/下午/晚上
7074
7055
  * @author huangbo
7075
7056
  * @date 2022年5月7日
7076
7057
  * @param {String} [time] - 时间
7077
- **/
7078
- const timeCycle = function (time) {
7079
- let hour = 0;
7080
- if (!time) {
7081
- hour = new Date().getHours();
7082
- } else if (typeof time === 'string') {
7083
- // 从时间字符串中提取小时
7084
- const match = time.match(/^(\d{1,2})/);
7085
- if (match) {
7086
- hour = parseInt(match[1], 10);
7087
- }
7088
- } else if (typeof time === 'number') {
7089
- hour = time;
7090
- }
7091
- // 判断时间段
7092
- if (hour >= 5 && hour < 12) {
7093
- return '上午';
7094
- } else if (hour >= 12 && hour < 18) {
7095
- return '下午';
7096
- } else {
7097
- return '晚上';
7098
- }
7058
+ **/
7059
+ var timeCycle = function timeCycle(time) {
7060
+ var hour = 0;
7061
+ if (!time) {
7062
+ hour = new Date().getHours();
7063
+ } else if (typeof time === 'string') {
7064
+ // 从时间字符串中提取小时
7065
+ var match = time.match(/^(\d{1,2})/);
7066
+ if (match) {
7067
+ hour = parseInt(match[1], 10);
7068
+ }
7069
+ } else if (typeof time === 'number') {
7070
+ hour = time;
7071
+ }
7072
+ // 判断时间段
7073
+ if (hour >= 5 && hour < 12) {
7074
+ return '上午';
7075
+ } else if (hour >= 12 && hour < 18) {
7076
+ return '下午';
7077
+ } else {
7078
+ return '晚上';
7079
+ }
7099
7080
  };
7100
7081
 
7101
7082
  /***/ }),