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