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
@@ -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 = 254);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 261);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -4668,7 +4668,7 @@ var getRgb = function getRgb($color) {
4668
4668
 
4669
4669
  /***/ }),
4670
4670
 
4671
- /***/ 121:
4671
+ /***/ 125:
4672
4672
  /***/ (function(module, exports) {
4673
4673
 
4674
4674
  module.exports = require("eoss/lib/qr-code");
@@ -4776,7 +4776,7 @@ module.exports = require("fetch-request-source");
4776
4776
 
4777
4777
  /***/ }),
4778
4778
 
4779
- /***/ 254:
4779
+ /***/ 261:
4780
4780
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4781
4781
 
4782
4782
  "use strict";
@@ -4825,7 +4825,7 @@ render._withStripped = true
4825
4825
  var ajax = __webpack_require__(10);
4826
4826
 
4827
4827
  // EXTERNAL MODULE: external "eoss/lib/qr-code"
4828
- var qr_code_ = __webpack_require__(121);
4828
+ var qr_code_ = __webpack_require__(125);
4829
4829
  var qr_code_default = /*#__PURE__*/__webpack_require__.n(qr_code_);
4830
4830
 
4831
4831
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/qrcode-login/src/qrcode-login.vue?vue&type=script&lang=js&
@@ -5890,759 +5890,736 @@ var changeInTime = '/baseIssueRules/changeInTime';
5890
5890
  /* unused harmony export getSecond */
5891
5891
  /* unused harmony export getWeekday */
5892
5892
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
5893
- /* Modified from https://github.com/taylorhakes/fecha
5894
- *
5895
- * The MIT License (MIT)
5896
- *
5897
- * Copyright (c) 2015 Taylor Hakes
5898
- *
5899
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5900
- * of this software and associated documentation files (the "Software"), to deal
5901
- * in the Software without restriction, including without limitation the rights
5902
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5903
- * copies of the Software, and to permit persons to whom the Software is
5904
- * furnished to do so, subject to the following conditions:
5905
- *
5906
- * The above copyright notice and this permission notice shall be included in all
5907
- * copies or substantial portions of the Software.
5908
- *
5909
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5910
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5911
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5912
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5913
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5914
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5915
- * SOFTWARE.
5916
- */
5917
-
5918
- /*eslint-disable*/
5919
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
5920
-
5921
-
5893
+
5894
+
5922
5895
  /**
5923
5896
  * Parse or format dates
5924
5897
  * @class fecha
5925
- */
5926
- const fecha = {};
5927
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5928
- const twoDigits = '\\d\\d?';
5929
- const threeDigits = '\\d{3}';
5930
- const fourDigits = '\\d{4}';
5931
- const word = '[^\\s]+';
5932
- const literal = /\[([^]*?)\]/gm;
5933
- const noop = function () {};
5934
-
5935
- function regexEscape(str) {
5936
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5937
- }
5938
-
5939
- function shorten(arr, sLen) {
5940
- const newArr = [];
5941
- for (let i = 0, len = arr.length; i < len; i++) {
5942
- newArr.push(arr[i].substr(0, sLen));
5943
- }
5944
- return newArr;
5945
- }
5946
-
5947
- function monthUpdate() {
5948
- return function (d, v) {
5949
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5950
- if (~index) {
5951
- d.month = index;
5952
- }
5953
- };
5954
- }
5955
-
5956
- function pad(val, len) {
5957
- val = String(val);
5958
- len = len || 2;
5959
- while (val.length < len) {
5960
- val = '0' + val;
5961
- }
5962
- return val;
5963
- }
5964
-
5965
- // 直接使用中文日期名称常量
5966
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5967
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5968
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5969
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5970
- const amPm = ['上午', '下午'];
5971
- const DoFn = function DoFn(D) {
5972
- return D + '日';
5973
- };
5974
-
5975
- const formatFlags = {
5976
- D: function(dateObj) {
5977
- return dateObj.getDay();
5978
- },
5979
- DD: function(dateObj) {
5980
- return pad(dateObj.getDay());
5981
- },
5982
- Do: function(dateObj) {
5983
- return DoFn(dateObj.getDate());
5984
- },
5985
- d: function(dateObj) {
5986
- return dateObj.getDate();
5987
- },
5988
- dd: function(dateObj) {
5989
- return pad(dateObj.getDate());
5990
- },
5991
- ddd: function(dateObj) {
5992
- return dayNamesShort[dateObj.getDay()];
5993
- },
5994
- dddd: function(dateObj) {
5995
- return dayNames[dateObj.getDay()];
5996
- },
5997
- M: function(dateObj) {
5998
- return dateObj.getMonth() + 1;
5999
- },
6000
- MM: function(dateObj) {
6001
- return pad(dateObj.getMonth() + 1);
6002
- },
6003
- MMM: function(dateObj) {
6004
- return monthNamesShort[dateObj.getMonth()];
6005
- },
6006
- MMMM: function(dateObj) {
6007
- return monthNames[dateObj.getMonth()];
6008
- },
6009
- yy: function(dateObj) {
6010
- return pad(String(dateObj.getFullYear()), 4).substr(2);
6011
- },
6012
- yyyy: function(dateObj) {
6013
- return pad(dateObj.getFullYear(), 4);
6014
- },
6015
- h: function(dateObj) {
6016
- return dateObj.getHours() % 12 || 12;
6017
- },
6018
- hh: function(dateObj) {
6019
- return pad(dateObj.getHours() % 12 || 12);
6020
- },
6021
- H: function(dateObj) {
6022
- return dateObj.getHours();
6023
- },
6024
- HH: function(dateObj) {
6025
- return pad(dateObj.getHours());
6026
- },
6027
- m: function(dateObj) {
6028
- return dateObj.getMinutes();
6029
- },
6030
- mm: function(dateObj) {
6031
- return pad(dateObj.getMinutes());
6032
- },
6033
- s: function(dateObj) {
6034
- return dateObj.getSeconds();
6035
- },
6036
- ss: function(dateObj) {
6037
- return pad(dateObj.getSeconds());
6038
- },
6039
- S: function(dateObj) {
6040
- return Math.round(dateObj.getMilliseconds() / 100);
6041
- },
6042
- SS: function(dateObj) {
6043
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
6044
- },
6045
- SSS: function(dateObj) {
6046
- return pad(dateObj.getMilliseconds(), 3);
6047
- },
6048
- a: function(dateObj) {
6049
- return dateObj.getHours() < 12 ? '上午' : '下午';
6050
- },
6051
- A: function(dateObj) {
6052
- return dateObj.getHours() < 12 ? '上午' : '下午';
6053
- },
6054
- ZZ: function(dateObj) {
6055
- const o = dateObj.getTimezoneOffset();
6056
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
6057
- }
6058
- };
6059
-
6060
- const parseFlags = {
6061
- d: [twoDigits, function (d, v) {
6062
- d.day = v;
6063
- }],
6064
- Do: [twoDigits + word, function (d, v) {
6065
- d.day = parseInt(v, 10);
6066
- }],
6067
- M: [twoDigits, function (d, v) {
6068
- d.month = v - 1;
6069
- }],
6070
- yy: [twoDigits, function (d, v) {
6071
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
6072
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
6073
- }],
6074
- h: [twoDigits, function (d, v) {
6075
- d.hour = v;
6076
- }],
6077
- m: [twoDigits, function (d, v) {
6078
- d.minute = v;
6079
- }],
6080
- s: [twoDigits, function (d, v) {
6081
- d.second = v;
6082
- }],
6083
- yyyy: [fourDigits, function (d, v) {
6084
- d.year = v;
6085
- }],
6086
- S: ['\\d', function (d, v) {
6087
- d.millisecond = v * 100;
6088
- }],
6089
- SS: ['\\d{2}', function (d, v) {
6090
- d.millisecond = v * 10;
6091
- }],
6092
- SSS: [threeDigits, function (d, v) {
6093
- d.millisecond = v;
6094
- }],
6095
- D: [twoDigits, noop],
6096
- ddd: [word, noop],
6097
- MMM: [word, monthUpdate('monthNamesShort')],
6098
- MMMM: [word, monthUpdate('monthNames')],
6099
- a: [word, function (d, v) {
6100
- const val = v.toLowerCase();
6101
- if (val === '上午') {
6102
- d.isPm = false;
6103
- } else if (val === '下午') {
6104
- d.isPm = true;
6105
- }
6106
- }],
6107
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
6108
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
6109
-
6110
- if (parts) {
6111
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
6112
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
6113
- }
6114
- }]
6115
- };
6116
- parseFlags.dd = parseFlags.d;
6117
- parseFlags.dddd = parseFlags.ddd;
6118
- parseFlags.DD = parseFlags.D;
6119
- parseFlags.mm = parseFlags.m;
6120
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
6121
- parseFlags.MM = parseFlags.M;
6122
- parseFlags.ss = parseFlags.s;
6123
- parseFlags.A = parseFlags.a;
6124
-
6125
-
6126
- // Some common format strings
6127
- fecha.masks = {
6128
- default: 'ddd MMM dd yyyy HH:mm:ss',
6129
- shortDate: 'M/D/yy',
6130
- mediumDate: 'MMM d, yyyy',
6131
- longDate: 'MMMM d, yyyy',
6132
- fullDate: 'dddd, MMMM d, yyyy',
6133
- shortTime: 'HH:mm',
6134
- mediumTime: 'HH:mm:ss',
6135
- longTime: 'HH:mm:ss.SSS'
6136
- };
6137
-
5898
+ */
5899
+ var fecha = {};
5900
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5901
+ var twoDigits = '\\d\\d?';
5902
+ var threeDigits = '\\d{3}';
5903
+ var fourDigits = '\\d{4}';
5904
+ var word = '[^\\s]+';
5905
+ var literal = /\[([^]*?)\]/gm;
5906
+ var noop = function noop() {};
5907
+
5908
+ function regexEscape(str) {
5909
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5910
+ }
5911
+
5912
+ function shorten(arr, sLen) {
5913
+ var newArr = [];
5914
+ for (var i = 0, len = arr.length; i < len; i++) {
5915
+ newArr.push(arr[i].substr(0, sLen));
5916
+ }
5917
+ return newArr;
5918
+ }
5919
+
5920
+ function monthUpdate() {
5921
+ return function (d, v) {
5922
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5923
+ if (~index) {
5924
+ d.month = index;
5925
+ }
5926
+ };
5927
+ }
5928
+
5929
+ function pad(val, len) {
5930
+ val = String(val);
5931
+ len = len || 2;
5932
+ while (val.length < len) {
5933
+ val = '0' + val;
5934
+ }
5935
+ return val;
5936
+ }
5937
+
5938
+ // 直接使用中文日期名称常量
5939
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5940
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5941
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5942
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5943
+ var amPm = ['上午', '下午'];
5944
+ var DoFn = function DoFn(D) {
5945
+ return D + '日';
5946
+ };
5947
+
5948
+ var formatFlags = {
5949
+ D: function D(dateObj) {
5950
+ return dateObj.getDay();
5951
+ },
5952
+ DD: function DD(dateObj) {
5953
+ return pad(dateObj.getDay());
5954
+ },
5955
+ Do: function Do(dateObj) {
5956
+ return DoFn(dateObj.getDate());
5957
+ },
5958
+ d: function d(dateObj) {
5959
+ return dateObj.getDate();
5960
+ },
5961
+ dd: function dd(dateObj) {
5962
+ return pad(dateObj.getDate());
5963
+ },
5964
+ ddd: function ddd(dateObj) {
5965
+ return dayNamesShort[dateObj.getDay()];
5966
+ },
5967
+ dddd: function dddd(dateObj) {
5968
+ return dayNames[dateObj.getDay()];
5969
+ },
5970
+ M: function M(dateObj) {
5971
+ return dateObj.getMonth() + 1;
5972
+ },
5973
+ MM: function MM(dateObj) {
5974
+ return pad(dateObj.getMonth() + 1);
5975
+ },
5976
+ MMM: function MMM(dateObj) {
5977
+ return monthNamesShort[dateObj.getMonth()];
5978
+ },
5979
+ MMMM: function MMMM(dateObj) {
5980
+ return monthNames[dateObj.getMonth()];
5981
+ },
5982
+ yy: function yy(dateObj) {
5983
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
5984
+ },
5985
+ yyyy: function yyyy(dateObj) {
5986
+ return pad(dateObj.getFullYear(), 4);
5987
+ },
5988
+ h: function h(dateObj) {
5989
+ return dateObj.getHours() % 12 || 12;
5990
+ },
5991
+ hh: function hh(dateObj) {
5992
+ return pad(dateObj.getHours() % 12 || 12);
5993
+ },
5994
+ H: function H(dateObj) {
5995
+ return dateObj.getHours();
5996
+ },
5997
+ HH: function HH(dateObj) {
5998
+ return pad(dateObj.getHours());
5999
+ },
6000
+ m: function m(dateObj) {
6001
+ return dateObj.getMinutes();
6002
+ },
6003
+ mm: function mm(dateObj) {
6004
+ return pad(dateObj.getMinutes());
6005
+ },
6006
+ s: function s(dateObj) {
6007
+ return dateObj.getSeconds();
6008
+ },
6009
+ ss: function ss(dateObj) {
6010
+ return pad(dateObj.getSeconds());
6011
+ },
6012
+ S: function S(dateObj) {
6013
+ return Math.round(dateObj.getMilliseconds() / 100);
6014
+ },
6015
+ SS: function SS(dateObj) {
6016
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
6017
+ },
6018
+ SSS: function SSS(dateObj) {
6019
+ return pad(dateObj.getMilliseconds(), 3);
6020
+ },
6021
+ a: function a(dateObj) {
6022
+ return dateObj.getHours() < 12 ? '上午' : '下午';
6023
+ },
6024
+ A: function A(dateObj) {
6025
+ return dateObj.getHours() < 12 ? '上午' : '下午';
6026
+ },
6027
+ ZZ: function ZZ(dateObj) {
6028
+ var o = dateObj.getTimezoneOffset();
6029
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
6030
+ }
6031
+ };
6032
+
6033
+ var parseFlags = {
6034
+ d: [twoDigits, function (d, v) {
6035
+ d.day = v;
6036
+ }],
6037
+ Do: [twoDigits + word, function (d, v) {
6038
+ d.day = parseInt(v, 10);
6039
+ }],
6040
+ M: [twoDigits, function (d, v) {
6041
+ d.month = v - 1;
6042
+ }],
6043
+ yy: [twoDigits, function (d, v) {
6044
+ var da = new Date(),
6045
+ cent = +('' + da.getFullYear()).substr(0, 2);
6046
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
6047
+ }],
6048
+ h: [twoDigits, function (d, v) {
6049
+ d.hour = v;
6050
+ }],
6051
+ m: [twoDigits, function (d, v) {
6052
+ d.minute = v;
6053
+ }],
6054
+ s: [twoDigits, function (d, v) {
6055
+ d.second = v;
6056
+ }],
6057
+ yyyy: [fourDigits, function (d, v) {
6058
+ d.year = v;
6059
+ }],
6060
+ S: ['\\d', function (d, v) {
6061
+ d.millisecond = v * 100;
6062
+ }],
6063
+ SS: ['\\d{2}', function (d, v) {
6064
+ d.millisecond = v * 10;
6065
+ }],
6066
+ SSS: [threeDigits, function (d, v) {
6067
+ d.millisecond = v;
6068
+ }],
6069
+ D: [twoDigits, noop],
6070
+ ddd: [word, noop],
6071
+ MMM: [word, monthUpdate('monthNamesShort')],
6072
+ MMMM: [word, monthUpdate('monthNames')],
6073
+ a: [word, function (d, v) {
6074
+ var val = v.toLowerCase();
6075
+ if (val === '上午') {
6076
+ d.isPm = false;
6077
+ } else if (val === '下午') {
6078
+ d.isPm = true;
6079
+ }
6080
+ }],
6081
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
6082
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
6083
+ minutes = void 0;
6084
+
6085
+ if (parts) {
6086
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
6087
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
6088
+ }
6089
+ }]
6090
+ };
6091
+ parseFlags.dd = parseFlags.d;
6092
+ parseFlags.dddd = parseFlags.ddd;
6093
+ parseFlags.DD = parseFlags.D;
6094
+ parseFlags.mm = parseFlags.m;
6095
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
6096
+ parseFlags.MM = parseFlags.M;
6097
+ parseFlags.ss = parseFlags.s;
6098
+ parseFlags.A = parseFlags.a;
6099
+
6100
+ // Some common format strings
6101
+ fecha.masks = {
6102
+ default: 'ddd MMM dd yyyy HH:mm:ss',
6103
+ shortDate: 'M/D/yy',
6104
+ mediumDate: 'MMM d, yyyy',
6105
+ longDate: 'MMMM d, yyyy',
6106
+ fullDate: 'dddd, MMMM d, yyyy',
6107
+ shortTime: 'HH:mm',
6108
+ mediumTime: 'HH:mm:ss',
6109
+ longTime: 'HH:mm:ss.SSS'
6110
+ };
6111
+
6138
6112
  /***
6139
6113
  * Format a date
6140
6114
  * @method format
6141
6115
  * @param {Date|number} dateObj
6142
6116
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
6143
- */
6144
- fecha.format = function (dateObj, mask) {
6145
- if (typeof dateObj === 'number') {
6146
- dateObj = new Date(dateObj);
6147
- }
6148
-
6149
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
6150
- throw new Error('Invalid Date in fecha.format');
6151
- }
6152
-
6153
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
6154
-
6155
- const literals = [];
6156
-
6157
- // Make literals inactive by replacing them with ??
6158
- mask = mask.replace(literal, function($0, $1) {
6159
- literals.push($1);
6160
- return '@@@';
6161
- });
6162
- // Apply formatting rules
6163
- mask = mask.replace(token, function ($0) {
6164
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
6165
- });
6166
- // Inline literal values back into the formatted value
6167
- return mask.replace(/@@@/g, function() {
6168
- return literals.shift();
6169
- });
6170
- };
6171
-
6117
+ */
6118
+ fecha.format = function (dateObj, mask) {
6119
+ if (typeof dateObj === 'number') {
6120
+ dateObj = new Date(dateObj);
6121
+ }
6122
+
6123
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
6124
+ throw new Error('Invalid Date in fecha.format');
6125
+ }
6126
+
6127
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
6128
+
6129
+ var literals = [];
6130
+
6131
+ // Make literals inactive by replacing them with ??
6132
+ mask = mask.replace(literal, function ($0, $1) {
6133
+ literals.push($1);
6134
+ return '@@@';
6135
+ });
6136
+ // Apply formatting rules
6137
+ mask = mask.replace(token, function ($0) {
6138
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
6139
+ });
6140
+ // Inline literal values back into the formatted value
6141
+ return mask.replace(/@@@/g, function () {
6142
+ return literals.shift();
6143
+ });
6144
+ };
6145
+
6172
6146
  /**
6173
6147
  * Parse a date string into an object, changes - into /
6174
6148
  * @method parse
6175
6149
  * @param {string} dateStr Date string
6176
6150
  * @param {string} format Date parse format
6177
6151
  * @returns {Date|boolean}
6178
- */
6179
- fecha.parse = function (dateStr, format) {
6180
- if (typeof format !== 'string') {
6181
- throw new Error('Invalid format in fecha.parse');
6182
- }
6183
-
6184
- format = fecha.masks[format] || format;
6185
-
6186
- // Avoid regular expression denial of service, fail early for really long strings
6187
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
6188
- if (dateStr.length > 1000) {
6189
- return null;
6190
- }
6191
-
6192
- const dateInfo = {};
6193
- const parseInfo = [];
6194
- const literals = [];
6195
- format = format.replace(literal, function($0, $1) {
6196
- literals.push($1);
6197
- return '@@@';
6198
- });
6199
- let newFormat = regexEscape(format).replace(token, function ($0) {
6200
- if (parseFlags[$0]) {
6201
- const info = parseFlags[$0];
6202
- parseInfo.push(info[1]);
6203
- return '(' + info[0] + ')';
6204
- }
6205
-
6206
- return $0;
6207
- });
6208
- newFormat = newFormat.replace(/@@@/g, function() {
6209
- return literals.shift();
6210
- });
6211
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
6212
- if (!matches) {
6213
- return null;
6214
- }
6215
-
6216
- for (let i = 1; i < matches.length; i++) {
6217
- parseInfo[i - 1](dateInfo, matches[i]);
6218
- }
6219
-
6220
- const today = new Date();
6221
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
6222
- dateInfo.hour = +dateInfo.hour + 12;
6223
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
6224
- dateInfo.hour = 0;
6225
- }
6226
-
6227
- let date;
6228
- if (dateInfo.timezoneOffset != null) {
6229
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
6230
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
6231
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
6232
- } else {
6233
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
6234
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
6235
- }
6236
- return date;
6237
- };
6238
-
6239
- // 导出fecha对象
6240
-
6241
-
6242
- // 以下是从date-util.js合并的函数
6243
- const newArray = function(start, end) {
6244
- let result = [];
6245
- for (let i = start; i <= end; i++) {
6246
- result.push(i);
6247
- }
6248
- return result;
6249
- };
6250
-
6251
- const getSettings = () => {
6252
- return {
6253
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
6254
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
6255
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
6256
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
6257
- amPm: ['上午', '下午']
6258
- };
6259
- };
6260
-
6261
- const toDate = function(date) {
6262
- return isDate(date) ? new Date(date) : null;
6263
- };
6264
-
6265
- const isDate = function(date) {
6266
- if (date === null || date === undefined) return false;
6267
- if (isNaN(new Date(date).getTime())) return false;
6268
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
6269
- return true;
6270
- };
6271
-
6272
- const isDateObject = function(val) {
6273
- return val instanceof Date;
6274
- };
6275
-
6276
- const formatDate = function (date, format = 'yyyy-MM-dd') {
6277
- // 处理多种输入类型
6278
- if (!date) return '';
6279
-
6280
- // 如果是时间戳,转成日期对象
6281
- if (typeof date === 'number') {
6282
- date = new Date(date);
6283
- }
6284
- // 如果是字符串,转成日期对象
6285
- if (typeof date === 'string') {
6286
- date = new Date(date);
6287
- }
6288
-
6289
- // 调用toDate进一步验证和转换
6290
- date = toDate(date);
6291
- if (!date) return '';
6292
-
6293
- // 兼容大写和小写的格式标记
6294
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
6295
- const lowercaseFormat = format
6296
- .replace(/YYYY/g, 'yyyy')
6297
- .replace(/D/g, 'd')
6298
-
6299
- // 使用fecha库进行格式化,支持中文配置
6300
- const str = fecha.format(date, lowercaseFormat, getSettings());
6301
- return str;
6302
- };
6303
-
6304
- const parseDate = function(string, format) {
6305
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
6306
- };
6307
-
6308
- const getDayCountOfMonth = function(year, month) {
6309
- if (month === 3 || month === 5 || month === 8 || month === 10) {
6310
- return 30;
6311
- }
6312
-
6313
- if (month === 1) {
6314
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
6315
- return 29;
6316
- } else {
6317
- return 28;
6318
- }
6319
- }
6320
-
6321
- return 31;
6322
- };
6323
-
6324
- const getDayCountOfYear = function(year) {
6325
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
6326
- return isLeapYear ? 366 : 365;
6327
- };
6328
-
6329
- const getFirstDayOfMonth = function(date) {
6330
- const temp = new Date(date.getTime());
6331
- temp.setDate(1);
6332
- return temp.getDay();
6333
- };
6334
-
6335
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
6336
- // {prev, next} Date should work for Daylight Saving Time
6337
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
6338
- const prevDate = function(date, amount = 1) {
6339
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
6340
- };
6341
-
6342
- const nextDate = function(date, amount = 1) {
6343
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
6344
- };
6345
-
6346
- const getStartDateOfMonth = function(year, month) {
6347
- const result = new Date(year, month, 1);
6348
- const day = result.getDay();
6349
-
6350
- if (day === 0) {
6351
- return prevDate(result, 7);
6352
- } else {
6353
- return prevDate(result, day);
6354
- }
6355
- };
6356
-
6357
- const getWeekNumber = function(date) {
6358
- // 支持多种输入类型
6359
- if (!date||!isDate(date)) {
6360
- date = new Date();
6361
- }
6362
- if (typeof date === 'string') {
6363
- date = new Date(date);
6364
- }
6365
-
6366
- // 验证日期有效性
6367
- if (!isDate(date)) return null;
6368
-
6369
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
6370
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
6371
- // 将星期日的星期数设为7
6372
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
6373
- // 获取当年的第一天
6374
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
6375
- // 计算到最近的星期四的完整周数
6376
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
6377
- // 返回周数
6378
- return weekNo;
6379
- };
6380
-
6381
- const getRangeHours = function(ranges) {
6382
- const hours = [];
6383
- let disabledHours = [];
6384
-
6385
- (ranges || []).forEach(range => {
6386
- const value = range.map(date => date.getHours());
6387
-
6388
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
6389
- });
6390
-
6391
- if (disabledHours.length) {
6392
- for (let i = 0; i < 24; i++) {
6393
- hours[i] = disabledHours.indexOf(i) === -1;
6394
- }
6395
- } else {
6396
- for (let i = 0; i < 24; i++) {
6397
- hours[i] = false;
6398
- }
6399
- }
6400
-
6401
- return hours;
6402
- };
6403
-
6404
- const getPrevMonthLastDays = (date, amount) => {
6405
- if (amount <= 0) return [];
6406
- const temp = new Date(date.getTime());
6407
- temp.setDate(0);
6408
- const lastDay = temp.getDate();
6409
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
6410
- };
6411
-
6412
- const getMonthDays = (date) => {
6413
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
6414
- const days = temp.getDate();
6415
- return range(days).map((_, index) => index + 1);
6416
- };
6417
-
6418
- function setRangeData(arr, start, end, value) {
6419
- for (let i = start; i < end; i++) {
6420
- arr[i] = value;
6421
- }
6422
- }
6423
-
6424
- const getRangeMinutes = function(ranges, hour) {
6425
- const minutes = new Array(60);
6426
-
6427
- if (ranges.length > 0) {
6428
- ranges.forEach(range => {
6429
- const start = range[0];
6430
- const end = range[1];
6431
- const startHour = start.getHours();
6432
- const startMinute = start.getMinutes();
6433
- const endHour = end.getHours();
6434
- const endMinute = end.getMinutes();
6435
- if (startHour === hour && endHour !== hour) {
6436
- setRangeData(minutes, startMinute, 60, true);
6437
- } else if (startHour === hour && endHour === hour) {
6438
- setRangeData(minutes, startMinute, endMinute + 1, true);
6439
- } else if (startHour !== hour && endHour === hour) {
6440
- setRangeData(minutes, 0, endMinute + 1, true);
6441
- } else if (startHour < hour && endHour > hour) {
6442
- setRangeData(minutes, 0, 60, true);
6443
- }
6444
- });
6445
- } else {
6446
- setRangeData(minutes, 0, 60, true);
6447
- }
6448
- return minutes;
6449
- };
6450
-
6451
- const range = function(n) {
6452
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
6453
- return Array.apply(null, {length: n}).map((_, n) => n);
6454
- };
6455
-
6456
- const modifyDate = function(date, y, m, d) {
6457
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
6458
- };
6459
-
6460
- const modifyTime = function(date, h, m, s) {
6461
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
6462
- };
6463
-
6464
- const modifyWithTimeString = (date, time) => {
6465
- if (date == null || !time) {
6466
- return date;
6467
- }
6468
- time = parseDate(time, 'HH:mm:ss');
6469
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
6470
- };
6471
-
6472
- const clearTime = function(date) {
6473
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
6474
- };
6475
-
6476
- const clearMilliseconds = function(date) {
6477
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
6478
- };
6479
-
6480
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
6481
- // TODO: refactory a more elegant solution
6482
- if (ranges.length === 0) return date;
6483
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
6484
- const ndate = normalizeDate(date);
6485
- const nranges = ranges.map(range => range.map(normalizeDate));
6486
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
6487
-
6488
- let minDate = nranges[0][0];
6489
- let maxDate = nranges[0][0];
6490
-
6491
- nranges.forEach(nrange => {
6492
- minDate = new Date(Math.min(nrange[0], minDate));
6493
- maxDate = new Date(Math.max(nrange[1], minDate));
6494
- });
6495
-
6496
- const ret = ndate < minDate ? minDate : maxDate;
6497
- // preserve Year/Month/Date
6498
- return modifyDate(
6499
- ret,
6500
- date.getFullYear(),
6501
- date.getMonth(),
6502
- date.getDate()
6503
- );
6504
- };
6505
-
6506
- const timeWithinRange = function(date, selectableRange, format) {
6507
- const limitedDate = limitTimeRange(date, selectableRange, format);
6508
- return limitedDate.getTime() === date.getTime();
6509
- };
6510
-
6511
- const changeYearMonthAndClampDate = function(date, year, month) {
6512
- // clamp date to the number of days in `year`, `month`
6513
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
6514
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
6515
- return modifyDate(date, year, month, monthDate);
6516
- };
6517
-
6518
- const prevMonth = function(date) {
6519
- const year = date.getFullYear();
6520
- const month = date.getMonth();
6521
- return month === 0
6522
- ? changeYearMonthAndClampDate(date, year - 1, 11)
6523
- : changeYearMonthAndClampDate(date, year, month - 1);
6524
- };
6525
-
6526
- const nextMonth = function(date) {
6527
- const year = date.getFullYear();
6528
- const month = date.getMonth();
6529
- return month === 11
6530
- ? changeYearMonthAndClampDate(date, year + 1, 0)
6531
- : changeYearMonthAndClampDate(date, year, month + 1);
6532
- };
6533
-
6534
- const prevYear = function(date, amount = 1) {
6535
- const year = date.getFullYear();
6536
- const month = date.getMonth();
6537
- return changeYearMonthAndClampDate(date, year - amount, month);
6538
- };
6539
-
6540
- const nextYear = function(date, amount = 1) {
6541
- const year = date.getFullYear();
6542
- const month = date.getMonth();
6543
- return changeYearMonthAndClampDate(date, year + amount, month);
6544
- };
6545
-
6546
- const extractDateFormat = function(format) {
6547
- return format
6548
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
6549
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
6550
- .trim();
6551
- };
6552
-
6553
- const extractTimeFormat = function(format) {
6554
- return format
6555
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
6556
- .trim();
6557
- };
6558
-
6559
- const validateRangeInOneMonth = function(start, end) {
6560
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
6561
- };
6562
-
6152
+ */
6153
+ fecha.parse = function (dateStr, format) {
6154
+ if (typeof format !== 'string') {
6155
+ throw new Error('Invalid format in fecha.parse');
6156
+ }
6157
+
6158
+ format = fecha.masks[format] || format;
6159
+
6160
+ // Avoid regular expression denial of service, fail early for really long strings
6161
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
6162
+ if (dateStr.length > 1000) {
6163
+ return null;
6164
+ }
6165
+
6166
+ var dateInfo = {};
6167
+ var parseInfo = [];
6168
+ var literals = [];
6169
+ format = format.replace(literal, function ($0, $1) {
6170
+ literals.push($1);
6171
+ return '@@@';
6172
+ });
6173
+ var newFormat = regexEscape(format).replace(token, function ($0) {
6174
+ if (parseFlags[$0]) {
6175
+ var info = parseFlags[$0];
6176
+ parseInfo.push(info[1]);
6177
+ return '(' + info[0] + ')';
6178
+ }
6179
+
6180
+ return $0;
6181
+ });
6182
+ newFormat = newFormat.replace(/@@@/g, function () {
6183
+ return literals.shift();
6184
+ });
6185
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
6186
+ if (!matches) {
6187
+ return null;
6188
+ }
6189
+
6190
+ for (var i = 1; i < matches.length; i++) {
6191
+ parseInfo[i - 1](dateInfo, matches[i]);
6192
+ }
6193
+
6194
+ var today = new Date();
6195
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
6196
+ dateInfo.hour = +dateInfo.hour + 12;
6197
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
6198
+ dateInfo.hour = 0;
6199
+ }
6200
+
6201
+ var date = void 0;
6202
+ if (dateInfo.timezoneOffset != null) {
6203
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
6204
+ 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));
6205
+ } else {
6206
+ 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);
6207
+ }
6208
+ return date;
6209
+ };
6210
+
6211
+ // 导出fecha对象
6212
+
6213
+
6214
+ // 以下是从date-util.js合并的函数
6215
+ var newArray = function newArray(start, end) {
6216
+ var result = [];
6217
+ for (var i = start; i <= end; i++) {
6218
+ result.push(i);
6219
+ }
6220
+ return result;
6221
+ };
6222
+
6223
+ var getSettings = function getSettings() {
6224
+ return {
6225
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
6226
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
6227
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
6228
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
6229
+ amPm: ['上午', '下午']
6230
+ };
6231
+ };
6232
+
6233
+ var toDate = function toDate(date) {
6234
+ return isDate(date) ? new Date(date) : null;
6235
+ };
6236
+
6237
+ var isDate = function isDate(date) {
6238
+ if (date === null || date === undefined) return false;
6239
+ if (isNaN(new Date(date).getTime())) return false;
6240
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
6241
+ return true;
6242
+ };
6243
+
6244
+ var isDateObject = function isDateObject(val) {
6245
+ return val instanceof Date;
6246
+ };
6247
+
6248
+ var formatDate = function formatDate(date) {
6249
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
6250
+
6251
+ // 处理多种输入类型
6252
+ if (!date) return '';
6253
+
6254
+ // 如果是时间戳,转成日期对象
6255
+ if (typeof date === 'number') {
6256
+ date = new Date(date);
6257
+ }
6258
+ // 如果是字符串,转成日期对象
6259
+ if (typeof date === 'string') {
6260
+ date = new Date(date);
6261
+ }
6262
+
6263
+ // 调用toDate进一步验证和转换
6264
+ date = toDate(date);
6265
+ if (!date) return '';
6266
+
6267
+ // 兼容大写和小写的格式标记
6268
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
6269
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
6270
+
6271
+ // 使用fecha库进行格式化,支持中文配置
6272
+ var str = fecha.format(date, lowercaseFormat, getSettings());
6273
+ return str;
6274
+ };
6275
+
6276
+ var parseDate = function parseDate(string, format) {
6277
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
6278
+ };
6279
+
6280
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
6281
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
6282
+ return 30;
6283
+ }
6284
+
6285
+ if (month === 1) {
6286
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
6287
+ return 29;
6288
+ } else {
6289
+ return 28;
6290
+ }
6291
+ }
6292
+
6293
+ return 31;
6294
+ };
6295
+
6296
+ var getDayCountOfYear = function getDayCountOfYear(year) {
6297
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
6298
+ return isLeapYear ? 366 : 365;
6299
+ };
6300
+
6301
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
6302
+ var temp = new Date(date.getTime());
6303
+ temp.setDate(1);
6304
+ return temp.getDay();
6305
+ };
6306
+
6307
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
6308
+ // {prev, next} Date should work for Daylight Saving Time
6309
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
6310
+ var prevDate = function prevDate(date) {
6311
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6312
+
6313
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
6314
+ };
6315
+
6316
+ var nextDate = function nextDate(date) {
6317
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6318
+
6319
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
6320
+ };
6321
+
6322
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
6323
+ var result = new Date(year, month, 1);
6324
+ var day = result.getDay();
6325
+
6326
+ if (day === 0) {
6327
+ return prevDate(result, 7);
6328
+ } else {
6329
+ return prevDate(result, day);
6330
+ }
6331
+ };
6332
+
6333
+ var getWeekNumber = function getWeekNumber(date) {
6334
+ // 支持多种输入类型
6335
+ if (!date || !isDate(date)) {
6336
+ date = new Date();
6337
+ }
6338
+ if (typeof date === 'string') {
6339
+ date = new Date(date);
6340
+ }
6341
+
6342
+ // 验证日期有效性
6343
+ if (!isDate(date)) return null;
6344
+
6345
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
6346
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
6347
+ // 将星期日的星期数设为7
6348
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
6349
+ // 获取当年的第一天
6350
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
6351
+ // 计算到最近的星期四的完整周数
6352
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
6353
+ // 返回周数
6354
+ return weekNo;
6355
+ };
6356
+
6357
+ var getRangeHours = function getRangeHours(ranges) {
6358
+ var hours = [];
6359
+ var disabledHours = [];
6360
+
6361
+ (ranges || []).forEach(function (range) {
6362
+ var value = range.map(function (date) {
6363
+ return date.getHours();
6364
+ });
6365
+
6366
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
6367
+ });
6368
+
6369
+ if (disabledHours.length) {
6370
+ for (var i = 0; i < 24; i++) {
6371
+ hours[i] = disabledHours.indexOf(i) === -1;
6372
+ }
6373
+ } else {
6374
+ for (var _i = 0; _i < 24; _i++) {
6375
+ hours[_i] = false;
6376
+ }
6377
+ }
6378
+
6379
+ return hours;
6380
+ };
6381
+
6382
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
6383
+ if (amount <= 0) return [];
6384
+ var temp = new Date(date.getTime());
6385
+ temp.setDate(0);
6386
+ var lastDay = temp.getDate();
6387
+ return range(amount).map(function (_, index) {
6388
+ return lastDay - (amount - index - 1);
6389
+ });
6390
+ };
6391
+
6392
+ var getMonthDays = function getMonthDays(date) {
6393
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
6394
+ var days = temp.getDate();
6395
+ return range(days).map(function (_, index) {
6396
+ return index + 1;
6397
+ });
6398
+ };
6399
+
6400
+ function setRangeData(arr, start, end, value) {
6401
+ for (var i = start; i < end; i++) {
6402
+ arr[i] = value;
6403
+ }
6404
+ }
6405
+
6406
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
6407
+ var minutes = new Array(60);
6408
+
6409
+ if (ranges.length > 0) {
6410
+ ranges.forEach(function (range) {
6411
+ var start = range[0];
6412
+ var end = range[1];
6413
+ var startHour = start.getHours();
6414
+ var startMinute = start.getMinutes();
6415
+ var endHour = end.getHours();
6416
+ var endMinute = end.getMinutes();
6417
+ if (startHour === hour && endHour !== hour) {
6418
+ setRangeData(minutes, startMinute, 60, true);
6419
+ } else if (startHour === hour && endHour === hour) {
6420
+ setRangeData(minutes, startMinute, endMinute + 1, true);
6421
+ } else if (startHour !== hour && endHour === hour) {
6422
+ setRangeData(minutes, 0, endMinute + 1, true);
6423
+ } else if (startHour < hour && endHour > hour) {
6424
+ setRangeData(minutes, 0, 60, true);
6425
+ }
6426
+ });
6427
+ } else {
6428
+ setRangeData(minutes, 0, 60, true);
6429
+ }
6430
+ return minutes;
6431
+ };
6432
+
6433
+ var range = function range(n) {
6434
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
6435
+ return Array.apply(null, { length: n }).map(function (_, n) {
6436
+ return n;
6437
+ });
6438
+ };
6439
+
6440
+ var modifyDate = function modifyDate(date, y, m, d) {
6441
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
6442
+ };
6443
+
6444
+ var modifyTime = function modifyTime(date, h, m, s) {
6445
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
6446
+ };
6447
+
6448
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
6449
+ if (date == null || !time) {
6450
+ return date;
6451
+ }
6452
+ time = parseDate(time, 'HH:mm:ss');
6453
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
6454
+ };
6455
+
6456
+ var clearTime = function clearTime(date) {
6457
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
6458
+ };
6459
+
6460
+ var clearMilliseconds = function clearMilliseconds(date) {
6461
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
6462
+ };
6463
+
6464
+ var limitTimeRange = function limitTimeRange(date, ranges) {
6465
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
6466
+
6467
+ // TODO: refactory a more elegant solution
6468
+ if (ranges.length === 0) return date;
6469
+ var normalizeDate = function normalizeDate(date) {
6470
+ return fecha.parse(fecha.format(date, format), format);
6471
+ };
6472
+ var ndate = normalizeDate(date);
6473
+ var nranges = ranges.map(function (range) {
6474
+ return range.map(normalizeDate);
6475
+ });
6476
+ if (nranges.some(function (nrange) {
6477
+ return ndate >= nrange[0] && ndate <= nrange[1];
6478
+ })) return date;
6479
+
6480
+ var minDate = nranges[0][0];
6481
+ var maxDate = nranges[0][0];
6482
+
6483
+ nranges.forEach(function (nrange) {
6484
+ minDate = new Date(Math.min(nrange[0], minDate));
6485
+ maxDate = new Date(Math.max(nrange[1], minDate));
6486
+ });
6487
+
6488
+ var ret = ndate < minDate ? minDate : maxDate;
6489
+ // preserve Year/Month/Date
6490
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
6491
+ };
6492
+
6493
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
6494
+ var limitedDate = limitTimeRange(date, selectableRange, format);
6495
+ return limitedDate.getTime() === date.getTime();
6496
+ };
6497
+
6498
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
6499
+ // clamp date to the number of days in `year`, `month`
6500
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
6501
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
6502
+ return modifyDate(date, year, month, monthDate);
6503
+ };
6504
+
6505
+ var prevMonth = function prevMonth(date) {
6506
+ var year = date.getFullYear();
6507
+ var month = date.getMonth();
6508
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
6509
+ };
6510
+
6511
+ var nextMonth = function nextMonth(date) {
6512
+ var year = date.getFullYear();
6513
+ var month = date.getMonth();
6514
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
6515
+ };
6516
+
6517
+ var prevYear = function prevYear(date) {
6518
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6519
+
6520
+ var year = date.getFullYear();
6521
+ var month = date.getMonth();
6522
+ return changeYearMonthAndClampDate(date, year - amount, month);
6523
+ };
6524
+
6525
+ var nextYear = function nextYear(date) {
6526
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6527
+
6528
+ var year = date.getFullYear();
6529
+ var month = date.getMonth();
6530
+ return changeYearMonthAndClampDate(date, year + amount, month);
6531
+ };
6532
+
6533
+ var extractDateFormat = function extractDateFormat(format) {
6534
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
6535
+ };
6536
+
6537
+ var extractTimeFormat = function extractTimeFormat(format) {
6538
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
6539
+ };
6540
+
6541
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
6542
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
6543
+ };
6544
+
6563
6545
  /**
6564
6546
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
6565
6547
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
6566
6548
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
6567
6549
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
6568
6550
  * @returns {number} 工作日数量
6569
- */
6570
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
6571
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
6572
- throw new Error(
6573
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
6574
- );
6575
- }
6576
-
6577
- const startDateObj = new Date(start_date);
6578
- const endDateObj = new Date(end_date);
6579
-
6580
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
6581
- throw new Error(
6582
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
6583
- );
6584
- }
6585
-
6586
- if (startDateObj > endDateObj) {
6587
- throw new Error('Start date should be earlier than or equal to end date.');
6588
- }
6589
-
6590
- let workdays = 0;
6591
-
6592
- // Iterate through each day in the date range
6593
- for (
6594
- let currentDate = new Date(startDateObj);
6595
- currentDate <= endDateObj;
6596
- currentDate.setDate(currentDate.getDate() + 1)
6597
- ) {
6598
- // Check if the current day is a weekend (Saturday or Sunday)
6599
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
6600
-
6601
- // Check if the current day is a holiday
6602
- const isHoliday = holidays.some((holiday) => {
6603
- const holidayDate = new Date(holiday);
6604
- return currentDate.toDateString() === holidayDate.toDateString();
6605
- });
6606
-
6607
- // If it's a workday (not a weekend or holiday), increment the workdays count
6608
- if (!isWeekend && !isHoliday) {
6609
- workdays++;
6610
- }
6611
- }
6612
-
6613
- return workdays;
6614
- };
6615
-
6551
+ */
6552
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
6553
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
6554
+
6555
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
6556
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
6557
+ }
6558
+
6559
+ var startDateObj = new Date(start_date);
6560
+ var endDateObj = new Date(end_date);
6561
+
6562
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
6563
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
6564
+ }
6565
+
6566
+ if (startDateObj > endDateObj) {
6567
+ throw new Error('Start date should be earlier than or equal to end date.');
6568
+ }
6569
+
6570
+ var workdays = 0;
6571
+
6572
+ // Iterate through each day in the date range
6573
+
6574
+ var _loop = function _loop(currentDate) {
6575
+ // Check if the current day is a weekend (Saturday or Sunday)
6576
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
6577
+
6578
+ // Check if the current day is a holiday
6579
+ var isHoliday = holidays.some(function (holiday) {
6580
+ var holidayDate = new Date(holiday);
6581
+ return currentDate.toDateString() === holidayDate.toDateString();
6582
+ });
6583
+
6584
+ // If it's a workday (not a weekend or holiday), increment the workdays count
6585
+ if (!isWeekend && !isHoliday) {
6586
+ workdays++;
6587
+ }
6588
+ };
6589
+
6590
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
6591
+ _loop(currentDate);
6592
+ }
6593
+
6594
+ return workdays;
6595
+ };
6596
+
6616
6597
  /**
6617
6598
  * 日期加减天数
6618
6599
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
6619
6600
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
6620
6601
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
6621
- */
6622
- const dateAddDays = function (start_date, days) {
6623
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6624
- throw new Error(
6625
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
6626
- );
6627
- }
6628
-
6629
- const startDateObj = new Date(start_date);
6630
- if (isNaN(startDateObj.getTime())) {
6631
- throw new Error(
6632
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6633
- );
6634
- }
6635
-
6636
- const resultDateObj = new Date(startDateObj);
6637
- resultDateObj.setDate(resultDateObj.getDate() + days);
6638
-
6639
- const resultYear = resultDateObj.getFullYear();
6640
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6641
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6642
-
6643
- return `${resultYear}-${resultMonth}-${resultDay}`;
6644
- };
6645
-
6602
+ */
6603
+ var dateAddDays = function dateAddDays(start_date, days) {
6604
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6605
+ 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.");
6606
+ }
6607
+
6608
+ var startDateObj = new Date(start_date);
6609
+ if (isNaN(startDateObj.getTime())) {
6610
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6611
+ }
6612
+
6613
+ var resultDateObj = new Date(startDateObj);
6614
+ resultDateObj.setDate(resultDateObj.getDate() + days);
6615
+
6616
+ var resultYear = resultDateObj.getFullYear();
6617
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6618
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6619
+
6620
+ return resultYear + '-' + resultMonth + '-' + resultDay;
6621
+ };
6622
+
6646
6623
  /**
6647
6624
  * 计算两个日期之间的差值
6648
6625
  * @date 2023年12月14日
@@ -6650,182 +6627,180 @@ const dateAddDays = function (start_date, days) {
6650
6627
  * @param {String} end_date - 结束日期字符串
6651
6628
  * @param {String} unit - 单位:year/month/day
6652
6629
  * @returns {Number} 差值
6653
- */
6654
- const dateDiff = function (start_date, end_date, unit = 'day') {
6655
- // Assuming date strings are in "YYYY-MM-DD" format
6656
- var startDate = new Date(start_date);
6657
- var endDate = new Date(end_date);
6658
-
6659
- // If the date is invalid, return 0
6660
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6661
- return 0;
6662
- }
6663
-
6664
- if (unit === 'year') {
6665
- return endDate.getFullYear() - startDate.getFullYear();
6666
- } else if (unit === 'month') {
6667
- return (
6668
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
6669
- (endDate.getMonth() - startDate.getMonth())
6670
- );
6671
- } else {
6672
- // Default to day
6673
- var timeDifference = endDate - startDate;
6674
- // Calculate days (86400000 milliseconds per day)
6675
- return Math.floor(timeDifference / 86400000);
6676
- }
6677
- };
6678
-
6630
+ */
6631
+ var dateDiff = function dateDiff(start_date, end_date) {
6632
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
6633
+
6634
+ // Assuming date strings are in "YYYY-MM-DD" format
6635
+ var startDate = new Date(start_date);
6636
+ var endDate = new Date(end_date);
6637
+
6638
+ // If the date is invalid, return 0
6639
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6640
+ return 0;
6641
+ }
6642
+
6643
+ if (unit === 'year') {
6644
+ return endDate.getFullYear() - startDate.getFullYear();
6645
+ } else if (unit === 'month') {
6646
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
6647
+ } else {
6648
+ // Default to day
6649
+ var timeDifference = endDate - startDate;
6650
+ // Calculate days (86400000 milliseconds per day)
6651
+ return Math.floor(timeDifference / 86400000);
6652
+ }
6653
+ };
6654
+
6679
6655
  /**
6680
6656
  * 获取月份中的日期
6681
6657
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
6682
6658
  * @returns {number} 月份中的日期(1-31)
6683
- */
6684
- const dayOfMonth = function (date) {
6685
- if (typeof date !== 'string') {
6686
- throw new Error(
6687
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
6688
- );
6689
- }
6690
-
6691
- const dateObj = new Date(date);
6692
- if (isNaN(dateObj.getTime())) {
6693
- throw new Error(
6694
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6695
- );
6696
- }
6697
-
6698
- return dateObj.getDate();
6699
- };
6700
-
6659
+ */
6660
+ var dayOfMonth = function dayOfMonth(date) {
6661
+ if (typeof date !== 'string') {
6662
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6663
+ }
6664
+
6665
+ var dateObj = new Date(date);
6666
+ if (isNaN(dateObj.getTime())) {
6667
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6668
+ }
6669
+
6670
+ return dateObj.getDate();
6671
+ };
6672
+
6701
6673
  /**
6702
6674
  * 获取当前日期
6703
6675
  * @date 2022年5月7日
6704
6676
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
6705
6677
  * @returns {string} 当前日期的格式化字符串
6706
- */
6707
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
6708
- return formatDate(new Date(), format);
6709
- };
6710
-
6678
+ */
6679
+ var getCurrentDate = function getCurrentDate() {
6680
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
6681
+
6682
+ return formatDate(new Date(), format);
6683
+ };
6684
+
6711
6685
  /**
6712
6686
  * 获取当前日期时间
6713
6687
  * @date 2022年5月7日
6714
6688
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
6715
6689
  * @returns {string} 当前日期时间的格式化字符串
6716
- */
6717
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
6718
- return formatDate(new Date(), format);
6719
- };
6720
-
6690
+ */
6691
+ var getCurrentDateTime = function getCurrentDateTime() {
6692
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
6693
+
6694
+ return formatDate(new Date(), format);
6695
+ };
6696
+
6721
6697
  /**
6722
6698
  * 获取小时
6723
6699
  * @date 2022年5月7日
6724
6700
  * @param {Date|string} [date] - 日期对象或日期字符串
6725
6701
  * @returns {number} 小时数(0-23)
6726
- */
6727
- const getHour = function (date) {
6728
- if (!date) {
6729
- return new Date().getHours();
6730
- }
6731
- if (typeof date === 'string') {
6732
- date = new Date(date);
6733
- }
6734
- return date.getHours();
6735
- };
6736
-
6702
+ */
6703
+ var getHour = function getHour(date) {
6704
+ if (!date) {
6705
+ return new Date().getHours();
6706
+ }
6707
+ if (typeof date === 'string') {
6708
+ date = new Date(date);
6709
+ }
6710
+ return date.getHours();
6711
+ };
6712
+
6737
6713
  /**
6738
6714
  * 获取分钟
6739
6715
  * @date 2022年5月7日
6740
6716
  * @param {Date|string} [date] - 日期对象或日期字符串
6741
6717
  * @returns {number} 分钟数(0-59)
6742
- */
6743
- const getMinute = function (date) {
6744
- if (!date) {
6745
- return new Date().getMinutes();
6746
- }
6747
- if (typeof date === 'string') {
6748
- date = new Date(date);
6749
- }
6750
- return date.getMinutes();
6751
- };
6752
-
6718
+ */
6719
+ var getMinute = function getMinute(date) {
6720
+ if (!date) {
6721
+ return new Date().getMinutes();
6722
+ }
6723
+ if (typeof date === 'string') {
6724
+ date = new Date(date);
6725
+ }
6726
+ return date.getMinutes();
6727
+ };
6728
+
6753
6729
  /**
6754
6730
  * 获取月份
6755
6731
  * @date 2022年5月7日
6756
6732
  * @param {Date|string} [date] - 日期对象或日期字符串
6757
6733
  * @returns {number} 月份数(1-12)
6758
- */
6759
- const getMonth = function (date) {
6760
- if (!date) {
6761
- return new Date().getMonth() + 1;
6762
- }
6763
- if (typeof date === 'string') {
6764
- date = new Date(date);
6765
- }
6766
- return date.getMonth() + 1;
6767
- };
6768
-
6734
+ */
6735
+ var getMonth = function getMonth(date) {
6736
+ if (!date) {
6737
+ return new Date().getMonth() + 1;
6738
+ }
6739
+ if (typeof date === 'string') {
6740
+ date = new Date(date);
6741
+ }
6742
+ return date.getMonth() + 1;
6743
+ };
6744
+
6769
6745
  /**
6770
6746
  * 获取秒
6771
6747
  * @date 2022年5月7日
6772
6748
  * @param {Date|string} [date] - 日期对象或日期字符串
6773
6749
  * @returns {number} 秒数(0-59)
6774
- */
6775
- const getSecond = function (date) {
6776
- if (!date) {
6777
- return new Date().getSeconds();
6778
- }
6779
- if (typeof date === 'string') {
6780
- date = new Date(date);
6781
- }
6782
- return date.getSeconds();
6783
- };
6784
-
6750
+ */
6751
+ var getSecond = function getSecond(date) {
6752
+ if (!date) {
6753
+ return new Date().getSeconds();
6754
+ }
6755
+ if (typeof date === 'string') {
6756
+ date = new Date(date);
6757
+ }
6758
+ return date.getSeconds();
6759
+ };
6760
+
6785
6761
  /**
6786
6762
  * 获取星期几
6787
6763
  * @date 2022年5月7日
6788
6764
  * @param {Date|string} [date] - 日期对象或日期字符串
6789
6765
  * @returns {number} 星期几(0-6,0表示星期日)
6790
- */
6791
- const getWeekday = function (date) {
6792
- if (!date) {
6793
- return new Date().getDay();
6794
- }
6795
- if (typeof date === 'string') {
6796
- date = new Date(date);
6797
- }
6798
- return date.getDay();
6799
- };
6800
-
6801
-
6766
+ */
6767
+ var getWeekday = function getWeekday(date) {
6768
+ if (!date) {
6769
+ return new Date().getDay();
6770
+ }
6771
+ if (typeof date === 'string') {
6772
+ date = new Date(date);
6773
+ }
6774
+ return date.getDay();
6775
+ };
6776
+
6802
6777
  /**
6803
6778
  * @desc 获取上午/下午/晚上
6804
6779
  * @author huangbo
6805
6780
  * @date 2022年5月7日
6806
6781
  * @param {String} [time] - 时间
6807
- **/
6808
- const timeCycle = function (time) {
6809
- let hour = 0;
6810
- if (!time) {
6811
- hour = new Date().getHours();
6812
- } else if (typeof time === 'string') {
6813
- // 从时间字符串中提取小时
6814
- const match = time.match(/^(\d{1,2})/);
6815
- if (match) {
6816
- hour = parseInt(match[1], 10);
6817
- }
6818
- } else if (typeof time === 'number') {
6819
- hour = time;
6820
- }
6821
- // 判断时间段
6822
- if (hour >= 5 && hour < 12) {
6823
- return '上午';
6824
- } else if (hour >= 12 && hour < 18) {
6825
- return '下午';
6826
- } else {
6827
- return '晚上';
6828
- }
6782
+ **/
6783
+ var timeCycle = function timeCycle(time) {
6784
+ var hour = 0;
6785
+ if (!time) {
6786
+ hour = new Date().getHours();
6787
+ } else if (typeof time === 'string') {
6788
+ // 从时间字符串中提取小时
6789
+ var match = time.match(/^(\d{1,2})/);
6790
+ if (match) {
6791
+ hour = parseInt(match[1], 10);
6792
+ }
6793
+ } else if (typeof time === 'number') {
6794
+ hour = time;
6795
+ }
6796
+ // 判断时间段
6797
+ if (hour >= 5 && hour < 12) {
6798
+ return '上午';
6799
+ } else if (hour >= 12 && hour < 18) {
6800
+ return '下午';
6801
+ } else {
6802
+ return '晚上';
6803
+ }
6829
6804
  };
6830
6805
 
6831
6806
  /***/ }),