@nutui/nutui-react 2.7.7 → 2.7.8

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.
package/dist/esm/date.js CHANGED
@@ -1,184 +1,103 @@
1
- const Utils = {
2
- /**
3
- * 是否为闫年
4
- * @return {Boolse} true|false
5
- */
6
- isLeapYear(y) {
7
- return y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
8
- },
9
- /**
10
- * 返回星期数
11
- * @return {String}
12
- */
13
- getWhatDay(year, month, day) {
14
- const date = /* @__PURE__ */ new Date(`${year}/${month}/${day}`);
15
- const index = date.getDay();
16
- const dayNames = [
17
- "星期日",
18
- "星期一",
19
- "星期二",
20
- "星期三",
21
- "星期四",
22
- "星期五",
23
- "星期六"
24
- ];
25
- return dayNames[index];
26
- },
27
- /**
28
- * 返回上一个月在当前面板中的天数
29
- * @return {Number}
30
- */
31
- getMonthPreDay(year, month) {
32
- const date = /* @__PURE__ */ new Date(`${year}/${month}/01`);
33
- let day = date.getDay();
34
- if (day === 0) {
35
- day = 7;
36
- }
37
- return day;
38
- },
39
- /**
40
- * 返回月份天数
41
- * @return {Number}
42
- */
43
- getMonthDays(year, month) {
44
- if (/^0/.test(month)) {
45
- month = month.split("")[1];
46
- }
47
- return [
48
- 0,
49
- 31,
50
- this.isLeapYear(Number(year)) ? 29 : 28,
51
- 31,
52
- 30,
53
- 31,
54
- 30,
55
- 31,
56
- 31,
57
- 30,
58
- 31,
59
- 30,
60
- 31
61
- ][month];
62
- },
63
- /**
64
- * 补齐数字位数
65
- * @return {string}
66
- */
67
- getNumTwoBit(n) {
68
- n = Number(n);
69
- return (n > 9 ? "" : "0") + n;
70
- },
71
- /**
72
- * 日期对象转成字符串
73
- * @return {string}
74
- */
75
- date2Str(date, split) {
76
- split = split || "-";
77
- const y = date.getFullYear();
78
- const m = this.getNumTwoBit(date.getMonth() + 1);
79
- const d = this.getNumTwoBit(date.getDate());
80
- return [y, m, d].join(split);
81
- },
82
- /**
83
- * 返回日期格式字符串
84
- * @param {Number} 0返回今天的日期、1返回明天的日期,2返回后天得日期,依次类推
85
- * @return {string} '2014-12-31'
86
- */
87
- getDay(i) {
88
- i = i || 0;
89
- let date = /* @__PURE__ */ new Date();
90
- const diff = i * (1e3 * 60 * 60 * 24);
91
- date = new Date(date.getTime() + diff);
92
- return this.date2Str(date);
93
- },
94
- /**
95
- * 时间比较
96
- * @return {Boolean}
97
- */
98
- compareDate(date1, date2) {
99
- const startTime = new Date(date1.replace("-", "/").replace("-", "/"));
100
- const endTime = new Date(date2.replace("-", "/").replace("-", "/"));
101
- if (startTime >= endTime) {
102
- return false;
103
- }
104
- return true;
105
- },
106
- /**
107
- * 时间是否相等
108
- * @return {Boolean}
109
- */
110
- isEqual(date1, date2) {
111
- const startTime = new Date((date1 || "").replace(/-/g, "/")).getTime();
112
- const endTime = new Date(date2.replace(/-/g, "/")).getTime();
113
- if (startTime === endTime) {
114
- return true;
115
- }
116
- return false;
117
- },
118
- getMonthWeek(year, month, date, firstDayOfWeek = 0) {
119
- const dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
120
- let w = dateNow.getDay();
121
- const d = dateNow.getDate();
122
- let remainder = 6 - w;
123
- if (firstDayOfWeek !== 0) {
124
- w = w === 0 ? 7 : w;
125
- remainder = 7 - w;
126
- }
127
- return Math.ceil((d + remainder) / 7);
128
- },
129
- getYearWeek(year, month, date, firstDayOfWeek = 0) {
130
- const dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
131
- const dateFirst = new Date(Number(year), 0, 1);
132
- const dataNumber = Math.round((dateNow.valueOf() - dateFirst.valueOf()) / 864e5);
133
- return Math.ceil((dataNumber + (dateFirst.getDay() + 1 - 1)) / 7);
134
- },
135
- getWeekDate(year, month, date, firstDayOfWeek = 0) {
136
- const dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
137
- const nowTime = dateNow.getTime();
138
- let day = dateNow.getDay();
139
- if (firstDayOfWeek === 0) {
140
- const oneDayTime2 = 24 * 60 * 60 * 1e3;
141
- const SundayTime2 = nowTime - day * oneDayTime2;
142
- const SaturdayTime = nowTime + (6 - day) * oneDayTime2;
143
- const sunday2 = this.date2Str(new Date(SundayTime2));
144
- const saturday = this.date2Str(new Date(SaturdayTime));
145
- return [sunday2, saturday];
146
- }
147
- day = day === 0 ? 7 : day;
148
- const oneDayTime = 24 * 60 * 60 * 1e3;
149
- const MondayTime = nowTime - (day - 1) * oneDayTime;
150
- const SundayTime = nowTime + (7 - day) * oneDayTime;
151
- const monday = this.date2Str(new Date(MondayTime));
152
- const sunday = this.date2Str(new Date(SundayTime));
153
- return [monday, sunday];
154
- },
155
- formatResultDate(date) {
156
- const days = [...date.split("-")];
157
- days[2] = Utils.getNumTwoBit(Number(days[2]));
158
- days[3] = `${days[0]}-${days[1]}-${days[2]}`;
159
- days[4] = Utils.getWhatDay(+days[0], +days[1], +days[2]);
160
- return days;
1
+ const isLeapYear = (y) => {
2
+ return y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
3
+ };
4
+ const getWhatDay = (year, month, day) => {
5
+ const date = new Date(year, month - 1, day);
6
+ const dayNames = [
7
+ "星期日",
8
+ "星期一",
9
+ "星期二",
10
+ "星期三",
11
+ "星期四",
12
+ "星期五",
13
+ "星期六"
14
+ ];
15
+ return dayNames[date.getDay()];
16
+ };
17
+ const getMonthPreDay = (year, month) => {
18
+ const day = new Date(year, month - 1, 1).getDay();
19
+ return day === 0 ? 7 : day;
20
+ };
21
+ const getMonthDays = (year, month) => {
22
+ if (/^0/.test(month)) {
23
+ month = month.split("")[1];
161
24
  }
25
+ return [
26
+ 0,
27
+ 31,
28
+ isLeapYear(Number(year)) ? 29 : 28,
29
+ 31,
30
+ 30,
31
+ 31,
32
+ 30,
33
+ 31,
34
+ 31,
35
+ 30,
36
+ 31,
37
+ 30,
38
+ 31
39
+ ][month];
40
+ };
41
+ const getNumTwoBit = (n) => {
42
+ return n > 9 ? `${n}` : `0${n}`;
43
+ };
44
+ const date2Str = (date, split = "-") => {
45
+ const y = date.getFullYear();
46
+ const m = getNumTwoBit(date.getMonth() + 1);
47
+ const d = getNumTwoBit(date.getDate());
48
+ return [y, m, d].join(split);
49
+ };
50
+ const getDateString = (offset = 0) => {
51
+ const date = /* @__PURE__ */ new Date();
52
+ date.setDate(date.getDate() + offset);
53
+ return date2Str(date, "-");
54
+ };
55
+ const compareDate = (date1, date2) => {
56
+ const startTime = new Date(date1.replace("-", "/").replace("-", "/"));
57
+ const endTime = new Date(date2.replace("-", "/").replace("-", "/"));
58
+ return startTime < endTime;
59
+ };
60
+ const isEqual = (date1, date2) => {
61
+ const startTime = new Date((date1 || "").replace(/-/g, "/")).getTime();
62
+ const endTime = new Date(date2.replace(/-/g, "/")).getTime();
63
+ return startTime === endTime;
64
+ };
65
+ const getWeekDate = (year, month, date, firstDayOfWeek = 0) => {
66
+ const dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
67
+ const nowTime = dateNow.getTime();
68
+ let day = dateNow.getDay();
69
+ if (firstDayOfWeek === 0) {
70
+ const oneDayTime2 = 24 * 60 * 60 * 1e3;
71
+ const SundayTime2 = nowTime - day * oneDayTime2;
72
+ const SaturdayTime = nowTime + (6 - day) * oneDayTime2;
73
+ const sunday2 = date2Str(new Date(SundayTime2));
74
+ const saturday = date2Str(new Date(SaturdayTime));
75
+ return [sunday2, saturday];
76
+ }
77
+ day = day === 0 ? 7 : day;
78
+ const oneDayTime = 24 * 60 * 60 * 1e3;
79
+ const MondayTime = nowTime - (day - 1) * oneDayTime;
80
+ const SundayTime = nowTime + (7 - day) * oneDayTime;
81
+ const monday = date2Str(new Date(MondayTime));
82
+ const sunday = date2Str(new Date(SundayTime));
83
+ return [monday, sunday];
84
+ };
85
+ const formatResultDate = (date) => {
86
+ const [year, month, day] = [...date.split("-")];
87
+ const formatterDay = getNumTwoBit(Number(day));
88
+ const formatterDate = `${year}-${month}-${day}`;
89
+ const dayOfWeek = getWhatDay(Number(year), Number(month), Number(day));
90
+ return [year, month, formatterDay, formatterDate, dayOfWeek];
162
91
  };
163
92
  const getCurrMonthData = (type, year, month) => {
164
- switch (type) {
165
- case "prev":
166
- month === 1 && (year -= 1);
167
- month = month === 1 ? 12 : --month;
168
- break;
169
- case "next":
170
- month === 12 && (year += 1);
171
- month = month === 12 ? 1 : ++month;
172
- break;
93
+ {
94
+ month === 12 && (year += 1);
95
+ month = month === 12 ? 1 : ++month;
173
96
  }
174
- return [
175
- year,
176
- Utils.getNumTwoBit(month),
177
- Utils.getMonthDays(String(year), String(month))
178
- ];
97
+ return [year, getNumTwoBit(month), getMonthDays(String(year), String(month))];
179
98
  };
180
99
  const getDaysStatus = (type, year, month) => {
181
- let days = Utils.getMonthDays(`${year}`, `${month}`);
100
+ let days = getMonthDays(`${year}`, `${month}`);
182
101
  return Array.from(Array(days), (v, k) => {
183
102
  return {
184
103
  day: k + 1,
@@ -195,12 +114,12 @@ const getPreMonthDates = (type, year, month, firstDayOfWeek) => {
195
114
  preMonth = 12;
196
115
  preYear += 1;
197
116
  }
198
- let days = Utils.getMonthPreDay(+year, +month);
117
+ let days = getMonthPreDay(+year, +month);
199
118
  days -= firstDayOfWeek;
200
119
  if (days >= 7) {
201
120
  days -= 7;
202
121
  }
203
- const preDates = Utils.getMonthDays(`${preYear}`, `${preMonth}`);
122
+ const preDates = getMonthDays(`${preYear}`, `${preMonth}`);
204
123
  const months = Array.from(Array(preDates), (v, k) => {
205
124
  return {
206
125
  day: k + 1,
@@ -212,8 +131,17 @@ const getPreMonthDates = (type, year, month, firstDayOfWeek) => {
212
131
  return months.slice(preDates - days);
213
132
  };
214
133
  export {
215
- Utils as U,
216
- getDaysStatus as a,
217
- getCurrMonthData as b,
218
- getPreMonthDates as g
134
+ getNumTwoBit as a,
135
+ getPreMonthDates as b,
136
+ compareDate as c,
137
+ date2Str as d,
138
+ getDaysStatus as e,
139
+ getMonthDays as f,
140
+ getDateString as g,
141
+ getCurrMonthData as h,
142
+ isEqual as i,
143
+ getWeekDate as j,
144
+ getWhatDay as k,
145
+ formatResultDate as l,
146
+ getMonthPreDay as m
219
147
  };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.7.7 Fri Jan 24 2025 13:55:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.7.8 Fri Feb 14 2025 16:19:53 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.7.7 Fri Jan 24 2025 13:55:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.7.8 Fri Feb 14 2025 16:19:53 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.7.7 Fri Jan 24 2025 13:55:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.7.8 Fri Feb 14 2025 16:19:53 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.7.7 Fri Jan 24 2025 13:55:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.7.8 Fri Feb 14 2025 16:19:53 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.7.7 Fri Jan 24 2025 13:55:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.7.8 Fri Feb 14 2025 16:19:53 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.7.7 Fri Jan 24 2025 13:55:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.7.8 Fri Feb 14 2025 16:19:53 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.7.7 Fri Jan 24 2025 13:55:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.7.8 Fri Feb 14 2025 16:19:53 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */