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