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