eoss 0.1.0-alpha.34 → 0.1.0-alpha.35

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 (208) 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 +985 -1010
  83. package/lib/alert.js +2 -2
  84. package/lib/aside.js +2 -2
  85. package/lib/audit-trajectory.js +145 -145
  86. package/lib/autocomplete.js +1778 -2002
  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 +2 -2
  93. package/lib/button.js +2 -2
  94. package/lib/ca-login.js +837 -862
  95. package/lib/calendar.js +837 -862
  96. package/lib/card.js +2 -2
  97. package/lib/carousel-item.js +839 -864
  98. package/lib/carousel.js +839 -864
  99. package/lib/cascader-panel.js +839 -864
  100. package/lib/cascader.js +1780 -2004
  101. package/lib/checkbox-button.js +2 -2
  102. package/lib/checkbox-group.js +987 -1012
  103. package/lib/checkbox.js +2 -2
  104. package/lib/col.js +2 -2
  105. package/lib/collapse-item.js +839 -864
  106. package/lib/collapse.js +839 -864
  107. package/lib/color-picker.js +942 -1141
  108. package/lib/container.js +2 -2
  109. package/lib/cron.js +2 -2
  110. package/lib/data-table.js +987 -1012
  111. package/lib/date-picker.js +1785 -2009
  112. package/lib/dialog.js +837 -862
  113. package/lib/divider.js +2 -2
  114. package/lib/drawer.js +2 -2
  115. package/lib/dropdown-item.js +4 -4
  116. package/lib/dropdown-menu.js +942 -1141
  117. package/lib/dropdown.js +837 -862
  118. package/lib/email-login.js +986 -1011
  119. package/lib/empty.js +2 -2
  120. package/lib/eoss.common.js +2935 -2523
  121. package/lib/flip.js +2 -2
  122. package/lib/flow-group.js +841 -866
  123. package/lib/flow.js +1073 -1098
  124. package/lib/flows.js +993 -1018
  125. package/lib/footer.js +2 -2
  126. package/lib/form-item.js +2275 -2300
  127. package/lib/form.js +1034 -1046
  128. package/lib/guide.js +2 -2
  129. package/lib/header.js +2 -2
  130. package/lib/icon.js +981 -1006
  131. package/lib/icons.js +2 -2
  132. package/lib/image-viewer.js +837 -862
  133. package/lib/image.js +4 -4
  134. package/lib/index.js +1 -1
  135. package/lib/infinite-scroll.js +2 -2
  136. package/lib/input-number.js +4 -4
  137. package/lib/input.js +837 -862
  138. package/lib/link.js +2 -2
  139. package/lib/loading.js +2 -2
  140. package/lib/login.js +1737 -1059
  141. package/lib/lowcode-view.js +991 -1016
  142. package/lib/lowcode.js +1088 -1113
  143. package/lib/main.js +1066 -1091
  144. package/lib/marquee.js +837 -862
  145. package/lib/menu-item-group.js +2 -2
  146. package/lib/menu-item.js +2 -2
  147. package/lib/menu.js +1779 -2003
  148. package/lib/message-box.js +837 -862
  149. package/lib/message.js +837 -862
  150. package/lib/notification.js +859 -884
  151. package/lib/option-group.js +4 -4
  152. package/lib/option.js +839 -864
  153. package/lib/page-header.js +2 -2
  154. package/lib/pagination.js +837 -862
  155. package/lib/phone-login.js +986 -1011
  156. package/lib/popconfirm.js +4 -4
  157. package/lib/popover.js +1779 -2003
  158. package/lib/process-config.js +995 -1020
  159. package/lib/process-module.js +1056 -1081
  160. package/lib/process-rule.js +999 -1024
  161. package/lib/progress.js +2 -2
  162. package/lib/qr-code.js +4 -4
  163. package/lib/qrcode-login.js +987 -1012
  164. package/lib/radio-button.js +2 -2
  165. package/lib/radio-group.js +987 -1012
  166. package/lib/radio.js +2 -2
  167. package/lib/rate.js +837 -862
  168. package/lib/row.js +2 -2
  169. package/lib/scrollbar.js +837 -862
  170. package/lib/select.js +1938 -2162
  171. package/lib/selector-panel.js +1014 -1039
  172. package/lib/selector.js +991 -1016
  173. package/lib/slider.js +2 -2
  174. package/lib/step.js +4 -4
  175. package/lib/steps.js +839 -864
  176. package/lib/submenu.js +944 -1143
  177. package/lib/switch.js +837 -862
  178. package/lib/tab-pane.js +4 -4
  179. package/lib/table-column.js +837 -862
  180. package/lib/table.js +1927 -2151
  181. package/lib/tabs.js +839 -864
  182. package/lib/tag.js +2 -2
  183. package/lib/theme-chalk/base.css +1 -1
  184. package/lib/theme-chalk/index.css +1 -1
  185. package/lib/theme-chalk/main.css +1 -1
  186. package/lib/time-picker.js +1786 -2010
  187. package/lib/time-select.js +1782 -2006
  188. package/lib/timeline-item.js +2 -2
  189. package/lib/timeline.js +2 -2
  190. package/lib/tips.js +986 -1011
  191. package/lib/toolbar.js +2 -2
  192. package/lib/tooltip.js +1778 -2002
  193. package/lib/transfer.js +837 -862
  194. package/lib/tree-group.js +982 -1007
  195. package/lib/tree.js +985 -1010
  196. package/lib/update-history.js +146 -146
  197. package/lib/upload.js +999 -1024
  198. package/lib/utils/helpers.js +52 -0
  199. package/lib/utils/popper.js +48 -97
  200. package/lib/wujie.js +841 -866
  201. package/package.json +1 -1
  202. package/packages/login/src/login.vue +24 -3
  203. package/packages/login/src/resetPassword.vue +19 -13
  204. package/packages/main/src/minxs.js +0 -1
  205. package/packages/theme-chalk/src/base.scss +1 -2
  206. package/src/index.js +327 -327
  207. package/src/utils/helpers.js +49 -0
  208. package/src/utils/popper.js +70 -109
package/lib/steps.js CHANGED
@@ -136,7 +136,7 @@ module.exports =
136
136
  /******/
137
137
  /******/
138
138
  /******/ // Load entry module and return exports
139
- /******/ return __webpack_require__(__webpack_require__.s = 253);
139
+ /******/ return __webpack_require__(__webpack_require__.s = 254);
140
140
  /******/ })
141
141
  /************************************************************************/
142
142
  /******/ ({
@@ -3339,7 +3339,7 @@ var warning = function warning(content, _callback3) {
3339
3339
 
3340
3340
  /***/ }),
3341
3341
 
3342
- /***/ 109:
3342
+ /***/ 110:
3343
3343
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3344
3344
 
3345
3345
  "use strict";
@@ -4277,7 +4277,7 @@ module.exports = require("vue");
4277
4277
 
4278
4278
  /***/ }),
4279
4279
 
4280
- /***/ 253:
4280
+ /***/ 254:
4281
4281
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4282
4282
 
4283
4283
  "use strict";
@@ -4334,7 +4334,7 @@ render._withStripped = true
4334
4334
  var migrating = __webpack_require__(45);
4335
4335
 
4336
4336
  // EXTERNAL MODULE: ./packages/steps/src/step.vue + 4 modules
4337
- var step = __webpack_require__(109);
4337
+ var step = __webpack_require__(110);
4338
4338
 
4339
4339
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/steps/src/steps.vue?vue&type=script&lang=js&
4340
4340
  var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
@@ -4960,759 +4960,736 @@ module.exports = require("eoss/lib/cascader");
4960
4960
  /* unused harmony export getSecond */
4961
4961
  /* unused harmony export getWeekday */
4962
4962
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
4963
- /* Modified from https://github.com/taylorhakes/fecha
4964
- *
4965
- * The MIT License (MIT)
4966
- *
4967
- * Copyright (c) 2015 Taylor Hakes
4968
- *
4969
- * Permission is hereby granted, free of charge, to any person obtaining a copy
4970
- * of this software and associated documentation files (the "Software"), to deal
4971
- * in the Software without restriction, including without limitation the rights
4972
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4973
- * copies of the Software, and to permit persons to whom the Software is
4974
- * furnished to do so, subject to the following conditions:
4975
- *
4976
- * The above copyright notice and this permission notice shall be included in all
4977
- * copies or substantial portions of the Software.
4978
- *
4979
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4980
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4981
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4982
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4983
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4984
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4985
- * SOFTWARE.
4986
- */
4987
-
4988
- /*eslint-disable*/
4989
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
4990
-
4991
-
4963
+
4964
+
4992
4965
  /**
4993
4966
  * Parse or format dates
4994
4967
  * @class fecha
4995
- */
4996
- const fecha = {};
4997
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4998
- const twoDigits = '\\d\\d?';
4999
- const threeDigits = '\\d{3}';
5000
- const fourDigits = '\\d{4}';
5001
- const word = '[^\\s]+';
5002
- const literal = /\[([^]*?)\]/gm;
5003
- const noop = function () {};
5004
-
5005
- function regexEscape(str) {
5006
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5007
- }
5008
-
5009
- function shorten(arr, sLen) {
5010
- const newArr = [];
5011
- for (let i = 0, len = arr.length; i < len; i++) {
5012
- newArr.push(arr[i].substr(0, sLen));
5013
- }
5014
- return newArr;
5015
- }
5016
-
5017
- function monthUpdate() {
5018
- return function (d, v) {
5019
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5020
- if (~index) {
5021
- d.month = index;
5022
- }
5023
- };
5024
- }
5025
-
5026
- function pad(val, len) {
5027
- val = String(val);
5028
- len = len || 2;
5029
- while (val.length < len) {
5030
- val = '0' + val;
5031
- }
5032
- return val;
5033
- }
5034
-
5035
- // 直接使用中文日期名称常量
5036
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5037
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5038
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5039
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5040
- const amPm = ['上午', '下午'];
5041
- const DoFn = function DoFn(D) {
5042
- return D + '日';
5043
- };
5044
-
5045
- const formatFlags = {
5046
- D: function(dateObj) {
5047
- return dateObj.getDay();
5048
- },
5049
- DD: function(dateObj) {
5050
- return pad(dateObj.getDay());
5051
- },
5052
- Do: function(dateObj) {
5053
- return DoFn(dateObj.getDate());
5054
- },
5055
- d: function(dateObj) {
5056
- return dateObj.getDate();
5057
- },
5058
- dd: function(dateObj) {
5059
- return pad(dateObj.getDate());
5060
- },
5061
- ddd: function(dateObj) {
5062
- return dayNamesShort[dateObj.getDay()];
5063
- },
5064
- dddd: function(dateObj) {
5065
- return dayNames[dateObj.getDay()];
5066
- },
5067
- M: function(dateObj) {
5068
- return dateObj.getMonth() + 1;
5069
- },
5070
- MM: function(dateObj) {
5071
- return pad(dateObj.getMonth() + 1);
5072
- },
5073
- MMM: function(dateObj) {
5074
- return monthNamesShort[dateObj.getMonth()];
5075
- },
5076
- MMMM: function(dateObj) {
5077
- return monthNames[dateObj.getMonth()];
5078
- },
5079
- yy: function(dateObj) {
5080
- return pad(String(dateObj.getFullYear()), 4).substr(2);
5081
- },
5082
- yyyy: function(dateObj) {
5083
- return pad(dateObj.getFullYear(), 4);
5084
- },
5085
- h: function(dateObj) {
5086
- return dateObj.getHours() % 12 || 12;
5087
- },
5088
- hh: function(dateObj) {
5089
- return pad(dateObj.getHours() % 12 || 12);
5090
- },
5091
- H: function(dateObj) {
5092
- return dateObj.getHours();
5093
- },
5094
- HH: function(dateObj) {
5095
- return pad(dateObj.getHours());
5096
- },
5097
- m: function(dateObj) {
5098
- return dateObj.getMinutes();
5099
- },
5100
- mm: function(dateObj) {
5101
- return pad(dateObj.getMinutes());
5102
- },
5103
- s: function(dateObj) {
5104
- return dateObj.getSeconds();
5105
- },
5106
- ss: function(dateObj) {
5107
- return pad(dateObj.getSeconds());
5108
- },
5109
- S: function(dateObj) {
5110
- return Math.round(dateObj.getMilliseconds() / 100);
5111
- },
5112
- SS: function(dateObj) {
5113
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5114
- },
5115
- SSS: function(dateObj) {
5116
- return pad(dateObj.getMilliseconds(), 3);
5117
- },
5118
- a: function(dateObj) {
5119
- return dateObj.getHours() < 12 ? '上午' : '下午';
5120
- },
5121
- A: function(dateObj) {
5122
- return dateObj.getHours() < 12 ? '上午' : '下午';
5123
- },
5124
- ZZ: function(dateObj) {
5125
- const o = dateObj.getTimezoneOffset();
5126
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5127
- }
5128
- };
5129
-
5130
- const parseFlags = {
5131
- d: [twoDigits, function (d, v) {
5132
- d.day = v;
5133
- }],
5134
- Do: [twoDigits + word, function (d, v) {
5135
- d.day = parseInt(v, 10);
5136
- }],
5137
- M: [twoDigits, function (d, v) {
5138
- d.month = v - 1;
5139
- }],
5140
- yy: [twoDigits, function (d, v) {
5141
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
5142
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5143
- }],
5144
- h: [twoDigits, function (d, v) {
5145
- d.hour = v;
5146
- }],
5147
- m: [twoDigits, function (d, v) {
5148
- d.minute = v;
5149
- }],
5150
- s: [twoDigits, function (d, v) {
5151
- d.second = v;
5152
- }],
5153
- yyyy: [fourDigits, function (d, v) {
5154
- d.year = v;
5155
- }],
5156
- S: ['\\d', function (d, v) {
5157
- d.millisecond = v * 100;
5158
- }],
5159
- SS: ['\\d{2}', function (d, v) {
5160
- d.millisecond = v * 10;
5161
- }],
5162
- SSS: [threeDigits, function (d, v) {
5163
- d.millisecond = v;
5164
- }],
5165
- D: [twoDigits, noop],
5166
- ddd: [word, noop],
5167
- MMM: [word, monthUpdate('monthNamesShort')],
5168
- MMMM: [word, monthUpdate('monthNames')],
5169
- a: [word, function (d, v) {
5170
- const val = v.toLowerCase();
5171
- if (val === '上午') {
5172
- d.isPm = false;
5173
- } else if (val === '下午') {
5174
- d.isPm = true;
5175
- }
5176
- }],
5177
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5178
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
5179
-
5180
- if (parts) {
5181
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5182
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5183
- }
5184
- }]
5185
- };
5186
- parseFlags.dd = parseFlags.d;
5187
- parseFlags.dddd = parseFlags.ddd;
5188
- parseFlags.DD = parseFlags.D;
5189
- parseFlags.mm = parseFlags.m;
5190
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5191
- parseFlags.MM = parseFlags.M;
5192
- parseFlags.ss = parseFlags.s;
5193
- parseFlags.A = parseFlags.a;
5194
-
5195
-
5196
- // Some common format strings
5197
- fecha.masks = {
5198
- default: 'ddd MMM dd yyyy HH:mm:ss',
5199
- shortDate: 'M/D/yy',
5200
- mediumDate: 'MMM d, yyyy',
5201
- longDate: 'MMMM d, yyyy',
5202
- fullDate: 'dddd, MMMM d, yyyy',
5203
- shortTime: 'HH:mm',
5204
- mediumTime: 'HH:mm:ss',
5205
- longTime: 'HH:mm:ss.SSS'
5206
- };
5207
-
4968
+ */
4969
+ var fecha = {};
4970
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4971
+ var twoDigits = '\\d\\d?';
4972
+ var threeDigits = '\\d{3}';
4973
+ var fourDigits = '\\d{4}';
4974
+ var word = '[^\\s]+';
4975
+ var literal = /\[([^]*?)\]/gm;
4976
+ var noop = function noop() {};
4977
+
4978
+ function regexEscape(str) {
4979
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
4980
+ }
4981
+
4982
+ function shorten(arr, sLen) {
4983
+ var newArr = [];
4984
+ for (var i = 0, len = arr.length; i < len; i++) {
4985
+ newArr.push(arr[i].substr(0, sLen));
4986
+ }
4987
+ return newArr;
4988
+ }
4989
+
4990
+ function monthUpdate() {
4991
+ return function (d, v) {
4992
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
4993
+ if (~index) {
4994
+ d.month = index;
4995
+ }
4996
+ };
4997
+ }
4998
+
4999
+ function pad(val, len) {
5000
+ val = String(val);
5001
+ len = len || 2;
5002
+ while (val.length < len) {
5003
+ val = '0' + val;
5004
+ }
5005
+ return val;
5006
+ }
5007
+
5008
+ // 直接使用中文日期名称常量
5009
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5010
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5011
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5012
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5013
+ var amPm = ['上午', '下午'];
5014
+ var DoFn = function DoFn(D) {
5015
+ return D + '日';
5016
+ };
5017
+
5018
+ var formatFlags = {
5019
+ D: function D(dateObj) {
5020
+ return dateObj.getDay();
5021
+ },
5022
+ DD: function DD(dateObj) {
5023
+ return pad(dateObj.getDay());
5024
+ },
5025
+ Do: function Do(dateObj) {
5026
+ return DoFn(dateObj.getDate());
5027
+ },
5028
+ d: function d(dateObj) {
5029
+ return dateObj.getDate();
5030
+ },
5031
+ dd: function dd(dateObj) {
5032
+ return pad(dateObj.getDate());
5033
+ },
5034
+ ddd: function ddd(dateObj) {
5035
+ return dayNamesShort[dateObj.getDay()];
5036
+ },
5037
+ dddd: function dddd(dateObj) {
5038
+ return dayNames[dateObj.getDay()];
5039
+ },
5040
+ M: function M(dateObj) {
5041
+ return dateObj.getMonth() + 1;
5042
+ },
5043
+ MM: function MM(dateObj) {
5044
+ return pad(dateObj.getMonth() + 1);
5045
+ },
5046
+ MMM: function MMM(dateObj) {
5047
+ return monthNamesShort[dateObj.getMonth()];
5048
+ },
5049
+ MMMM: function MMMM(dateObj) {
5050
+ return monthNames[dateObj.getMonth()];
5051
+ },
5052
+ yy: function yy(dateObj) {
5053
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
5054
+ },
5055
+ yyyy: function yyyy(dateObj) {
5056
+ return pad(dateObj.getFullYear(), 4);
5057
+ },
5058
+ h: function h(dateObj) {
5059
+ return dateObj.getHours() % 12 || 12;
5060
+ },
5061
+ hh: function hh(dateObj) {
5062
+ return pad(dateObj.getHours() % 12 || 12);
5063
+ },
5064
+ H: function H(dateObj) {
5065
+ return dateObj.getHours();
5066
+ },
5067
+ HH: function HH(dateObj) {
5068
+ return pad(dateObj.getHours());
5069
+ },
5070
+ m: function m(dateObj) {
5071
+ return dateObj.getMinutes();
5072
+ },
5073
+ mm: function mm(dateObj) {
5074
+ return pad(dateObj.getMinutes());
5075
+ },
5076
+ s: function s(dateObj) {
5077
+ return dateObj.getSeconds();
5078
+ },
5079
+ ss: function ss(dateObj) {
5080
+ return pad(dateObj.getSeconds());
5081
+ },
5082
+ S: function S(dateObj) {
5083
+ return Math.round(dateObj.getMilliseconds() / 100);
5084
+ },
5085
+ SS: function SS(dateObj) {
5086
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5087
+ },
5088
+ SSS: function SSS(dateObj) {
5089
+ return pad(dateObj.getMilliseconds(), 3);
5090
+ },
5091
+ a: function a(dateObj) {
5092
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5093
+ },
5094
+ A: function A(dateObj) {
5095
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5096
+ },
5097
+ ZZ: function ZZ(dateObj) {
5098
+ var o = dateObj.getTimezoneOffset();
5099
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5100
+ }
5101
+ };
5102
+
5103
+ var parseFlags = {
5104
+ d: [twoDigits, function (d, v) {
5105
+ d.day = v;
5106
+ }],
5107
+ Do: [twoDigits + word, function (d, v) {
5108
+ d.day = parseInt(v, 10);
5109
+ }],
5110
+ M: [twoDigits, function (d, v) {
5111
+ d.month = v - 1;
5112
+ }],
5113
+ yy: [twoDigits, function (d, v) {
5114
+ var da = new Date(),
5115
+ cent = +('' + da.getFullYear()).substr(0, 2);
5116
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5117
+ }],
5118
+ h: [twoDigits, function (d, v) {
5119
+ d.hour = v;
5120
+ }],
5121
+ m: [twoDigits, function (d, v) {
5122
+ d.minute = v;
5123
+ }],
5124
+ s: [twoDigits, function (d, v) {
5125
+ d.second = v;
5126
+ }],
5127
+ yyyy: [fourDigits, function (d, v) {
5128
+ d.year = v;
5129
+ }],
5130
+ S: ['\\d', function (d, v) {
5131
+ d.millisecond = v * 100;
5132
+ }],
5133
+ SS: ['\\d{2}', function (d, v) {
5134
+ d.millisecond = v * 10;
5135
+ }],
5136
+ SSS: [threeDigits, function (d, v) {
5137
+ d.millisecond = v;
5138
+ }],
5139
+ D: [twoDigits, noop],
5140
+ ddd: [word, noop],
5141
+ MMM: [word, monthUpdate('monthNamesShort')],
5142
+ MMMM: [word, monthUpdate('monthNames')],
5143
+ a: [word, function (d, v) {
5144
+ var val = v.toLowerCase();
5145
+ if (val === '上午') {
5146
+ d.isPm = false;
5147
+ } else if (val === '下午') {
5148
+ d.isPm = true;
5149
+ }
5150
+ }],
5151
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5152
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
5153
+ minutes = void 0;
5154
+
5155
+ if (parts) {
5156
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5157
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5158
+ }
5159
+ }]
5160
+ };
5161
+ parseFlags.dd = parseFlags.d;
5162
+ parseFlags.dddd = parseFlags.ddd;
5163
+ parseFlags.DD = parseFlags.D;
5164
+ parseFlags.mm = parseFlags.m;
5165
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5166
+ parseFlags.MM = parseFlags.M;
5167
+ parseFlags.ss = parseFlags.s;
5168
+ parseFlags.A = parseFlags.a;
5169
+
5170
+ // Some common format strings
5171
+ fecha.masks = {
5172
+ default: 'ddd MMM dd yyyy HH:mm:ss',
5173
+ shortDate: 'M/D/yy',
5174
+ mediumDate: 'MMM d, yyyy',
5175
+ longDate: 'MMMM d, yyyy',
5176
+ fullDate: 'dddd, MMMM d, yyyy',
5177
+ shortTime: 'HH:mm',
5178
+ mediumTime: 'HH:mm:ss',
5179
+ longTime: 'HH:mm:ss.SSS'
5180
+ };
5181
+
5208
5182
  /***
5209
5183
  * Format a date
5210
5184
  * @method format
5211
5185
  * @param {Date|number} dateObj
5212
5186
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
5213
- */
5214
- fecha.format = function (dateObj, mask) {
5215
- if (typeof dateObj === 'number') {
5216
- dateObj = new Date(dateObj);
5217
- }
5218
-
5219
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5220
- throw new Error('Invalid Date in fecha.format');
5221
- }
5222
-
5223
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
5224
-
5225
- const literals = [];
5226
-
5227
- // Make literals inactive by replacing them with ??
5228
- mask = mask.replace(literal, function($0, $1) {
5229
- literals.push($1);
5230
- return '@@@';
5231
- });
5232
- // Apply formatting rules
5233
- mask = mask.replace(token, function ($0) {
5234
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5235
- });
5236
- // Inline literal values back into the formatted value
5237
- return mask.replace(/@@@/g, function() {
5238
- return literals.shift();
5239
- });
5240
- };
5241
-
5187
+ */
5188
+ fecha.format = function (dateObj, mask) {
5189
+ if (typeof dateObj === 'number') {
5190
+ dateObj = new Date(dateObj);
5191
+ }
5192
+
5193
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5194
+ throw new Error('Invalid Date in fecha.format');
5195
+ }
5196
+
5197
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
5198
+
5199
+ var literals = [];
5200
+
5201
+ // Make literals inactive by replacing them with ??
5202
+ mask = mask.replace(literal, function ($0, $1) {
5203
+ literals.push($1);
5204
+ return '@@@';
5205
+ });
5206
+ // Apply formatting rules
5207
+ mask = mask.replace(token, function ($0) {
5208
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5209
+ });
5210
+ // Inline literal values back into the formatted value
5211
+ return mask.replace(/@@@/g, function () {
5212
+ return literals.shift();
5213
+ });
5214
+ };
5215
+
5242
5216
  /**
5243
5217
  * Parse a date string into an object, changes - into /
5244
5218
  * @method parse
5245
5219
  * @param {string} dateStr Date string
5246
5220
  * @param {string} format Date parse format
5247
5221
  * @returns {Date|boolean}
5248
- */
5249
- fecha.parse = function (dateStr, format) {
5250
- if (typeof format !== 'string') {
5251
- throw new Error('Invalid format in fecha.parse');
5252
- }
5253
-
5254
- format = fecha.masks[format] || format;
5255
-
5256
- // Avoid regular expression denial of service, fail early for really long strings
5257
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5258
- if (dateStr.length > 1000) {
5259
- return null;
5260
- }
5261
-
5262
- const dateInfo = {};
5263
- const parseInfo = [];
5264
- const literals = [];
5265
- format = format.replace(literal, function($0, $1) {
5266
- literals.push($1);
5267
- return '@@@';
5268
- });
5269
- let newFormat = regexEscape(format).replace(token, function ($0) {
5270
- if (parseFlags[$0]) {
5271
- const info = parseFlags[$0];
5272
- parseInfo.push(info[1]);
5273
- return '(' + info[0] + ')';
5274
- }
5275
-
5276
- return $0;
5277
- });
5278
- newFormat = newFormat.replace(/@@@/g, function() {
5279
- return literals.shift();
5280
- });
5281
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
5282
- if (!matches) {
5283
- return null;
5284
- }
5285
-
5286
- for (let i = 1; i < matches.length; i++) {
5287
- parseInfo[i - 1](dateInfo, matches[i]);
5288
- }
5289
-
5290
- const today = new Date();
5291
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5292
- dateInfo.hour = +dateInfo.hour + 12;
5293
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5294
- dateInfo.hour = 0;
5295
- }
5296
-
5297
- let date;
5298
- if (dateInfo.timezoneOffset != null) {
5299
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5300
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5301
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
5302
- } else {
5303
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5304
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
5305
- }
5306
- return date;
5307
- };
5308
-
5309
- // 导出fecha对象
5310
-
5311
-
5312
- // 以下是从date-util.js合并的函数
5313
- const newArray = function(start, end) {
5314
- let result = [];
5315
- for (let i = start; i <= end; i++) {
5316
- result.push(i);
5317
- }
5318
- return result;
5319
- };
5320
-
5321
- const getSettings = () => {
5322
- return {
5323
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5324
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5325
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5326
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5327
- amPm: ['上午', '下午']
5328
- };
5329
- };
5330
-
5331
- const toDate = function(date) {
5332
- return isDate(date) ? new Date(date) : null;
5333
- };
5334
-
5335
- const isDate = function(date) {
5336
- if (date === null || date === undefined) return false;
5337
- if (isNaN(new Date(date).getTime())) return false;
5338
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5339
- return true;
5340
- };
5341
-
5342
- const isDateObject = function(val) {
5343
- return val instanceof Date;
5344
- };
5345
-
5346
- const formatDate = function (date, format = 'yyyy-MM-dd') {
5347
- // 处理多种输入类型
5348
- if (!date) return '';
5349
-
5350
- // 如果是时间戳,转成日期对象
5351
- if (typeof date === 'number') {
5352
- date = new Date(date);
5353
- }
5354
- // 如果是字符串,转成日期对象
5355
- if (typeof date === 'string') {
5356
- date = new Date(date);
5357
- }
5358
-
5359
- // 调用toDate进一步验证和转换
5360
- date = toDate(date);
5361
- if (!date) return '';
5362
-
5363
- // 兼容大写和小写的格式标记
5364
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5365
- const lowercaseFormat = format
5366
- .replace(/YYYY/g, 'yyyy')
5367
- .replace(/D/g, 'd')
5368
-
5369
- // 使用fecha库进行格式化,支持中文配置
5370
- const str = fecha.format(date, lowercaseFormat, getSettings());
5371
- return str;
5372
- };
5373
-
5374
- const parseDate = function(string, format) {
5375
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5376
- };
5377
-
5378
- const getDayCountOfMonth = function(year, month) {
5379
- if (month === 3 || month === 5 || month === 8 || month === 10) {
5380
- return 30;
5381
- }
5382
-
5383
- if (month === 1) {
5384
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5385
- return 29;
5386
- } else {
5387
- return 28;
5388
- }
5389
- }
5390
-
5391
- return 31;
5392
- };
5393
-
5394
- const getDayCountOfYear = function(year) {
5395
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
5396
- return isLeapYear ? 366 : 365;
5397
- };
5398
-
5399
- const getFirstDayOfMonth = function(date) {
5400
- const temp = new Date(date.getTime());
5401
- temp.setDate(1);
5402
- return temp.getDay();
5403
- };
5404
-
5405
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5406
- // {prev, next} Date should work for Daylight Saving Time
5407
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5408
- const prevDate = function(date, amount = 1) {
5409
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5410
- };
5411
-
5412
- const nextDate = function(date, amount = 1) {
5413
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5414
- };
5415
-
5416
- const getStartDateOfMonth = function(year, month) {
5417
- const result = new Date(year, month, 1);
5418
- const day = result.getDay();
5419
-
5420
- if (day === 0) {
5421
- return prevDate(result, 7);
5422
- } else {
5423
- return prevDate(result, day);
5424
- }
5425
- };
5426
-
5427
- const getWeekNumber = function(date) {
5428
- // 支持多种输入类型
5429
- if (!date||!isDate(date)) {
5430
- date = new Date();
5431
- }
5432
- if (typeof date === 'string') {
5433
- date = new Date(date);
5434
- }
5435
-
5436
- // 验证日期有效性
5437
- if (!isDate(date)) return null;
5438
-
5439
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5440
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5441
- // 将星期日的星期数设为7
5442
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5443
- // 获取当年的第一天
5444
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5445
- // 计算到最近的星期四的完整周数
5446
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
5447
- // 返回周数
5448
- return weekNo;
5449
- };
5450
-
5451
- const getRangeHours = function(ranges) {
5452
- const hours = [];
5453
- let disabledHours = [];
5454
-
5455
- (ranges || []).forEach(range => {
5456
- const value = range.map(date => date.getHours());
5457
-
5458
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5459
- });
5460
-
5461
- if (disabledHours.length) {
5462
- for (let i = 0; i < 24; i++) {
5463
- hours[i] = disabledHours.indexOf(i) === -1;
5464
- }
5465
- } else {
5466
- for (let i = 0; i < 24; i++) {
5467
- hours[i] = false;
5468
- }
5469
- }
5470
-
5471
- return hours;
5472
- };
5473
-
5474
- const getPrevMonthLastDays = (date, amount) => {
5475
- if (amount <= 0) return [];
5476
- const temp = new Date(date.getTime());
5477
- temp.setDate(0);
5478
- const lastDay = temp.getDate();
5479
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
5480
- };
5481
-
5482
- const getMonthDays = (date) => {
5483
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5484
- const days = temp.getDate();
5485
- return range(days).map((_, index) => index + 1);
5486
- };
5487
-
5488
- function setRangeData(arr, start, end, value) {
5489
- for (let i = start; i < end; i++) {
5490
- arr[i] = value;
5491
- }
5492
- }
5493
-
5494
- const getRangeMinutes = function(ranges, hour) {
5495
- const minutes = new Array(60);
5496
-
5497
- if (ranges.length > 0) {
5498
- ranges.forEach(range => {
5499
- const start = range[0];
5500
- const end = range[1];
5501
- const startHour = start.getHours();
5502
- const startMinute = start.getMinutes();
5503
- const endHour = end.getHours();
5504
- const endMinute = end.getMinutes();
5505
- if (startHour === hour && endHour !== hour) {
5506
- setRangeData(minutes, startMinute, 60, true);
5507
- } else if (startHour === hour && endHour === hour) {
5508
- setRangeData(minutes, startMinute, endMinute + 1, true);
5509
- } else if (startHour !== hour && endHour === hour) {
5510
- setRangeData(minutes, 0, endMinute + 1, true);
5511
- } else if (startHour < hour && endHour > hour) {
5512
- setRangeData(minutes, 0, 60, true);
5513
- }
5514
- });
5515
- } else {
5516
- setRangeData(minutes, 0, 60, true);
5517
- }
5518
- return minutes;
5519
- };
5520
-
5521
- const range = function(n) {
5522
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5523
- return Array.apply(null, {length: n}).map((_, n) => n);
5524
- };
5525
-
5526
- const modifyDate = function(date, y, m, d) {
5527
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5528
- };
5529
-
5530
- const modifyTime = function(date, h, m, s) {
5531
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5532
- };
5533
-
5534
- const modifyWithTimeString = (date, time) => {
5535
- if (date == null || !time) {
5536
- return date;
5537
- }
5538
- time = parseDate(time, 'HH:mm:ss');
5539
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5540
- };
5541
-
5542
- const clearTime = function(date) {
5543
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5544
- };
5545
-
5546
- const clearMilliseconds = function(date) {
5547
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5548
- };
5549
-
5550
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
5551
- // TODO: refactory a more elegant solution
5552
- if (ranges.length === 0) return date;
5553
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
5554
- const ndate = normalizeDate(date);
5555
- const nranges = ranges.map(range => range.map(normalizeDate));
5556
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
5557
-
5558
- let minDate = nranges[0][0];
5559
- let maxDate = nranges[0][0];
5560
-
5561
- nranges.forEach(nrange => {
5562
- minDate = new Date(Math.min(nrange[0], minDate));
5563
- maxDate = new Date(Math.max(nrange[1], minDate));
5564
- });
5565
-
5566
- const ret = ndate < minDate ? minDate : maxDate;
5567
- // preserve Year/Month/Date
5568
- return modifyDate(
5569
- ret,
5570
- date.getFullYear(),
5571
- date.getMonth(),
5572
- date.getDate()
5573
- );
5574
- };
5575
-
5576
- const timeWithinRange = function(date, selectableRange, format) {
5577
- const limitedDate = limitTimeRange(date, selectableRange, format);
5578
- return limitedDate.getTime() === date.getTime();
5579
- };
5580
-
5581
- const changeYearMonthAndClampDate = function(date, year, month) {
5582
- // clamp date to the number of days in `year`, `month`
5583
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
5584
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5585
- return modifyDate(date, year, month, monthDate);
5586
- };
5587
-
5588
- const prevMonth = function(date) {
5589
- const year = date.getFullYear();
5590
- const month = date.getMonth();
5591
- return month === 0
5592
- ? changeYearMonthAndClampDate(date, year - 1, 11)
5593
- : changeYearMonthAndClampDate(date, year, month - 1);
5594
- };
5595
-
5596
- const nextMonth = function(date) {
5597
- const year = date.getFullYear();
5598
- const month = date.getMonth();
5599
- return month === 11
5600
- ? changeYearMonthAndClampDate(date, year + 1, 0)
5601
- : changeYearMonthAndClampDate(date, year, month + 1);
5602
- };
5603
-
5604
- const prevYear = function(date, amount = 1) {
5605
- const year = date.getFullYear();
5606
- const month = date.getMonth();
5607
- return changeYearMonthAndClampDate(date, year - amount, month);
5608
- };
5609
-
5610
- const nextYear = function(date, amount = 1) {
5611
- const year = date.getFullYear();
5612
- const month = date.getMonth();
5613
- return changeYearMonthAndClampDate(date, year + amount, month);
5614
- };
5615
-
5616
- const extractDateFormat = function(format) {
5617
- return format
5618
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
5619
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
5620
- .trim();
5621
- };
5622
-
5623
- const extractTimeFormat = function(format) {
5624
- return format
5625
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
5626
- .trim();
5627
- };
5628
-
5629
- const validateRangeInOneMonth = function(start, end) {
5630
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
5631
- };
5632
-
5222
+ */
5223
+ fecha.parse = function (dateStr, format) {
5224
+ if (typeof format !== 'string') {
5225
+ throw new Error('Invalid format in fecha.parse');
5226
+ }
5227
+
5228
+ format = fecha.masks[format] || format;
5229
+
5230
+ // Avoid regular expression denial of service, fail early for really long strings
5231
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5232
+ if (dateStr.length > 1000) {
5233
+ return null;
5234
+ }
5235
+
5236
+ var dateInfo = {};
5237
+ var parseInfo = [];
5238
+ var literals = [];
5239
+ format = format.replace(literal, function ($0, $1) {
5240
+ literals.push($1);
5241
+ return '@@@';
5242
+ });
5243
+ var newFormat = regexEscape(format).replace(token, function ($0) {
5244
+ if (parseFlags[$0]) {
5245
+ var info = parseFlags[$0];
5246
+ parseInfo.push(info[1]);
5247
+ return '(' + info[0] + ')';
5248
+ }
5249
+
5250
+ return $0;
5251
+ });
5252
+ newFormat = newFormat.replace(/@@@/g, function () {
5253
+ return literals.shift();
5254
+ });
5255
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
5256
+ if (!matches) {
5257
+ return null;
5258
+ }
5259
+
5260
+ for (var i = 1; i < matches.length; i++) {
5261
+ parseInfo[i - 1](dateInfo, matches[i]);
5262
+ }
5263
+
5264
+ var today = new Date();
5265
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5266
+ dateInfo.hour = +dateInfo.hour + 12;
5267
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5268
+ dateInfo.hour = 0;
5269
+ }
5270
+
5271
+ var date = void 0;
5272
+ if (dateInfo.timezoneOffset != null) {
5273
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5274
+ 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));
5275
+ } else {
5276
+ 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);
5277
+ }
5278
+ return date;
5279
+ };
5280
+
5281
+ // 导出fecha对象
5282
+
5283
+
5284
+ // 以下是从date-util.js合并的函数
5285
+ var newArray = function newArray(start, end) {
5286
+ var result = [];
5287
+ for (var i = start; i <= end; i++) {
5288
+ result.push(i);
5289
+ }
5290
+ return result;
5291
+ };
5292
+
5293
+ var getSettings = function getSettings() {
5294
+ return {
5295
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5296
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5297
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5298
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5299
+ amPm: ['上午', '下午']
5300
+ };
5301
+ };
5302
+
5303
+ var toDate = function toDate(date) {
5304
+ return isDate(date) ? new Date(date) : null;
5305
+ };
5306
+
5307
+ var isDate = function isDate(date) {
5308
+ if (date === null || date === undefined) return false;
5309
+ if (isNaN(new Date(date).getTime())) return false;
5310
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5311
+ return true;
5312
+ };
5313
+
5314
+ var isDateObject = function isDateObject(val) {
5315
+ return val instanceof Date;
5316
+ };
5317
+
5318
+ var formatDate = function formatDate(date) {
5319
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
5320
+
5321
+ // 处理多种输入类型
5322
+ if (!date) return '';
5323
+
5324
+ // 如果是时间戳,转成日期对象
5325
+ if (typeof date === 'number') {
5326
+ date = new Date(date);
5327
+ }
5328
+ // 如果是字符串,转成日期对象
5329
+ if (typeof date === 'string') {
5330
+ date = new Date(date);
5331
+ }
5332
+
5333
+ // 调用toDate进一步验证和转换
5334
+ date = toDate(date);
5335
+ if (!date) return '';
5336
+
5337
+ // 兼容大写和小写的格式标记
5338
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5339
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
5340
+
5341
+ // 使用fecha库进行格式化,支持中文配置
5342
+ var str = fecha.format(date, lowercaseFormat, getSettings());
5343
+ return str;
5344
+ };
5345
+
5346
+ var parseDate = function parseDate(string, format) {
5347
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5348
+ };
5349
+
5350
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
5351
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
5352
+ return 30;
5353
+ }
5354
+
5355
+ if (month === 1) {
5356
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5357
+ return 29;
5358
+ } else {
5359
+ return 28;
5360
+ }
5361
+ }
5362
+
5363
+ return 31;
5364
+ };
5365
+
5366
+ var getDayCountOfYear = function getDayCountOfYear(year) {
5367
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
5368
+ return isLeapYear ? 366 : 365;
5369
+ };
5370
+
5371
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
5372
+ var temp = new Date(date.getTime());
5373
+ temp.setDate(1);
5374
+ return temp.getDay();
5375
+ };
5376
+
5377
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5378
+ // {prev, next} Date should work for Daylight Saving Time
5379
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5380
+ var prevDate = function prevDate(date) {
5381
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5382
+
5383
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5384
+ };
5385
+
5386
+ var nextDate = function nextDate(date) {
5387
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5388
+
5389
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5390
+ };
5391
+
5392
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
5393
+ var result = new Date(year, month, 1);
5394
+ var day = result.getDay();
5395
+
5396
+ if (day === 0) {
5397
+ return prevDate(result, 7);
5398
+ } else {
5399
+ return prevDate(result, day);
5400
+ }
5401
+ };
5402
+
5403
+ var getWeekNumber = function getWeekNumber(date) {
5404
+ // 支持多种输入类型
5405
+ if (!date || !isDate(date)) {
5406
+ date = new Date();
5407
+ }
5408
+ if (typeof date === 'string') {
5409
+ date = new Date(date);
5410
+ }
5411
+
5412
+ // 验证日期有效性
5413
+ if (!isDate(date)) return null;
5414
+
5415
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5416
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5417
+ // 将星期日的星期数设为7
5418
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5419
+ // 获取当年的第一天
5420
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5421
+ // 计算到最近的星期四的完整周数
5422
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
5423
+ // 返回周数
5424
+ return weekNo;
5425
+ };
5426
+
5427
+ var getRangeHours = function getRangeHours(ranges) {
5428
+ var hours = [];
5429
+ var disabledHours = [];
5430
+
5431
+ (ranges || []).forEach(function (range) {
5432
+ var value = range.map(function (date) {
5433
+ return date.getHours();
5434
+ });
5435
+
5436
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5437
+ });
5438
+
5439
+ if (disabledHours.length) {
5440
+ for (var i = 0; i < 24; i++) {
5441
+ hours[i] = disabledHours.indexOf(i) === -1;
5442
+ }
5443
+ } else {
5444
+ for (var _i = 0; _i < 24; _i++) {
5445
+ hours[_i] = false;
5446
+ }
5447
+ }
5448
+
5449
+ return hours;
5450
+ };
5451
+
5452
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
5453
+ if (amount <= 0) return [];
5454
+ var temp = new Date(date.getTime());
5455
+ temp.setDate(0);
5456
+ var lastDay = temp.getDate();
5457
+ return range(amount).map(function (_, index) {
5458
+ return lastDay - (amount - index - 1);
5459
+ });
5460
+ };
5461
+
5462
+ var getMonthDays = function getMonthDays(date) {
5463
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5464
+ var days = temp.getDate();
5465
+ return range(days).map(function (_, index) {
5466
+ return index + 1;
5467
+ });
5468
+ };
5469
+
5470
+ function setRangeData(arr, start, end, value) {
5471
+ for (var i = start; i < end; i++) {
5472
+ arr[i] = value;
5473
+ }
5474
+ }
5475
+
5476
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
5477
+ var minutes = new Array(60);
5478
+
5479
+ if (ranges.length > 0) {
5480
+ ranges.forEach(function (range) {
5481
+ var start = range[0];
5482
+ var end = range[1];
5483
+ var startHour = start.getHours();
5484
+ var startMinute = start.getMinutes();
5485
+ var endHour = end.getHours();
5486
+ var endMinute = end.getMinutes();
5487
+ if (startHour === hour && endHour !== hour) {
5488
+ setRangeData(minutes, startMinute, 60, true);
5489
+ } else if (startHour === hour && endHour === hour) {
5490
+ setRangeData(minutes, startMinute, endMinute + 1, true);
5491
+ } else if (startHour !== hour && endHour === hour) {
5492
+ setRangeData(minutes, 0, endMinute + 1, true);
5493
+ } else if (startHour < hour && endHour > hour) {
5494
+ setRangeData(minutes, 0, 60, true);
5495
+ }
5496
+ });
5497
+ } else {
5498
+ setRangeData(minutes, 0, 60, true);
5499
+ }
5500
+ return minutes;
5501
+ };
5502
+
5503
+ var range = function range(n) {
5504
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5505
+ return Array.apply(null, { length: n }).map(function (_, n) {
5506
+ return n;
5507
+ });
5508
+ };
5509
+
5510
+ var modifyDate = function modifyDate(date, y, m, d) {
5511
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5512
+ };
5513
+
5514
+ var modifyTime = function modifyTime(date, h, m, s) {
5515
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5516
+ };
5517
+
5518
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
5519
+ if (date == null || !time) {
5520
+ return date;
5521
+ }
5522
+ time = parseDate(time, 'HH:mm:ss');
5523
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5524
+ };
5525
+
5526
+ var clearTime = function clearTime(date) {
5527
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5528
+ };
5529
+
5530
+ var clearMilliseconds = function clearMilliseconds(date) {
5531
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5532
+ };
5533
+
5534
+ var limitTimeRange = function limitTimeRange(date, ranges) {
5535
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
5536
+
5537
+ // TODO: refactory a more elegant solution
5538
+ if (ranges.length === 0) return date;
5539
+ var normalizeDate = function normalizeDate(date) {
5540
+ return fecha.parse(fecha.format(date, format), format);
5541
+ };
5542
+ var ndate = normalizeDate(date);
5543
+ var nranges = ranges.map(function (range) {
5544
+ return range.map(normalizeDate);
5545
+ });
5546
+ if (nranges.some(function (nrange) {
5547
+ return ndate >= nrange[0] && ndate <= nrange[1];
5548
+ })) return date;
5549
+
5550
+ var minDate = nranges[0][0];
5551
+ var maxDate = nranges[0][0];
5552
+
5553
+ nranges.forEach(function (nrange) {
5554
+ minDate = new Date(Math.min(nrange[0], minDate));
5555
+ maxDate = new Date(Math.max(nrange[1], minDate));
5556
+ });
5557
+
5558
+ var ret = ndate < minDate ? minDate : maxDate;
5559
+ // preserve Year/Month/Date
5560
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
5561
+ };
5562
+
5563
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
5564
+ var limitedDate = limitTimeRange(date, selectableRange, format);
5565
+ return limitedDate.getTime() === date.getTime();
5566
+ };
5567
+
5568
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
5569
+ // clamp date to the number of days in `year`, `month`
5570
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
5571
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5572
+ return modifyDate(date, year, month, monthDate);
5573
+ };
5574
+
5575
+ var prevMonth = function prevMonth(date) {
5576
+ var year = date.getFullYear();
5577
+ var month = date.getMonth();
5578
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
5579
+ };
5580
+
5581
+ var nextMonth = function nextMonth(date) {
5582
+ var year = date.getFullYear();
5583
+ var month = date.getMonth();
5584
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
5585
+ };
5586
+
5587
+ var prevYear = function prevYear(date) {
5588
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5589
+
5590
+ var year = date.getFullYear();
5591
+ var month = date.getMonth();
5592
+ return changeYearMonthAndClampDate(date, year - amount, month);
5593
+ };
5594
+
5595
+ var nextYear = function nextYear(date) {
5596
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5597
+
5598
+ var year = date.getFullYear();
5599
+ var month = date.getMonth();
5600
+ return changeYearMonthAndClampDate(date, year + amount, month);
5601
+ };
5602
+
5603
+ var extractDateFormat = function extractDateFormat(format) {
5604
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
5605
+ };
5606
+
5607
+ var extractTimeFormat = function extractTimeFormat(format) {
5608
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
5609
+ };
5610
+
5611
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
5612
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
5613
+ };
5614
+
5633
5615
  /**
5634
5616
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
5635
5617
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
5636
5618
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
5637
5619
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
5638
5620
  * @returns {number} 工作日数量
5639
- */
5640
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
5641
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5642
- throw new Error(
5643
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
5644
- );
5645
- }
5646
-
5647
- const startDateObj = new Date(start_date);
5648
- const endDateObj = new Date(end_date);
5649
-
5650
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5651
- throw new Error(
5652
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
5653
- );
5654
- }
5655
-
5656
- if (startDateObj > endDateObj) {
5657
- throw new Error('Start date should be earlier than or equal to end date.');
5658
- }
5659
-
5660
- let workdays = 0;
5661
-
5662
- // Iterate through each day in the date range
5663
- for (
5664
- let currentDate = new Date(startDateObj);
5665
- currentDate <= endDateObj;
5666
- currentDate.setDate(currentDate.getDate() + 1)
5667
- ) {
5668
- // Check if the current day is a weekend (Saturday or Sunday)
5669
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5670
-
5671
- // Check if the current day is a holiday
5672
- const isHoliday = holidays.some((holiday) => {
5673
- const holidayDate = new Date(holiday);
5674
- return currentDate.toDateString() === holidayDate.toDateString();
5675
- });
5676
-
5677
- // If it's a workday (not a weekend or holiday), increment the workdays count
5678
- if (!isWeekend && !isHoliday) {
5679
- workdays++;
5680
- }
5681
- }
5682
-
5683
- return workdays;
5684
- };
5685
-
5621
+ */
5622
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
5623
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5624
+
5625
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5626
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5627
+ }
5628
+
5629
+ var startDateObj = new Date(start_date);
5630
+ var endDateObj = new Date(end_date);
5631
+
5632
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5633
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5634
+ }
5635
+
5636
+ if (startDateObj > endDateObj) {
5637
+ throw new Error('Start date should be earlier than or equal to end date.');
5638
+ }
5639
+
5640
+ var workdays = 0;
5641
+
5642
+ // Iterate through each day in the date range
5643
+
5644
+ var _loop = function _loop(currentDate) {
5645
+ // Check if the current day is a weekend (Saturday or Sunday)
5646
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5647
+
5648
+ // Check if the current day is a holiday
5649
+ var isHoliday = holidays.some(function (holiday) {
5650
+ var holidayDate = new Date(holiday);
5651
+ return currentDate.toDateString() === holidayDate.toDateString();
5652
+ });
5653
+
5654
+ // If it's a workday (not a weekend or holiday), increment the workdays count
5655
+ if (!isWeekend && !isHoliday) {
5656
+ workdays++;
5657
+ }
5658
+ };
5659
+
5660
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
5661
+ _loop(currentDate);
5662
+ }
5663
+
5664
+ return workdays;
5665
+ };
5666
+
5686
5667
  /**
5687
5668
  * 日期加减天数
5688
5669
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
5689
5670
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
5690
5671
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
5691
- */
5692
- const dateAddDays = function (start_date, days) {
5693
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5694
- throw new Error(
5695
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
5696
- );
5697
- }
5698
-
5699
- const startDateObj = new Date(start_date);
5700
- if (isNaN(startDateObj.getTime())) {
5701
- throw new Error(
5702
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5703
- );
5704
- }
5705
-
5706
- const resultDateObj = new Date(startDateObj);
5707
- resultDateObj.setDate(resultDateObj.getDate() + days);
5708
-
5709
- const resultYear = resultDateObj.getFullYear();
5710
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5711
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5712
-
5713
- return `${resultYear}-${resultMonth}-${resultDay}`;
5714
- };
5715
-
5672
+ */
5673
+ var dateAddDays = function dateAddDays(start_date, days) {
5674
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5675
+ 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.");
5676
+ }
5677
+
5678
+ var startDateObj = new Date(start_date);
5679
+ if (isNaN(startDateObj.getTime())) {
5680
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5681
+ }
5682
+
5683
+ var resultDateObj = new Date(startDateObj);
5684
+ resultDateObj.setDate(resultDateObj.getDate() + days);
5685
+
5686
+ var resultYear = resultDateObj.getFullYear();
5687
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5688
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5689
+
5690
+ return resultYear + '-' + resultMonth + '-' + resultDay;
5691
+ };
5692
+
5716
5693
  /**
5717
5694
  * 计算两个日期之间的差值
5718
5695
  * @date 2023年12月14日
@@ -5720,182 +5697,180 @@ const dateAddDays = function (start_date, days) {
5720
5697
  * @param {String} end_date - 结束日期字符串
5721
5698
  * @param {String} unit - 单位:year/month/day
5722
5699
  * @returns {Number} 差值
5723
- */
5724
- const dateDiff = function (start_date, end_date, unit = 'day') {
5725
- // Assuming date strings are in "YYYY-MM-DD" format
5726
- var startDate = new Date(start_date);
5727
- var endDate = new Date(end_date);
5728
-
5729
- // If the date is invalid, return 0
5730
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5731
- return 0;
5732
- }
5733
-
5734
- if (unit === 'year') {
5735
- return endDate.getFullYear() - startDate.getFullYear();
5736
- } else if (unit === 'month') {
5737
- return (
5738
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
5739
- (endDate.getMonth() - startDate.getMonth())
5740
- );
5741
- } else {
5742
- // Default to day
5743
- var timeDifference = endDate - startDate;
5744
- // Calculate days (86400000 milliseconds per day)
5745
- return Math.floor(timeDifference / 86400000);
5746
- }
5747
- };
5748
-
5700
+ */
5701
+ var dateDiff = function dateDiff(start_date, end_date) {
5702
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
5703
+
5704
+ // Assuming date strings are in "YYYY-MM-DD" format
5705
+ var startDate = new Date(start_date);
5706
+ var endDate = new Date(end_date);
5707
+
5708
+ // If the date is invalid, return 0
5709
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5710
+ return 0;
5711
+ }
5712
+
5713
+ if (unit === 'year') {
5714
+ return endDate.getFullYear() - startDate.getFullYear();
5715
+ } else if (unit === 'month') {
5716
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
5717
+ } else {
5718
+ // Default to day
5719
+ var timeDifference = endDate - startDate;
5720
+ // Calculate days (86400000 milliseconds per day)
5721
+ return Math.floor(timeDifference / 86400000);
5722
+ }
5723
+ };
5724
+
5749
5725
  /**
5750
5726
  * 获取月份中的日期
5751
5727
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
5752
5728
  * @returns {number} 月份中的日期(1-31)
5753
- */
5754
- const dayOfMonth = function (date) {
5755
- if (typeof date !== 'string') {
5756
- throw new Error(
5757
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
5758
- );
5759
- }
5760
-
5761
- const dateObj = new Date(date);
5762
- if (isNaN(dateObj.getTime())) {
5763
- throw new Error(
5764
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5765
- );
5766
- }
5767
-
5768
- return dateObj.getDate();
5769
- };
5770
-
5729
+ */
5730
+ var dayOfMonth = function dayOfMonth(date) {
5731
+ if (typeof date !== 'string') {
5732
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5733
+ }
5734
+
5735
+ var dateObj = new Date(date);
5736
+ if (isNaN(dateObj.getTime())) {
5737
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5738
+ }
5739
+
5740
+ return dateObj.getDate();
5741
+ };
5742
+
5771
5743
  /**
5772
5744
  * 获取当前日期
5773
5745
  * @date 2022年5月7日
5774
5746
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
5775
5747
  * @returns {string} 当前日期的格式化字符串
5776
- */
5777
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
5778
- return formatDate(new Date(), format);
5779
- };
5780
-
5748
+ */
5749
+ var getCurrentDate = function getCurrentDate() {
5750
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
5751
+
5752
+ return formatDate(new Date(), format);
5753
+ };
5754
+
5781
5755
  /**
5782
5756
  * 获取当前日期时间
5783
5757
  * @date 2022年5月7日
5784
5758
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
5785
5759
  * @returns {string} 当前日期时间的格式化字符串
5786
- */
5787
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
5788
- return formatDate(new Date(), format);
5789
- };
5790
-
5760
+ */
5761
+ var getCurrentDateTime = function getCurrentDateTime() {
5762
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
5763
+
5764
+ return formatDate(new Date(), format);
5765
+ };
5766
+
5791
5767
  /**
5792
5768
  * 获取小时
5793
5769
  * @date 2022年5月7日
5794
5770
  * @param {Date|string} [date] - 日期对象或日期字符串
5795
5771
  * @returns {number} 小时数(0-23)
5796
- */
5797
- const getHour = function (date) {
5798
- if (!date) {
5799
- return new Date().getHours();
5800
- }
5801
- if (typeof date === 'string') {
5802
- date = new Date(date);
5803
- }
5804
- return date.getHours();
5805
- };
5806
-
5772
+ */
5773
+ var getHour = function getHour(date) {
5774
+ if (!date) {
5775
+ return new Date().getHours();
5776
+ }
5777
+ if (typeof date === 'string') {
5778
+ date = new Date(date);
5779
+ }
5780
+ return date.getHours();
5781
+ };
5782
+
5807
5783
  /**
5808
5784
  * 获取分钟
5809
5785
  * @date 2022年5月7日
5810
5786
  * @param {Date|string} [date] - 日期对象或日期字符串
5811
5787
  * @returns {number} 分钟数(0-59)
5812
- */
5813
- const getMinute = function (date) {
5814
- if (!date) {
5815
- return new Date().getMinutes();
5816
- }
5817
- if (typeof date === 'string') {
5818
- date = new Date(date);
5819
- }
5820
- return date.getMinutes();
5821
- };
5822
-
5788
+ */
5789
+ var getMinute = function getMinute(date) {
5790
+ if (!date) {
5791
+ return new Date().getMinutes();
5792
+ }
5793
+ if (typeof date === 'string') {
5794
+ date = new Date(date);
5795
+ }
5796
+ return date.getMinutes();
5797
+ };
5798
+
5823
5799
  /**
5824
5800
  * 获取月份
5825
5801
  * @date 2022年5月7日
5826
5802
  * @param {Date|string} [date] - 日期对象或日期字符串
5827
5803
  * @returns {number} 月份数(1-12)
5828
- */
5829
- const getMonth = function (date) {
5830
- if (!date) {
5831
- return new Date().getMonth() + 1;
5832
- }
5833
- if (typeof date === 'string') {
5834
- date = new Date(date);
5835
- }
5836
- return date.getMonth() + 1;
5837
- };
5838
-
5804
+ */
5805
+ var getMonth = function getMonth(date) {
5806
+ if (!date) {
5807
+ return new Date().getMonth() + 1;
5808
+ }
5809
+ if (typeof date === 'string') {
5810
+ date = new Date(date);
5811
+ }
5812
+ return date.getMonth() + 1;
5813
+ };
5814
+
5839
5815
  /**
5840
5816
  * 获取秒
5841
5817
  * @date 2022年5月7日
5842
5818
  * @param {Date|string} [date] - 日期对象或日期字符串
5843
5819
  * @returns {number} 秒数(0-59)
5844
- */
5845
- const getSecond = function (date) {
5846
- if (!date) {
5847
- return new Date().getSeconds();
5848
- }
5849
- if (typeof date === 'string') {
5850
- date = new Date(date);
5851
- }
5852
- return date.getSeconds();
5853
- };
5854
-
5820
+ */
5821
+ var getSecond = function getSecond(date) {
5822
+ if (!date) {
5823
+ return new Date().getSeconds();
5824
+ }
5825
+ if (typeof date === 'string') {
5826
+ date = new Date(date);
5827
+ }
5828
+ return date.getSeconds();
5829
+ };
5830
+
5855
5831
  /**
5856
5832
  * 获取星期几
5857
5833
  * @date 2022年5月7日
5858
5834
  * @param {Date|string} [date] - 日期对象或日期字符串
5859
5835
  * @returns {number} 星期几(0-6,0表示星期日)
5860
- */
5861
- const getWeekday = function (date) {
5862
- if (!date) {
5863
- return new Date().getDay();
5864
- }
5865
- if (typeof date === 'string') {
5866
- date = new Date(date);
5867
- }
5868
- return date.getDay();
5869
- };
5870
-
5871
-
5836
+ */
5837
+ var getWeekday = function getWeekday(date) {
5838
+ if (!date) {
5839
+ return new Date().getDay();
5840
+ }
5841
+ if (typeof date === 'string') {
5842
+ date = new Date(date);
5843
+ }
5844
+ return date.getDay();
5845
+ };
5846
+
5872
5847
  /**
5873
5848
  * @desc 获取上午/下午/晚上
5874
5849
  * @author huangbo
5875
5850
  * @date 2022年5月7日
5876
5851
  * @param {String} [time] - 时间
5877
- **/
5878
- const timeCycle = function (time) {
5879
- let hour = 0;
5880
- if (!time) {
5881
- hour = new Date().getHours();
5882
- } else if (typeof time === 'string') {
5883
- // 从时间字符串中提取小时
5884
- const match = time.match(/^(\d{1,2})/);
5885
- if (match) {
5886
- hour = parseInt(match[1], 10);
5887
- }
5888
- } else if (typeof time === 'number') {
5889
- hour = time;
5890
- }
5891
- // 判断时间段
5892
- if (hour >= 5 && hour < 12) {
5893
- return '上午';
5894
- } else if (hour >= 12 && hour < 18) {
5895
- return '下午';
5896
- } else {
5897
- return '晚上';
5898
- }
5852
+ **/
5853
+ var timeCycle = function timeCycle(time) {
5854
+ var hour = 0;
5855
+ if (!time) {
5856
+ hour = new Date().getHours();
5857
+ } else if (typeof time === 'string') {
5858
+ // 从时间字符串中提取小时
5859
+ var match = time.match(/^(\d{1,2})/);
5860
+ if (match) {
5861
+ hour = parseInt(match[1], 10);
5862
+ }
5863
+ } else if (typeof time === 'number') {
5864
+ hour = time;
5865
+ }
5866
+ // 判断时间段
5867
+ if (hour >= 5 && hour < 12) {
5868
+ return '上午';
5869
+ } else if (hour >= 12 && hour < 18) {
5870
+ return '下午';
5871
+ } else {
5872
+ return '晚上';
5873
+ }
5899
5874
  };
5900
5875
 
5901
5876
  /***/ }),