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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/lib/0.js +1 -1
  2. package/lib/1.js +1 -1
  3. package/lib/10.js +1 -1
  4. package/lib/11.js +1 -1
  5. package/lib/12.js +1 -1
  6. package/lib/13.js +1 -1
  7. package/lib/14.js +1 -1
  8. package/lib/15.js +1 -1
  9. package/lib/16.js +1 -1
  10. package/lib/17.js +1 -1
  11. package/lib/18.js +1 -1
  12. package/lib/19.js +1 -1
  13. package/lib/20.js +1 -1
  14. package/lib/21.js +1 -1
  15. package/lib/22.js +1 -1
  16. package/lib/23.js +1 -1
  17. package/lib/24.js +1 -1
  18. package/lib/25.js +1 -1
  19. package/lib/26.js +1 -1
  20. package/lib/27.js +1 -1
  21. package/lib/28.js +1 -1
  22. package/lib/29.js +1 -1
  23. package/lib/3.js +1 -1
  24. package/lib/30.js +1 -1
  25. package/lib/31.js +1 -1
  26. package/lib/32.js +1 -1
  27. package/lib/33.js +1 -1
  28. package/lib/34.js +1 -1
  29. package/lib/35.js +1 -1
  30. package/lib/36.js +1 -1
  31. package/lib/37.js +1 -1
  32. package/lib/38.js +1 -1
  33. package/lib/39.js +1 -1
  34. package/lib/4.js +1 -1
  35. package/lib/40.js +1 -1
  36. package/lib/41.js +1 -1
  37. package/lib/42.js +1 -1
  38. package/lib/43.js +1 -1
  39. package/lib/44.js +1 -1
  40. package/lib/45.js +1 -1
  41. package/lib/46.js +1 -1
  42. package/lib/47.js +1 -1
  43. package/lib/48.js +1 -1
  44. package/lib/49.js +1 -1
  45. package/lib/5.js +1 -1
  46. package/lib/50.js +1 -1
  47. package/lib/51.js +1 -1
  48. package/lib/52.js +1 -1
  49. package/lib/53.js +1 -1
  50. package/lib/54.js +1 -1
  51. package/lib/55.js +1 -1
  52. package/lib/56.js +1 -1
  53. package/lib/57.js +1 -1
  54. package/lib/58.js +1 -1
  55. package/lib/59.js +1 -1
  56. package/lib/6.js +1 -1
  57. package/lib/60.js +1 -1
  58. package/lib/61.js +1 -1
  59. package/lib/62.js +1 -1
  60. package/lib/63.js +1 -1
  61. package/lib/64.js +1 -1
  62. package/lib/65.js +1 -1
  63. package/lib/66.js +1 -1
  64. package/lib/67.js +1 -1
  65. package/lib/68.js +1 -1
  66. package/lib/69.js +1 -1
  67. package/lib/7.js +1 -1
  68. package/lib/70.js +1 -1
  69. package/lib/71.js +1 -1
  70. package/lib/72.js +1 -1
  71. package/lib/73.js +1 -1
  72. package/lib/74.js +1 -1
  73. package/lib/75.js +1 -1
  74. package/lib/76.js +1 -1
  75. package/lib/77.js +1 -1
  76. package/lib/78.js +1 -1
  77. package/lib/79.js +1 -1
  78. package/lib/8.js +1 -1
  79. package/lib/80.js +1 -1
  80. package/lib/81.js +1 -1
  81. package/lib/9.js +1 -1
  82. package/lib/account-login.js +837 -862
  83. package/lib/alert.js +2 -2
  84. package/lib/aside.js +2 -2
  85. package/lib/audit-trajectory.js +4 -4
  86. package/lib/autocomplete.js +1813 -1988
  87. package/lib/avatar.js +2 -2
  88. package/lib/backtop.js +2 -2
  89. package/lib/badge.js +2 -2
  90. package/lib/breadcrumb-item.js +4 -4
  91. package/lib/breadcrumb.js +4 -4
  92. package/lib/button-group.js +4 -4
  93. package/lib/button.js +2 -2
  94. package/lib/ca-login.js +837 -862
  95. package/lib/calendar.js +839 -864
  96. package/lib/card.js +2 -2
  97. package/lib/carousel-item.js +846 -871
  98. package/lib/carousel.js +839 -864
  99. package/lib/cascader-panel.js +852 -877
  100. package/lib/cascader.js +2048 -2223
  101. package/lib/checkbox-button.js +4 -4
  102. package/lib/checkbox-group.js +859 -884
  103. package/lib/checkbox.js +4 -4
  104. package/lib/col.js +2 -2
  105. package/lib/collapse-item.js +1040 -1065
  106. package/lib/collapse.js +1040 -1065
  107. package/lib/color-picker.js +972 -1122
  108. package/lib/container.js +2 -2
  109. package/lib/cron.js +12 -12
  110. package/lib/data-table.js +843 -868
  111. package/lib/date-picker.js +10520 -10695
  112. package/lib/descriptions-item.js +4 -4
  113. package/lib/descriptions.js +4 -4
  114. package/lib/dialog.js +837 -862
  115. package/lib/divider.js +2 -2
  116. package/lib/drawer.js +2 -2
  117. package/lib/dropdown-item.js +4 -4
  118. package/lib/dropdown-menu.js +974 -1124
  119. package/lib/dropdown.js +841 -866
  120. package/lib/email-login.js +837 -862
  121. package/lib/empty.js +2 -2
  122. package/lib/eoss.common.js +4023 -2668
  123. package/lib/flip.js +2 -2
  124. package/lib/flow-group.js +853 -878
  125. package/lib/flow.js +868 -893
  126. package/lib/flows.js +854 -879
  127. package/lib/footer.js +2 -2
  128. package/lib/form-item.js +860 -885
  129. package/lib/form.js +933 -950
  130. package/lib/guide.js +2 -2
  131. package/lib/header.js +2 -2
  132. package/lib/icon.js +837 -862
  133. package/lib/icons.js +2 -2
  134. package/lib/image-viewer.js +837 -862
  135. package/lib/image.js +4 -4
  136. package/lib/index.js +1 -1
  137. package/lib/infinite-scroll.js +2 -2
  138. package/lib/input-number.js +6 -6
  139. package/lib/input.js +839 -864
  140. package/lib/link.js +2 -2
  141. package/lib/loading.js +2 -2
  142. package/lib/login.js +867 -891
  143. package/lib/lowcode-view.js +1843 -1185
  144. package/lib/lowcode.js +3050 -1569
  145. package/lib/main.js +970 -988
  146. package/lib/marquee.js +837 -862
  147. package/lib/menu-item-group.js +15 -15
  148. package/lib/menu-item.js +6 -6
  149. package/lib/menu.js +2227 -2368
  150. package/lib/message-box.js +843 -868
  151. package/lib/message.js +839 -864
  152. package/lib/notification.js +861 -886
  153. package/lib/option-group.js +4 -4
  154. package/lib/option.js +839 -864
  155. package/lib/page-header.js +2 -2
  156. package/lib/pagination.js +839 -864
  157. package/lib/phone-login.js +847 -866
  158. package/lib/popconfirm.js +4 -4
  159. package/lib/popover.js +1831 -2006
  160. package/lib/process-config.js +839 -864
  161. package/lib/process-module.js +846 -871
  162. package/lib/process-rule.js +905 -930
  163. package/lib/progress.js +2 -2
  164. package/lib/qr-code.js +4 -4
  165. package/lib/qrcode-login.js +839 -864
  166. package/lib/radio-button.js +4 -4
  167. package/lib/radio-group.js +850 -875
  168. package/lib/radio.js +4 -4
  169. package/lib/rate.js +837 -862
  170. package/lib/retrial-auth.js +837 -862
  171. package/lib/row.js +2 -2
  172. package/lib/scrollbar.js +839 -864
  173. package/lib/select.js +2139 -2314
  174. package/lib/selector-panel.js +940 -965
  175. package/lib/selector.js +852 -877
  176. package/lib/slider.js +4 -4
  177. package/lib/step.js +32 -32
  178. package/lib/steps.js +874 -899
  179. package/lib/submenu.js +1269 -1385
  180. package/lib/switch.js +839 -864
  181. package/lib/tab-pane.js +4 -4
  182. package/lib/table-column.js +840 -865
  183. package/lib/table.js +1825 -2000
  184. package/lib/tabs.js +846 -871
  185. package/lib/tag.js +2 -2
  186. package/lib/theme-chalk/fonts/iconfont.ttf +0 -0
  187. package/lib/theme-chalk/fonts/iconfont.woff +0 -0
  188. package/lib/theme-chalk/index.css +1 -1
  189. package/lib/theme-chalk/lowcode.css +1 -1
  190. package/lib/time-picker.js +6471 -6646
  191. package/lib/time-select.js +5039 -5214
  192. package/lib/timeline-item.js +2 -2
  193. package/lib/timeline.js +2 -2
  194. package/lib/tips.js +837 -862
  195. package/lib/toolbar.js +4 -4
  196. package/lib/tooltip.js +1813 -1988
  197. package/lib/transfer.js +837 -862
  198. package/lib/tree-group.js +853 -878
  199. package/lib/tree.js +1026 -1051
  200. package/lib/update-history.js +4 -4
  201. package/lib/upload.js +859 -884
  202. package/lib/wujie.js +841 -866
  203. package/package.json +1 -1
  204. package/packages/flow-group/src/main.vue +2 -2
  205. package/packages/form/src/form-item-render.vue +1 -0
  206. package/packages/form/src/form-item.vue +12 -6
  207. package/packages/form/src/form.vue +5 -5
  208. package/packages/login/src/login.vue +1 -0
  209. package/packages/lowcode/src/attribute/function.vue +28 -9
  210. package/packages/lowcode/src/attribute/props.vue +202 -0
  211. package/packages/lowcode/src/attribute/styles.vue +79 -5
  212. package/packages/lowcode/src/attribute.vue +61 -4
  213. package/packages/lowcode/src/canvas.vue +159 -2
  214. package/packages/lowcode/src/form-render.vue +305 -0
  215. package/packages/lowcode/src/lowcode.vue +33 -13
  216. package/packages/lowcode/src/modules.vue +53 -37
  217. package/packages/lowcode/src/render.vue +80 -25
  218. package/packages/lowcode/src/util/components.js +100 -0
  219. package/packages/lowcode/src/util/props-util.js +67 -0
  220. package/packages/lowcode/src/util/source-generator.js +69 -9
  221. package/packages/lowcode/src/util/source-parser.js +64 -10
  222. package/packages/lowcode-view/src/render.vue +48 -18
  223. package/packages/main/src/components/userinfo.vue +0 -1
  224. package/packages/menu/src/menu-item-group.vue +1 -1
  225. package/packages/menu/src/mixins.js +8 -4
  226. package/packages/menu/src/submenu.vue +35 -5
  227. package/packages/phone-login/src/phone-login.vue +5 -2
  228. package/packages/theme-chalk/dist/fonts/iconfont.ttf +0 -0
  229. package/packages/theme-chalk/dist/fonts/iconfont.woff +0 -0
  230. package/packages/theme-chalk/src/fonts/iconfont.ttf +0 -0
  231. package/packages/theme-chalk/src/fonts/iconfont.woff +0 -0
  232. package/packages/theme-chalk/src/lowcode.scss +21 -2
  233. package/src/index.js +336 -336
package/lib/tabs.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 = 199);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 206);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3285,7 +3285,7 @@ var warning = function warning(content, _callback3) {
3285
3285
 
3286
3286
  /***/ }),
3287
3287
 
3288
- /***/ 116:
3288
+ /***/ 118:
3289
3289
  /***/ (function(module, exports) {
3290
3290
 
3291
3291
  module.exports = require("babel-helper-vue-jsx-merge-props");
@@ -3521,7 +3521,14 @@ module.exports = require("lodash/cloneDeep");
3521
3521
 
3522
3522
  /***/ }),
3523
3523
 
3524
- /***/ 199:
3524
+ /***/ 2:
3525
+ /***/ (function(module, exports) {
3526
+
3527
+ module.exports = require("vue");
3528
+
3529
+ /***/ }),
3530
+
3531
+ /***/ 206:
3525
3532
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3526
3533
 
3527
3534
  "use strict";
@@ -3529,7 +3536,7 @@ module.exports = require("lodash/cloneDeep");
3529
3536
  __webpack_require__.r(__webpack_exports__);
3530
3537
 
3531
3538
  // EXTERNAL MODULE: external "babel-helper-vue-jsx-merge-props"
3532
- var external_babel_helper_vue_jsx_merge_props_ = __webpack_require__(116);
3539
+ var external_babel_helper_vue_jsx_merge_props_ = __webpack_require__(118);
3533
3540
  var external_babel_helper_vue_jsx_merge_props_default = /*#__PURE__*/__webpack_require__.n(external_babel_helper_vue_jsx_merge_props_);
3534
3541
 
3535
3542
  // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/tabs/src/tab-bar.vue?vue&type=template&id=61310203&
@@ -4764,13 +4771,6 @@ tabs.install = function (Vue) {
4764
4771
 
4765
4772
  /***/ }),
4766
4773
 
4767
- /***/ 2:
4768
- /***/ (function(module, exports) {
4769
-
4770
- module.exports = require("vue");
4771
-
4772
- /***/ }),
4773
-
4774
4774
  /***/ 3:
4775
4775
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4776
4776
 
@@ -5206,759 +5206,736 @@ function normalizeComponent(
5206
5206
  /* unused harmony export getSecond */
5207
5207
  /* unused harmony export getWeekday */
5208
5208
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
5209
- /* Modified from https://github.com/taylorhakes/fecha
5210
- *
5211
- * The MIT License (MIT)
5212
- *
5213
- * Copyright (c) 2015 Taylor Hakes
5214
- *
5215
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5216
- * of this software and associated documentation files (the "Software"), to deal
5217
- * in the Software without restriction, including without limitation the rights
5218
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5219
- * copies of the Software, and to permit persons to whom the Software is
5220
- * furnished to do so, subject to the following conditions:
5221
- *
5222
- * The above copyright notice and this permission notice shall be included in all
5223
- * copies or substantial portions of the Software.
5224
- *
5225
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5226
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5227
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5228
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5229
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5230
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5231
- * SOFTWARE.
5232
- */
5233
-
5234
- /*eslint-disable*/
5235
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
5236
-
5237
-
5209
+
5210
+
5238
5211
  /**
5239
5212
  * Parse or format dates
5240
5213
  * @class fecha
5241
- */
5242
- const fecha = {};
5243
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5244
- const twoDigits = '\\d\\d?';
5245
- const threeDigits = '\\d{3}';
5246
- const fourDigits = '\\d{4}';
5247
- const word = '[^\\s]+';
5248
- const literal = /\[([^]*?)\]/gm;
5249
- const noop = function () {};
5250
-
5251
- function regexEscape(str) {
5252
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5253
- }
5254
-
5255
- function shorten(arr, sLen) {
5256
- const newArr = [];
5257
- for (let i = 0, len = arr.length; i < len; i++) {
5258
- newArr.push(arr[i].substr(0, sLen));
5259
- }
5260
- return newArr;
5261
- }
5262
-
5263
- function monthUpdate() {
5264
- return function (d, v) {
5265
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5266
- if (~index) {
5267
- d.month = index;
5268
- }
5269
- };
5270
- }
5271
-
5272
- function pad(val, len) {
5273
- val = String(val);
5274
- len = len || 2;
5275
- while (val.length < len) {
5276
- val = '0' + val;
5277
- }
5278
- return val;
5279
- }
5280
-
5281
- // 直接使用中文日期名称常量
5282
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5283
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5284
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5285
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5286
- const amPm = ['上午', '下午'];
5287
- const DoFn = function DoFn(D) {
5288
- return D + '日';
5289
- };
5290
-
5291
- const formatFlags = {
5292
- D: function(dateObj) {
5293
- return dateObj.getDay();
5294
- },
5295
- DD: function(dateObj) {
5296
- return pad(dateObj.getDay());
5297
- },
5298
- Do: function(dateObj) {
5299
- return DoFn(dateObj.getDate());
5300
- },
5301
- d: function(dateObj) {
5302
- return dateObj.getDate();
5303
- },
5304
- dd: function(dateObj) {
5305
- return pad(dateObj.getDate());
5306
- },
5307
- ddd: function(dateObj) {
5308
- return dayNamesShort[dateObj.getDay()];
5309
- },
5310
- dddd: function(dateObj) {
5311
- return dayNames[dateObj.getDay()];
5312
- },
5313
- M: function(dateObj) {
5314
- return dateObj.getMonth() + 1;
5315
- },
5316
- MM: function(dateObj) {
5317
- return pad(dateObj.getMonth() + 1);
5318
- },
5319
- MMM: function(dateObj) {
5320
- return monthNamesShort[dateObj.getMonth()];
5321
- },
5322
- MMMM: function(dateObj) {
5323
- return monthNames[dateObj.getMonth()];
5324
- },
5325
- yy: function(dateObj) {
5326
- return pad(String(dateObj.getFullYear()), 4).substr(2);
5327
- },
5328
- yyyy: function(dateObj) {
5329
- return pad(dateObj.getFullYear(), 4);
5330
- },
5331
- h: function(dateObj) {
5332
- return dateObj.getHours() % 12 || 12;
5333
- },
5334
- hh: function(dateObj) {
5335
- return pad(dateObj.getHours() % 12 || 12);
5336
- },
5337
- H: function(dateObj) {
5338
- return dateObj.getHours();
5339
- },
5340
- HH: function(dateObj) {
5341
- return pad(dateObj.getHours());
5342
- },
5343
- m: function(dateObj) {
5344
- return dateObj.getMinutes();
5345
- },
5346
- mm: function(dateObj) {
5347
- return pad(dateObj.getMinutes());
5348
- },
5349
- s: function(dateObj) {
5350
- return dateObj.getSeconds();
5351
- },
5352
- ss: function(dateObj) {
5353
- return pad(dateObj.getSeconds());
5354
- },
5355
- S: function(dateObj) {
5356
- return Math.round(dateObj.getMilliseconds() / 100);
5357
- },
5358
- SS: function(dateObj) {
5359
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5360
- },
5361
- SSS: function(dateObj) {
5362
- return pad(dateObj.getMilliseconds(), 3);
5363
- },
5364
- a: function(dateObj) {
5365
- return dateObj.getHours() < 12 ? '上午' : '下午';
5366
- },
5367
- A: function(dateObj) {
5368
- return dateObj.getHours() < 12 ? '上午' : '下午';
5369
- },
5370
- ZZ: function(dateObj) {
5371
- const o = dateObj.getTimezoneOffset();
5372
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5373
- }
5374
- };
5375
-
5376
- const parseFlags = {
5377
- d: [twoDigits, function (d, v) {
5378
- d.day = v;
5379
- }],
5380
- Do: [twoDigits + word, function (d, v) {
5381
- d.day = parseInt(v, 10);
5382
- }],
5383
- M: [twoDigits, function (d, v) {
5384
- d.month = v - 1;
5385
- }],
5386
- yy: [twoDigits, function (d, v) {
5387
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
5388
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5389
- }],
5390
- h: [twoDigits, function (d, v) {
5391
- d.hour = v;
5392
- }],
5393
- m: [twoDigits, function (d, v) {
5394
- d.minute = v;
5395
- }],
5396
- s: [twoDigits, function (d, v) {
5397
- d.second = v;
5398
- }],
5399
- yyyy: [fourDigits, function (d, v) {
5400
- d.year = v;
5401
- }],
5402
- S: ['\\d', function (d, v) {
5403
- d.millisecond = v * 100;
5404
- }],
5405
- SS: ['\\d{2}', function (d, v) {
5406
- d.millisecond = v * 10;
5407
- }],
5408
- SSS: [threeDigits, function (d, v) {
5409
- d.millisecond = v;
5410
- }],
5411
- D: [twoDigits, noop],
5412
- ddd: [word, noop],
5413
- MMM: [word, monthUpdate('monthNamesShort')],
5414
- MMMM: [word, monthUpdate('monthNames')],
5415
- a: [word, function (d, v) {
5416
- const val = v.toLowerCase();
5417
- if (val === '上午') {
5418
- d.isPm = false;
5419
- } else if (val === '下午') {
5420
- d.isPm = true;
5421
- }
5422
- }],
5423
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5424
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
5425
-
5426
- if (parts) {
5427
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5428
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5429
- }
5430
- }]
5431
- };
5432
- parseFlags.dd = parseFlags.d;
5433
- parseFlags.dddd = parseFlags.ddd;
5434
- parseFlags.DD = parseFlags.D;
5435
- parseFlags.mm = parseFlags.m;
5436
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5437
- parseFlags.MM = parseFlags.M;
5438
- parseFlags.ss = parseFlags.s;
5439
- parseFlags.A = parseFlags.a;
5440
-
5441
-
5442
- // Some common format strings
5443
- fecha.masks = {
5444
- default: 'ddd MMM dd yyyy HH:mm:ss',
5445
- shortDate: 'M/D/yy',
5446
- mediumDate: 'MMM d, yyyy',
5447
- longDate: 'MMMM d, yyyy',
5448
- fullDate: 'dddd, MMMM d, yyyy',
5449
- shortTime: 'HH:mm',
5450
- mediumTime: 'HH:mm:ss',
5451
- longTime: 'HH:mm:ss.SSS'
5452
- };
5453
-
5214
+ */
5215
+ var fecha = {};
5216
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5217
+ var twoDigits = '\\d\\d?';
5218
+ var threeDigits = '\\d{3}';
5219
+ var fourDigits = '\\d{4}';
5220
+ var word = '[^\\s]+';
5221
+ var literal = /\[([^]*?)\]/gm;
5222
+ var noop = function noop() {};
5223
+
5224
+ function regexEscape(str) {
5225
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5226
+ }
5227
+
5228
+ function shorten(arr, sLen) {
5229
+ var newArr = [];
5230
+ for (var i = 0, len = arr.length; i < len; i++) {
5231
+ newArr.push(arr[i].substr(0, sLen));
5232
+ }
5233
+ return newArr;
5234
+ }
5235
+
5236
+ function monthUpdate() {
5237
+ return function (d, v) {
5238
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5239
+ if (~index) {
5240
+ d.month = index;
5241
+ }
5242
+ };
5243
+ }
5244
+
5245
+ function pad(val, len) {
5246
+ val = String(val);
5247
+ len = len || 2;
5248
+ while (val.length < len) {
5249
+ val = '0' + val;
5250
+ }
5251
+ return val;
5252
+ }
5253
+
5254
+ // 直接使用中文日期名称常量
5255
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5256
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5257
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5258
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5259
+ var amPm = ['上午', '下午'];
5260
+ var DoFn = function DoFn(D) {
5261
+ return D + '日';
5262
+ };
5263
+
5264
+ var formatFlags = {
5265
+ D: function D(dateObj) {
5266
+ return dateObj.getDay();
5267
+ },
5268
+ DD: function DD(dateObj) {
5269
+ return pad(dateObj.getDay());
5270
+ },
5271
+ Do: function Do(dateObj) {
5272
+ return DoFn(dateObj.getDate());
5273
+ },
5274
+ d: function d(dateObj) {
5275
+ return dateObj.getDate();
5276
+ },
5277
+ dd: function dd(dateObj) {
5278
+ return pad(dateObj.getDate());
5279
+ },
5280
+ ddd: function ddd(dateObj) {
5281
+ return dayNamesShort[dateObj.getDay()];
5282
+ },
5283
+ dddd: function dddd(dateObj) {
5284
+ return dayNames[dateObj.getDay()];
5285
+ },
5286
+ M: function M(dateObj) {
5287
+ return dateObj.getMonth() + 1;
5288
+ },
5289
+ MM: function MM(dateObj) {
5290
+ return pad(dateObj.getMonth() + 1);
5291
+ },
5292
+ MMM: function MMM(dateObj) {
5293
+ return monthNamesShort[dateObj.getMonth()];
5294
+ },
5295
+ MMMM: function MMMM(dateObj) {
5296
+ return monthNames[dateObj.getMonth()];
5297
+ },
5298
+ yy: function yy(dateObj) {
5299
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
5300
+ },
5301
+ yyyy: function yyyy(dateObj) {
5302
+ return pad(dateObj.getFullYear(), 4);
5303
+ },
5304
+ h: function h(dateObj) {
5305
+ return dateObj.getHours() % 12 || 12;
5306
+ },
5307
+ hh: function hh(dateObj) {
5308
+ return pad(dateObj.getHours() % 12 || 12);
5309
+ },
5310
+ H: function H(dateObj) {
5311
+ return dateObj.getHours();
5312
+ },
5313
+ HH: function HH(dateObj) {
5314
+ return pad(dateObj.getHours());
5315
+ },
5316
+ m: function m(dateObj) {
5317
+ return dateObj.getMinutes();
5318
+ },
5319
+ mm: function mm(dateObj) {
5320
+ return pad(dateObj.getMinutes());
5321
+ },
5322
+ s: function s(dateObj) {
5323
+ return dateObj.getSeconds();
5324
+ },
5325
+ ss: function ss(dateObj) {
5326
+ return pad(dateObj.getSeconds());
5327
+ },
5328
+ S: function S(dateObj) {
5329
+ return Math.round(dateObj.getMilliseconds() / 100);
5330
+ },
5331
+ SS: function SS(dateObj) {
5332
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5333
+ },
5334
+ SSS: function SSS(dateObj) {
5335
+ return pad(dateObj.getMilliseconds(), 3);
5336
+ },
5337
+ a: function a(dateObj) {
5338
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5339
+ },
5340
+ A: function A(dateObj) {
5341
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5342
+ },
5343
+ ZZ: function ZZ(dateObj) {
5344
+ var o = dateObj.getTimezoneOffset();
5345
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5346
+ }
5347
+ };
5348
+
5349
+ var parseFlags = {
5350
+ d: [twoDigits, function (d, v) {
5351
+ d.day = v;
5352
+ }],
5353
+ Do: [twoDigits + word, function (d, v) {
5354
+ d.day = parseInt(v, 10);
5355
+ }],
5356
+ M: [twoDigits, function (d, v) {
5357
+ d.month = v - 1;
5358
+ }],
5359
+ yy: [twoDigits, function (d, v) {
5360
+ var da = new Date(),
5361
+ cent = +('' + da.getFullYear()).substr(0, 2);
5362
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5363
+ }],
5364
+ h: [twoDigits, function (d, v) {
5365
+ d.hour = v;
5366
+ }],
5367
+ m: [twoDigits, function (d, v) {
5368
+ d.minute = v;
5369
+ }],
5370
+ s: [twoDigits, function (d, v) {
5371
+ d.second = v;
5372
+ }],
5373
+ yyyy: [fourDigits, function (d, v) {
5374
+ d.year = v;
5375
+ }],
5376
+ S: ['\\d', function (d, v) {
5377
+ d.millisecond = v * 100;
5378
+ }],
5379
+ SS: ['\\d{2}', function (d, v) {
5380
+ d.millisecond = v * 10;
5381
+ }],
5382
+ SSS: [threeDigits, function (d, v) {
5383
+ d.millisecond = v;
5384
+ }],
5385
+ D: [twoDigits, noop],
5386
+ ddd: [word, noop],
5387
+ MMM: [word, monthUpdate('monthNamesShort')],
5388
+ MMMM: [word, monthUpdate('monthNames')],
5389
+ a: [word, function (d, v) {
5390
+ var val = v.toLowerCase();
5391
+ if (val === '上午') {
5392
+ d.isPm = false;
5393
+ } else if (val === '下午') {
5394
+ d.isPm = true;
5395
+ }
5396
+ }],
5397
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5398
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
5399
+ minutes = void 0;
5400
+
5401
+ if (parts) {
5402
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5403
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5404
+ }
5405
+ }]
5406
+ };
5407
+ parseFlags.dd = parseFlags.d;
5408
+ parseFlags.dddd = parseFlags.ddd;
5409
+ parseFlags.DD = parseFlags.D;
5410
+ parseFlags.mm = parseFlags.m;
5411
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5412
+ parseFlags.MM = parseFlags.M;
5413
+ parseFlags.ss = parseFlags.s;
5414
+ parseFlags.A = parseFlags.a;
5415
+
5416
+ // Some common format strings
5417
+ fecha.masks = {
5418
+ default: 'ddd MMM dd yyyy HH:mm:ss',
5419
+ shortDate: 'M/D/yy',
5420
+ mediumDate: 'MMM d, yyyy',
5421
+ longDate: 'MMMM d, yyyy',
5422
+ fullDate: 'dddd, MMMM d, yyyy',
5423
+ shortTime: 'HH:mm',
5424
+ mediumTime: 'HH:mm:ss',
5425
+ longTime: 'HH:mm:ss.SSS'
5426
+ };
5427
+
5454
5428
  /***
5455
5429
  * Format a date
5456
5430
  * @method format
5457
5431
  * @param {Date|number} dateObj
5458
5432
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
5459
- */
5460
- fecha.format = function (dateObj, mask) {
5461
- if (typeof dateObj === 'number') {
5462
- dateObj = new Date(dateObj);
5463
- }
5464
-
5465
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5466
- throw new Error('Invalid Date in fecha.format');
5467
- }
5468
-
5469
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
5470
-
5471
- const literals = [];
5472
-
5473
- // Make literals inactive by replacing them with ??
5474
- mask = mask.replace(literal, function($0, $1) {
5475
- literals.push($1);
5476
- return '@@@';
5477
- });
5478
- // Apply formatting rules
5479
- mask = mask.replace(token, function ($0) {
5480
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5481
- });
5482
- // Inline literal values back into the formatted value
5483
- return mask.replace(/@@@/g, function() {
5484
- return literals.shift();
5485
- });
5486
- };
5487
-
5433
+ */
5434
+ fecha.format = function (dateObj, mask) {
5435
+ if (typeof dateObj === 'number') {
5436
+ dateObj = new Date(dateObj);
5437
+ }
5438
+
5439
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5440
+ throw new Error('Invalid Date in fecha.format');
5441
+ }
5442
+
5443
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
5444
+
5445
+ var literals = [];
5446
+
5447
+ // Make literals inactive by replacing them with ??
5448
+ mask = mask.replace(literal, function ($0, $1) {
5449
+ literals.push($1);
5450
+ return '@@@';
5451
+ });
5452
+ // Apply formatting rules
5453
+ mask = mask.replace(token, function ($0) {
5454
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5455
+ });
5456
+ // Inline literal values back into the formatted value
5457
+ return mask.replace(/@@@/g, function () {
5458
+ return literals.shift();
5459
+ });
5460
+ };
5461
+
5488
5462
  /**
5489
5463
  * Parse a date string into an object, changes - into /
5490
5464
  * @method parse
5491
5465
  * @param {string} dateStr Date string
5492
5466
  * @param {string} format Date parse format
5493
5467
  * @returns {Date|boolean}
5494
- */
5495
- fecha.parse = function (dateStr, format) {
5496
- if (typeof format !== 'string') {
5497
- throw new Error('Invalid format in fecha.parse');
5498
- }
5499
-
5500
- format = fecha.masks[format] || format;
5501
-
5502
- // Avoid regular expression denial of service, fail early for really long strings
5503
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5504
- if (dateStr.length > 1000) {
5505
- return null;
5506
- }
5507
-
5508
- const dateInfo = {};
5509
- const parseInfo = [];
5510
- const literals = [];
5511
- format = format.replace(literal, function($0, $1) {
5512
- literals.push($1);
5513
- return '@@@';
5514
- });
5515
- let newFormat = regexEscape(format).replace(token, function ($0) {
5516
- if (parseFlags[$0]) {
5517
- const info = parseFlags[$0];
5518
- parseInfo.push(info[1]);
5519
- return '(' + info[0] + ')';
5520
- }
5521
-
5522
- return $0;
5523
- });
5524
- newFormat = newFormat.replace(/@@@/g, function() {
5525
- return literals.shift();
5526
- });
5527
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
5528
- if (!matches) {
5529
- return null;
5530
- }
5531
-
5532
- for (let i = 1; i < matches.length; i++) {
5533
- parseInfo[i - 1](dateInfo, matches[i]);
5534
- }
5535
-
5536
- const today = new Date();
5537
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5538
- dateInfo.hour = +dateInfo.hour + 12;
5539
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5540
- dateInfo.hour = 0;
5541
- }
5542
-
5543
- let date;
5544
- if (dateInfo.timezoneOffset != null) {
5545
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5546
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5547
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
5548
- } else {
5549
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5550
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
5551
- }
5552
- return date;
5553
- };
5554
-
5555
- // 导出fecha对象
5556
-
5557
-
5558
- // 以下是从date-util.js合并的函数
5559
- const newArray = function(start, end) {
5560
- let result = [];
5561
- for (let i = start; i <= end; i++) {
5562
- result.push(i);
5563
- }
5564
- return result;
5565
- };
5566
-
5567
- const getSettings = () => {
5568
- return {
5569
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5570
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5571
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5572
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5573
- amPm: ['上午', '下午']
5574
- };
5575
- };
5576
-
5577
- const toDate = function(date) {
5578
- return isDate(date) ? new Date(date) : null;
5579
- };
5580
-
5581
- const isDate = function(date) {
5582
- if (date === null || date === undefined) return false;
5583
- if (isNaN(new Date(date).getTime())) return false;
5584
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5585
- return true;
5586
- };
5587
-
5588
- const isDateObject = function(val) {
5589
- return val instanceof Date;
5590
- };
5591
-
5592
- const formatDate = function (date, format = 'yyyy-MM-dd') {
5593
- // 处理多种输入类型
5594
- if (!date) return '';
5595
-
5596
- // 如果是时间戳,转成日期对象
5597
- if (typeof date === 'number') {
5598
- date = new Date(date);
5599
- }
5600
- // 如果是字符串,转成日期对象
5601
- if (typeof date === 'string') {
5602
- date = new Date(date);
5603
- }
5604
-
5605
- // 调用toDate进一步验证和转换
5606
- date = toDate(date);
5607
- if (!date) return '';
5608
-
5609
- // 兼容大写和小写的格式标记
5610
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5611
- const lowercaseFormat = format
5612
- .replace(/YYYY/g, 'yyyy')
5613
- .replace(/D/g, 'd')
5614
-
5615
- // 使用fecha库进行格式化,支持中文配置
5616
- const str = fecha.format(date, lowercaseFormat, getSettings());
5617
- return str;
5618
- };
5619
-
5620
- const parseDate = function(string, format) {
5621
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5622
- };
5623
-
5624
- const getDayCountOfMonth = function(year, month) {
5625
- if (month === 3 || month === 5 || month === 8 || month === 10) {
5626
- return 30;
5627
- }
5628
-
5629
- if (month === 1) {
5630
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5631
- return 29;
5632
- } else {
5633
- return 28;
5634
- }
5635
- }
5636
-
5637
- return 31;
5638
- };
5639
-
5640
- const getDayCountOfYear = function(year) {
5641
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
5642
- return isLeapYear ? 366 : 365;
5643
- };
5644
-
5645
- const getFirstDayOfMonth = function(date) {
5646
- const temp = new Date(date.getTime());
5647
- temp.setDate(1);
5648
- return temp.getDay();
5649
- };
5650
-
5651
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5652
- // {prev, next} Date should work for Daylight Saving Time
5653
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5654
- const prevDate = function(date, amount = 1) {
5655
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5656
- };
5657
-
5658
- const nextDate = function(date, amount = 1) {
5659
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5660
- };
5661
-
5662
- const getStartDateOfMonth = function(year, month) {
5663
- const result = new Date(year, month, 1);
5664
- const day = result.getDay();
5665
-
5666
- if (day === 0) {
5667
- return prevDate(result, 7);
5668
- } else {
5669
- return prevDate(result, day);
5670
- }
5671
- };
5672
-
5673
- const getWeekNumber = function(date) {
5674
- // 支持多种输入类型
5675
- if (!date||!isDate(date)) {
5676
- date = new Date();
5677
- }
5678
- if (typeof date === 'string') {
5679
- date = new Date(date);
5680
- }
5681
-
5682
- // 验证日期有效性
5683
- if (!isDate(date)) return null;
5684
-
5685
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5686
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5687
- // 将星期日的星期数设为7
5688
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5689
- // 获取当年的第一天
5690
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5691
- // 计算到最近的星期四的完整周数
5692
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
5693
- // 返回周数
5694
- return weekNo;
5695
- };
5696
-
5697
- const getRangeHours = function(ranges) {
5698
- const hours = [];
5699
- let disabledHours = [];
5700
-
5701
- (ranges || []).forEach(range => {
5702
- const value = range.map(date => date.getHours());
5703
-
5704
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5705
- });
5706
-
5707
- if (disabledHours.length) {
5708
- for (let i = 0; i < 24; i++) {
5709
- hours[i] = disabledHours.indexOf(i) === -1;
5710
- }
5711
- } else {
5712
- for (let i = 0; i < 24; i++) {
5713
- hours[i] = false;
5714
- }
5715
- }
5716
-
5717
- return hours;
5718
- };
5719
-
5720
- const getPrevMonthLastDays = (date, amount) => {
5721
- if (amount <= 0) return [];
5722
- const temp = new Date(date.getTime());
5723
- temp.setDate(0);
5724
- const lastDay = temp.getDate();
5725
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
5726
- };
5727
-
5728
- const getMonthDays = (date) => {
5729
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5730
- const days = temp.getDate();
5731
- return range(days).map((_, index) => index + 1);
5732
- };
5733
-
5734
- function setRangeData(arr, start, end, value) {
5735
- for (let i = start; i < end; i++) {
5736
- arr[i] = value;
5737
- }
5738
- }
5739
-
5740
- const getRangeMinutes = function(ranges, hour) {
5741
- const minutes = new Array(60);
5742
-
5743
- if (ranges.length > 0) {
5744
- ranges.forEach(range => {
5745
- const start = range[0];
5746
- const end = range[1];
5747
- const startHour = start.getHours();
5748
- const startMinute = start.getMinutes();
5749
- const endHour = end.getHours();
5750
- const endMinute = end.getMinutes();
5751
- if (startHour === hour && endHour !== hour) {
5752
- setRangeData(minutes, startMinute, 60, true);
5753
- } else if (startHour === hour && endHour === hour) {
5754
- setRangeData(minutes, startMinute, endMinute + 1, true);
5755
- } else if (startHour !== hour && endHour === hour) {
5756
- setRangeData(minutes, 0, endMinute + 1, true);
5757
- } else if (startHour < hour && endHour > hour) {
5758
- setRangeData(minutes, 0, 60, true);
5759
- }
5760
- });
5761
- } else {
5762
- setRangeData(minutes, 0, 60, true);
5763
- }
5764
- return minutes;
5765
- };
5766
-
5767
- const range = function(n) {
5768
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5769
- return Array.apply(null, {length: n}).map((_, n) => n);
5770
- };
5771
-
5772
- const modifyDate = function(date, y, m, d) {
5773
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5774
- };
5775
-
5776
- const modifyTime = function(date, h, m, s) {
5777
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5778
- };
5779
-
5780
- const modifyWithTimeString = (date, time) => {
5781
- if (date == null || !time) {
5782
- return date;
5783
- }
5784
- time = parseDate(time, 'HH:mm:ss');
5785
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5786
- };
5787
-
5788
- const clearTime = function(date) {
5789
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5790
- };
5791
-
5792
- const clearMilliseconds = function(date) {
5793
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5794
- };
5795
-
5796
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
5797
- // TODO: refactory a more elegant solution
5798
- if (ranges.length === 0) return date;
5799
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
5800
- const ndate = normalizeDate(date);
5801
- const nranges = ranges.map(range => range.map(normalizeDate));
5802
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
5803
-
5804
- let minDate = nranges[0][0];
5805
- let maxDate = nranges[0][0];
5806
-
5807
- nranges.forEach(nrange => {
5808
- minDate = new Date(Math.min(nrange[0], minDate));
5809
- maxDate = new Date(Math.max(nrange[1], minDate));
5810
- });
5811
-
5812
- const ret = ndate < minDate ? minDate : maxDate;
5813
- // preserve Year/Month/Date
5814
- return modifyDate(
5815
- ret,
5816
- date.getFullYear(),
5817
- date.getMonth(),
5818
- date.getDate()
5819
- );
5820
- };
5821
-
5822
- const timeWithinRange = function(date, selectableRange, format) {
5823
- const limitedDate = limitTimeRange(date, selectableRange, format);
5824
- return limitedDate.getTime() === date.getTime();
5825
- };
5826
-
5827
- const changeYearMonthAndClampDate = function(date, year, month) {
5828
- // clamp date to the number of days in `year`, `month`
5829
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
5830
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5831
- return modifyDate(date, year, month, monthDate);
5832
- };
5833
-
5834
- const prevMonth = function(date) {
5835
- const year = date.getFullYear();
5836
- const month = date.getMonth();
5837
- return month === 0
5838
- ? changeYearMonthAndClampDate(date, year - 1, 11)
5839
- : changeYearMonthAndClampDate(date, year, month - 1);
5840
- };
5841
-
5842
- const nextMonth = function(date) {
5843
- const year = date.getFullYear();
5844
- const month = date.getMonth();
5845
- return month === 11
5846
- ? changeYearMonthAndClampDate(date, year + 1, 0)
5847
- : changeYearMonthAndClampDate(date, year, month + 1);
5848
- };
5849
-
5850
- const prevYear = function(date, amount = 1) {
5851
- const year = date.getFullYear();
5852
- const month = date.getMonth();
5853
- return changeYearMonthAndClampDate(date, year - amount, month);
5854
- };
5855
-
5856
- const nextYear = function(date, amount = 1) {
5857
- const year = date.getFullYear();
5858
- const month = date.getMonth();
5859
- return changeYearMonthAndClampDate(date, year + amount, month);
5860
- };
5861
-
5862
- const extractDateFormat = function(format) {
5863
- return format
5864
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
5865
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
5866
- .trim();
5867
- };
5868
-
5869
- const extractTimeFormat = function(format) {
5870
- return format
5871
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
5872
- .trim();
5873
- };
5874
-
5875
- const validateRangeInOneMonth = function(start, end) {
5876
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
5877
- };
5878
-
5468
+ */
5469
+ fecha.parse = function (dateStr, format) {
5470
+ if (typeof format !== 'string') {
5471
+ throw new Error('Invalid format in fecha.parse');
5472
+ }
5473
+
5474
+ format = fecha.masks[format] || format;
5475
+
5476
+ // Avoid regular expression denial of service, fail early for really long strings
5477
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5478
+ if (dateStr.length > 1000) {
5479
+ return null;
5480
+ }
5481
+
5482
+ var dateInfo = {};
5483
+ var parseInfo = [];
5484
+ var literals = [];
5485
+ format = format.replace(literal, function ($0, $1) {
5486
+ literals.push($1);
5487
+ return '@@@';
5488
+ });
5489
+ var newFormat = regexEscape(format).replace(token, function ($0) {
5490
+ if (parseFlags[$0]) {
5491
+ var info = parseFlags[$0];
5492
+ parseInfo.push(info[1]);
5493
+ return '(' + info[0] + ')';
5494
+ }
5495
+
5496
+ return $0;
5497
+ });
5498
+ newFormat = newFormat.replace(/@@@/g, function () {
5499
+ return literals.shift();
5500
+ });
5501
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
5502
+ if (!matches) {
5503
+ return null;
5504
+ }
5505
+
5506
+ for (var i = 1; i < matches.length; i++) {
5507
+ parseInfo[i - 1](dateInfo, matches[i]);
5508
+ }
5509
+
5510
+ var today = new Date();
5511
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5512
+ dateInfo.hour = +dateInfo.hour + 12;
5513
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5514
+ dateInfo.hour = 0;
5515
+ }
5516
+
5517
+ var date = void 0;
5518
+ if (dateInfo.timezoneOffset != null) {
5519
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5520
+ 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));
5521
+ } else {
5522
+ 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);
5523
+ }
5524
+ return date;
5525
+ };
5526
+
5527
+ // 导出fecha对象
5528
+
5529
+
5530
+ // 以下是从date-util.js合并的函数
5531
+ var newArray = function newArray(start, end) {
5532
+ var result = [];
5533
+ for (var i = start; i <= end; i++) {
5534
+ result.push(i);
5535
+ }
5536
+ return result;
5537
+ };
5538
+
5539
+ var getSettings = function getSettings() {
5540
+ return {
5541
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5542
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5543
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5544
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5545
+ amPm: ['上午', '下午']
5546
+ };
5547
+ };
5548
+
5549
+ var toDate = function toDate(date) {
5550
+ return isDate(date) ? new Date(date) : null;
5551
+ };
5552
+
5553
+ var isDate = function isDate(date) {
5554
+ if (date === null || date === undefined) return false;
5555
+ if (isNaN(new Date(date).getTime())) return false;
5556
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5557
+ return true;
5558
+ };
5559
+
5560
+ var isDateObject = function isDateObject(val) {
5561
+ return val instanceof Date;
5562
+ };
5563
+
5564
+ var formatDate = function formatDate(date) {
5565
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
5566
+
5567
+ // 处理多种输入类型
5568
+ if (!date) return '';
5569
+
5570
+ // 如果是时间戳,转成日期对象
5571
+ if (typeof date === 'number') {
5572
+ date = new Date(date);
5573
+ }
5574
+ // 如果是字符串,转成日期对象
5575
+ if (typeof date === 'string') {
5576
+ date = new Date(date);
5577
+ }
5578
+
5579
+ // 调用toDate进一步验证和转换
5580
+ date = toDate(date);
5581
+ if (!date) return '';
5582
+
5583
+ // 兼容大写和小写的格式标记
5584
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5585
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
5586
+
5587
+ // 使用fecha库进行格式化,支持中文配置
5588
+ var str = fecha.format(date, lowercaseFormat, getSettings());
5589
+ return str;
5590
+ };
5591
+
5592
+ var parseDate = function parseDate(string, format) {
5593
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5594
+ };
5595
+
5596
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
5597
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
5598
+ return 30;
5599
+ }
5600
+
5601
+ if (month === 1) {
5602
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5603
+ return 29;
5604
+ } else {
5605
+ return 28;
5606
+ }
5607
+ }
5608
+
5609
+ return 31;
5610
+ };
5611
+
5612
+ var getDayCountOfYear = function getDayCountOfYear(year) {
5613
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
5614
+ return isLeapYear ? 366 : 365;
5615
+ };
5616
+
5617
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
5618
+ var temp = new Date(date.getTime());
5619
+ temp.setDate(1);
5620
+ return temp.getDay();
5621
+ };
5622
+
5623
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5624
+ // {prev, next} Date should work for Daylight Saving Time
5625
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5626
+ var prevDate = function prevDate(date) {
5627
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5628
+
5629
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5630
+ };
5631
+
5632
+ var nextDate = function nextDate(date) {
5633
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5634
+
5635
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5636
+ };
5637
+
5638
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
5639
+ var result = new Date(year, month, 1);
5640
+ var day = result.getDay();
5641
+
5642
+ if (day === 0) {
5643
+ return prevDate(result, 7);
5644
+ } else {
5645
+ return prevDate(result, day);
5646
+ }
5647
+ };
5648
+
5649
+ var getWeekNumber = function getWeekNumber(date) {
5650
+ // 支持多种输入类型
5651
+ if (!date || !isDate(date)) {
5652
+ date = new Date();
5653
+ }
5654
+ if (typeof date === 'string') {
5655
+ date = new Date(date);
5656
+ }
5657
+
5658
+ // 验证日期有效性
5659
+ if (!isDate(date)) return null;
5660
+
5661
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5662
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5663
+ // 将星期日的星期数设为7
5664
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5665
+ // 获取当年的第一天
5666
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5667
+ // 计算到最近的星期四的完整周数
5668
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
5669
+ // 返回周数
5670
+ return weekNo;
5671
+ };
5672
+
5673
+ var getRangeHours = function getRangeHours(ranges) {
5674
+ var hours = [];
5675
+ var disabledHours = [];
5676
+
5677
+ (ranges || []).forEach(function (range) {
5678
+ var value = range.map(function (date) {
5679
+ return date.getHours();
5680
+ });
5681
+
5682
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5683
+ });
5684
+
5685
+ if (disabledHours.length) {
5686
+ for (var i = 0; i < 24; i++) {
5687
+ hours[i] = disabledHours.indexOf(i) === -1;
5688
+ }
5689
+ } else {
5690
+ for (var _i = 0; _i < 24; _i++) {
5691
+ hours[_i] = false;
5692
+ }
5693
+ }
5694
+
5695
+ return hours;
5696
+ };
5697
+
5698
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
5699
+ if (amount <= 0) return [];
5700
+ var temp = new Date(date.getTime());
5701
+ temp.setDate(0);
5702
+ var lastDay = temp.getDate();
5703
+ return range(amount).map(function (_, index) {
5704
+ return lastDay - (amount - index - 1);
5705
+ });
5706
+ };
5707
+
5708
+ var getMonthDays = function getMonthDays(date) {
5709
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5710
+ var days = temp.getDate();
5711
+ return range(days).map(function (_, index) {
5712
+ return index + 1;
5713
+ });
5714
+ };
5715
+
5716
+ function setRangeData(arr, start, end, value) {
5717
+ for (var i = start; i < end; i++) {
5718
+ arr[i] = value;
5719
+ }
5720
+ }
5721
+
5722
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
5723
+ var minutes = new Array(60);
5724
+
5725
+ if (ranges.length > 0) {
5726
+ ranges.forEach(function (range) {
5727
+ var start = range[0];
5728
+ var end = range[1];
5729
+ var startHour = start.getHours();
5730
+ var startMinute = start.getMinutes();
5731
+ var endHour = end.getHours();
5732
+ var endMinute = end.getMinutes();
5733
+ if (startHour === hour && endHour !== hour) {
5734
+ setRangeData(minutes, startMinute, 60, true);
5735
+ } else if (startHour === hour && endHour === hour) {
5736
+ setRangeData(minutes, startMinute, endMinute + 1, true);
5737
+ } else if (startHour !== hour && endHour === hour) {
5738
+ setRangeData(minutes, 0, endMinute + 1, true);
5739
+ } else if (startHour < hour && endHour > hour) {
5740
+ setRangeData(minutes, 0, 60, true);
5741
+ }
5742
+ });
5743
+ } else {
5744
+ setRangeData(minutes, 0, 60, true);
5745
+ }
5746
+ return minutes;
5747
+ };
5748
+
5749
+ var range = function range(n) {
5750
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5751
+ return Array.apply(null, { length: n }).map(function (_, n) {
5752
+ return n;
5753
+ });
5754
+ };
5755
+
5756
+ var modifyDate = function modifyDate(date, y, m, d) {
5757
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5758
+ };
5759
+
5760
+ var modifyTime = function modifyTime(date, h, m, s) {
5761
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5762
+ };
5763
+
5764
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
5765
+ if (date == null || !time) {
5766
+ return date;
5767
+ }
5768
+ time = parseDate(time, 'HH:mm:ss');
5769
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5770
+ };
5771
+
5772
+ var clearTime = function clearTime(date) {
5773
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5774
+ };
5775
+
5776
+ var clearMilliseconds = function clearMilliseconds(date) {
5777
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5778
+ };
5779
+
5780
+ var limitTimeRange = function limitTimeRange(date, ranges) {
5781
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
5782
+
5783
+ // TODO: refactory a more elegant solution
5784
+ if (ranges.length === 0) return date;
5785
+ var normalizeDate = function normalizeDate(date) {
5786
+ return fecha.parse(fecha.format(date, format), format);
5787
+ };
5788
+ var ndate = normalizeDate(date);
5789
+ var nranges = ranges.map(function (range) {
5790
+ return range.map(normalizeDate);
5791
+ });
5792
+ if (nranges.some(function (nrange) {
5793
+ return ndate >= nrange[0] && ndate <= nrange[1];
5794
+ })) return date;
5795
+
5796
+ var minDate = nranges[0][0];
5797
+ var maxDate = nranges[0][0];
5798
+
5799
+ nranges.forEach(function (nrange) {
5800
+ minDate = new Date(Math.min(nrange[0], minDate));
5801
+ maxDate = new Date(Math.max(nrange[1], minDate));
5802
+ });
5803
+
5804
+ var ret = ndate < minDate ? minDate : maxDate;
5805
+ // preserve Year/Month/Date
5806
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
5807
+ };
5808
+
5809
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
5810
+ var limitedDate = limitTimeRange(date, selectableRange, format);
5811
+ return limitedDate.getTime() === date.getTime();
5812
+ };
5813
+
5814
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
5815
+ // clamp date to the number of days in `year`, `month`
5816
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
5817
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5818
+ return modifyDate(date, year, month, monthDate);
5819
+ };
5820
+
5821
+ var prevMonth = function prevMonth(date) {
5822
+ var year = date.getFullYear();
5823
+ var month = date.getMonth();
5824
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
5825
+ };
5826
+
5827
+ var nextMonth = function nextMonth(date) {
5828
+ var year = date.getFullYear();
5829
+ var month = date.getMonth();
5830
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
5831
+ };
5832
+
5833
+ var prevYear = function prevYear(date) {
5834
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5835
+
5836
+ var year = date.getFullYear();
5837
+ var month = date.getMonth();
5838
+ return changeYearMonthAndClampDate(date, year - amount, month);
5839
+ };
5840
+
5841
+ var nextYear = function nextYear(date) {
5842
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5843
+
5844
+ var year = date.getFullYear();
5845
+ var month = date.getMonth();
5846
+ return changeYearMonthAndClampDate(date, year + amount, month);
5847
+ };
5848
+
5849
+ var extractDateFormat = function extractDateFormat(format) {
5850
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
5851
+ };
5852
+
5853
+ var extractTimeFormat = function extractTimeFormat(format) {
5854
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
5855
+ };
5856
+
5857
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
5858
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
5859
+ };
5860
+
5879
5861
  /**
5880
5862
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
5881
5863
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
5882
5864
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
5883
5865
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
5884
5866
  * @returns {number} 工作日数量
5885
- */
5886
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
5887
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5888
- throw new Error(
5889
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
5890
- );
5891
- }
5892
-
5893
- const startDateObj = new Date(start_date);
5894
- const endDateObj = new Date(end_date);
5895
-
5896
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5897
- throw new Error(
5898
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
5899
- );
5900
- }
5901
-
5902
- if (startDateObj > endDateObj) {
5903
- throw new Error('Start date should be earlier than or equal to end date.');
5904
- }
5905
-
5906
- let workdays = 0;
5907
-
5908
- // Iterate through each day in the date range
5909
- for (
5910
- let currentDate = new Date(startDateObj);
5911
- currentDate <= endDateObj;
5912
- currentDate.setDate(currentDate.getDate() + 1)
5913
- ) {
5914
- // Check if the current day is a weekend (Saturday or Sunday)
5915
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5916
-
5917
- // Check if the current day is a holiday
5918
- const isHoliday = holidays.some((holiday) => {
5919
- const holidayDate = new Date(holiday);
5920
- return currentDate.toDateString() === holidayDate.toDateString();
5921
- });
5922
-
5923
- // If it's a workday (not a weekend or holiday), increment the workdays count
5924
- if (!isWeekend && !isHoliday) {
5925
- workdays++;
5926
- }
5927
- }
5928
-
5929
- return workdays;
5930
- };
5931
-
5867
+ */
5868
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
5869
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5870
+
5871
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5872
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5873
+ }
5874
+
5875
+ var startDateObj = new Date(start_date);
5876
+ var endDateObj = new Date(end_date);
5877
+
5878
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5879
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5880
+ }
5881
+
5882
+ if (startDateObj > endDateObj) {
5883
+ throw new Error('Start date should be earlier than or equal to end date.');
5884
+ }
5885
+
5886
+ var workdays = 0;
5887
+
5888
+ // Iterate through each day in the date range
5889
+
5890
+ var _loop = function _loop(currentDate) {
5891
+ // Check if the current day is a weekend (Saturday or Sunday)
5892
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5893
+
5894
+ // Check if the current day is a holiday
5895
+ var isHoliday = holidays.some(function (holiday) {
5896
+ var holidayDate = new Date(holiday);
5897
+ return currentDate.toDateString() === holidayDate.toDateString();
5898
+ });
5899
+
5900
+ // If it's a workday (not a weekend or holiday), increment the workdays count
5901
+ if (!isWeekend && !isHoliday) {
5902
+ workdays++;
5903
+ }
5904
+ };
5905
+
5906
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
5907
+ _loop(currentDate);
5908
+ }
5909
+
5910
+ return workdays;
5911
+ };
5912
+
5932
5913
  /**
5933
5914
  * 日期加减天数
5934
5915
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
5935
5916
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
5936
5917
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
5937
- */
5938
- const dateAddDays = function (start_date, days) {
5939
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5940
- throw new Error(
5941
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
5942
- );
5943
- }
5944
-
5945
- const startDateObj = new Date(start_date);
5946
- if (isNaN(startDateObj.getTime())) {
5947
- throw new Error(
5948
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5949
- );
5950
- }
5951
-
5952
- const resultDateObj = new Date(startDateObj);
5953
- resultDateObj.setDate(resultDateObj.getDate() + days);
5954
-
5955
- const resultYear = resultDateObj.getFullYear();
5956
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5957
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5958
-
5959
- return `${resultYear}-${resultMonth}-${resultDay}`;
5960
- };
5961
-
5918
+ */
5919
+ var dateAddDays = function dateAddDays(start_date, days) {
5920
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5921
+ 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.");
5922
+ }
5923
+
5924
+ var startDateObj = new Date(start_date);
5925
+ if (isNaN(startDateObj.getTime())) {
5926
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5927
+ }
5928
+
5929
+ var resultDateObj = new Date(startDateObj);
5930
+ resultDateObj.setDate(resultDateObj.getDate() + days);
5931
+
5932
+ var resultYear = resultDateObj.getFullYear();
5933
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5934
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5935
+
5936
+ return resultYear + '-' + resultMonth + '-' + resultDay;
5937
+ };
5938
+
5962
5939
  /**
5963
5940
  * 计算两个日期之间的差值
5964
5941
  * @date 2023年12月14日
@@ -5966,182 +5943,180 @@ const dateAddDays = function (start_date, days) {
5966
5943
  * @param {String} end_date - 结束日期字符串
5967
5944
  * @param {String} unit - 单位:year/month/day
5968
5945
  * @returns {Number} 差值
5969
- */
5970
- const dateDiff = function (start_date, end_date, unit = 'day') {
5971
- // Assuming date strings are in "YYYY-MM-DD" format
5972
- var startDate = new Date(start_date);
5973
- var endDate = new Date(end_date);
5974
-
5975
- // If the date is invalid, return 0
5976
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5977
- return 0;
5978
- }
5979
-
5980
- if (unit === 'year') {
5981
- return endDate.getFullYear() - startDate.getFullYear();
5982
- } else if (unit === 'month') {
5983
- return (
5984
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
5985
- (endDate.getMonth() - startDate.getMonth())
5986
- );
5987
- } else {
5988
- // Default to day
5989
- var timeDifference = endDate - startDate;
5990
- // Calculate days (86400000 milliseconds per day)
5991
- return Math.floor(timeDifference / 86400000);
5992
- }
5993
- };
5994
-
5946
+ */
5947
+ var dateDiff = function dateDiff(start_date, end_date) {
5948
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
5949
+
5950
+ // Assuming date strings are in "YYYY-MM-DD" format
5951
+ var startDate = new Date(start_date);
5952
+ var endDate = new Date(end_date);
5953
+
5954
+ // If the date is invalid, return 0
5955
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5956
+ return 0;
5957
+ }
5958
+
5959
+ if (unit === 'year') {
5960
+ return endDate.getFullYear() - startDate.getFullYear();
5961
+ } else if (unit === 'month') {
5962
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
5963
+ } else {
5964
+ // Default to day
5965
+ var timeDifference = endDate - startDate;
5966
+ // Calculate days (86400000 milliseconds per day)
5967
+ return Math.floor(timeDifference / 86400000);
5968
+ }
5969
+ };
5970
+
5995
5971
  /**
5996
5972
  * 获取月份中的日期
5997
5973
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
5998
5974
  * @returns {number} 月份中的日期(1-31)
5999
- */
6000
- const dayOfMonth = function (date) {
6001
- if (typeof date !== 'string') {
6002
- throw new Error(
6003
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
6004
- );
6005
- }
6006
-
6007
- const dateObj = new Date(date);
6008
- if (isNaN(dateObj.getTime())) {
6009
- throw new Error(
6010
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6011
- );
6012
- }
6013
-
6014
- return dateObj.getDate();
6015
- };
6016
-
5975
+ */
5976
+ var dayOfMonth = function dayOfMonth(date) {
5977
+ if (typeof date !== 'string') {
5978
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5979
+ }
5980
+
5981
+ var dateObj = new Date(date);
5982
+ if (isNaN(dateObj.getTime())) {
5983
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5984
+ }
5985
+
5986
+ return dateObj.getDate();
5987
+ };
5988
+
6017
5989
  /**
6018
5990
  * 获取当前日期
6019
5991
  * @date 2022年5月7日
6020
5992
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
6021
5993
  * @returns {string} 当前日期的格式化字符串
6022
- */
6023
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
6024
- return formatDate(new Date(), format);
6025
- };
6026
-
5994
+ */
5995
+ var getCurrentDate = function getCurrentDate() {
5996
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
5997
+
5998
+ return formatDate(new Date(), format);
5999
+ };
6000
+
6027
6001
  /**
6028
6002
  * 获取当前日期时间
6029
6003
  * @date 2022年5月7日
6030
6004
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
6031
6005
  * @returns {string} 当前日期时间的格式化字符串
6032
- */
6033
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
6034
- return formatDate(new Date(), format);
6035
- };
6036
-
6006
+ */
6007
+ var getCurrentDateTime = function getCurrentDateTime() {
6008
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
6009
+
6010
+ return formatDate(new Date(), format);
6011
+ };
6012
+
6037
6013
  /**
6038
6014
  * 获取小时
6039
6015
  * @date 2022年5月7日
6040
6016
  * @param {Date|string} [date] - 日期对象或日期字符串
6041
6017
  * @returns {number} 小时数(0-23)
6042
- */
6043
- const getHour = function (date) {
6044
- if (!date) {
6045
- return new Date().getHours();
6046
- }
6047
- if (typeof date === 'string') {
6048
- date = new Date(date);
6049
- }
6050
- return date.getHours();
6051
- };
6052
-
6018
+ */
6019
+ var getHour = function getHour(date) {
6020
+ if (!date) {
6021
+ return new Date().getHours();
6022
+ }
6023
+ if (typeof date === 'string') {
6024
+ date = new Date(date);
6025
+ }
6026
+ return date.getHours();
6027
+ };
6028
+
6053
6029
  /**
6054
6030
  * 获取分钟
6055
6031
  * @date 2022年5月7日
6056
6032
  * @param {Date|string} [date] - 日期对象或日期字符串
6057
6033
  * @returns {number} 分钟数(0-59)
6058
- */
6059
- const getMinute = function (date) {
6060
- if (!date) {
6061
- return new Date().getMinutes();
6062
- }
6063
- if (typeof date === 'string') {
6064
- date = new Date(date);
6065
- }
6066
- return date.getMinutes();
6067
- };
6068
-
6034
+ */
6035
+ var getMinute = function getMinute(date) {
6036
+ if (!date) {
6037
+ return new Date().getMinutes();
6038
+ }
6039
+ if (typeof date === 'string') {
6040
+ date = new Date(date);
6041
+ }
6042
+ return date.getMinutes();
6043
+ };
6044
+
6069
6045
  /**
6070
6046
  * 获取月份
6071
6047
  * @date 2022年5月7日
6072
6048
  * @param {Date|string} [date] - 日期对象或日期字符串
6073
6049
  * @returns {number} 月份数(1-12)
6074
- */
6075
- const getMonth = function (date) {
6076
- if (!date) {
6077
- return new Date().getMonth() + 1;
6078
- }
6079
- if (typeof date === 'string') {
6080
- date = new Date(date);
6081
- }
6082
- return date.getMonth() + 1;
6083
- };
6084
-
6050
+ */
6051
+ var getMonth = function getMonth(date) {
6052
+ if (!date) {
6053
+ return new Date().getMonth() + 1;
6054
+ }
6055
+ if (typeof date === 'string') {
6056
+ date = new Date(date);
6057
+ }
6058
+ return date.getMonth() + 1;
6059
+ };
6060
+
6085
6061
  /**
6086
6062
  * 获取秒
6087
6063
  * @date 2022年5月7日
6088
6064
  * @param {Date|string} [date] - 日期对象或日期字符串
6089
6065
  * @returns {number} 秒数(0-59)
6090
- */
6091
- const getSecond = function (date) {
6092
- if (!date) {
6093
- return new Date().getSeconds();
6094
- }
6095
- if (typeof date === 'string') {
6096
- date = new Date(date);
6097
- }
6098
- return date.getSeconds();
6099
- };
6100
-
6066
+ */
6067
+ var getSecond = function getSecond(date) {
6068
+ if (!date) {
6069
+ return new Date().getSeconds();
6070
+ }
6071
+ if (typeof date === 'string') {
6072
+ date = new Date(date);
6073
+ }
6074
+ return date.getSeconds();
6075
+ };
6076
+
6101
6077
  /**
6102
6078
  * 获取星期几
6103
6079
  * @date 2022年5月7日
6104
6080
  * @param {Date|string} [date] - 日期对象或日期字符串
6105
6081
  * @returns {number} 星期几(0-6,0表示星期日)
6106
- */
6107
- const getWeekday = function (date) {
6108
- if (!date) {
6109
- return new Date().getDay();
6110
- }
6111
- if (typeof date === 'string') {
6112
- date = new Date(date);
6113
- }
6114
- return date.getDay();
6115
- };
6116
-
6117
-
6082
+ */
6083
+ var getWeekday = function getWeekday(date) {
6084
+ if (!date) {
6085
+ return new Date().getDay();
6086
+ }
6087
+ if (typeof date === 'string') {
6088
+ date = new Date(date);
6089
+ }
6090
+ return date.getDay();
6091
+ };
6092
+
6118
6093
  /**
6119
6094
  * @desc 获取上午/下午/晚上
6120
6095
  * @author huangbo
6121
6096
  * @date 2022年5月7日
6122
6097
  * @param {String} [time] - 时间
6123
- **/
6124
- const timeCycle = function (time) {
6125
- let hour = 0;
6126
- if (!time) {
6127
- hour = new Date().getHours();
6128
- } else if (typeof time === 'string') {
6129
- // 从时间字符串中提取小时
6130
- const match = time.match(/^(\d{1,2})/);
6131
- if (match) {
6132
- hour = parseInt(match[1], 10);
6133
- }
6134
- } else if (typeof time === 'number') {
6135
- hour = time;
6136
- }
6137
- // 判断时间段
6138
- if (hour >= 5 && hour < 12) {
6139
- return '上午';
6140
- } else if (hour >= 12 && hour < 18) {
6141
- return '下午';
6142
- } else {
6143
- return '晚上';
6144
- }
6098
+ **/
6099
+ var timeCycle = function timeCycle(time) {
6100
+ var hour = 0;
6101
+ if (!time) {
6102
+ hour = new Date().getHours();
6103
+ } else if (typeof time === 'string') {
6104
+ // 从时间字符串中提取小时
6105
+ var match = time.match(/^(\d{1,2})/);
6106
+ if (match) {
6107
+ hour = parseInt(match[1], 10);
6108
+ }
6109
+ } else if (typeof time === 'number') {
6110
+ hour = time;
6111
+ }
6112
+ // 判断时间段
6113
+ if (hour >= 5 && hour < 12) {
6114
+ return '上午';
6115
+ } else if (hour >= 12 && hour < 18) {
6116
+ return '下午';
6117
+ } else {
6118
+ return '晚上';
6119
+ }
6145
6120
  };
6146
6121
 
6147
6122
  /***/ }),