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