@10yun/cv-mobile-ui 0.5.42 → 0.5.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@10yun/cv-mobile-ui",
3
- "version": "0.5.42",
3
+ "version": "0.5.43",
4
4
  "description": "十云cvjs移动端ui,适用uniapp",
5
5
  "author": "10yun",
6
6
  "license": "Apache-2.0",
@@ -1,53 +1,82 @@
1
1
  /**
2
- * 判断是否在日期范围内
3
- * @param {*} monthStr
4
- * @param {*} startDateStr
5
- * @param {*} endDateStr
6
- * @returns
7
- */
8
- export function cc_date_in_scope(checkDateStr, startDateStr, endDateStr) {
9
- const checkDate = new Date(checkDateStr);
10
- // 将日期字符串转换为日期对象
11
- const startDate = new Date(startDateStr);
12
- const endDate = new Date(endDateStr);
13
- // NaN 防御
14
- if (isNaN(checkDate) || isNaN(startDate) || isNaN(endDate)) {
15
- return false;
16
- }
17
-
18
- return checkDate >= startDate && checkDate <= endDate;
19
- }
20
- /**
21
- * 判断某个月是否完全在指定时间范围内
22
- * @param {string} monthStr - 如 "2025-07"
2
+ * 判断某个时间(年/月/日/时分秒)是否完全包含在范围内
3
+ * @param {string|Date} inputStr
4
+ * - 可为 "2020"、"2020-07"、"2020-07-25"、"2020-07-25 12:00:00"
23
5
  * @param {string|Date} startDateStr - 开始时间
24
6
  * @param {string|Date} endDateStr - 结束时间
25
7
  * @returns {boolean}
26
8
  */
27
- export function cc_month_in_scope(monthStr, startDateStr, endDateStr) {
28
- const [year, month] = monthStr.split('-').map(Number);
29
- const monthStart = new Date(year, month - 1, 1, 0, 0, 0);
30
- const monthEnd = new Date(year, month, 0, 23, 59, 59); // 当月最后一天
31
-
9
+ export function cc_date_time_in_scope(inputStr, startDateStr, endDateStr) {
32
10
  const startDate = new Date(startDateStr);
33
11
  const endDate = new Date(endDateStr);
12
+ if (isNaN(startDate) || isNaN(endDate)) return false;
34
13
 
35
- return monthStart >= startDate && monthEnd <= endDate;
14
+ let inputStart, inputEnd;
15
+
16
+ if (typeof inputStr === 'string') {
17
+ if (/^\d{4}$/.test(inputStr)) {
18
+ // 年份:整年
19
+ inputStart = new Date(`${inputStr}-01-01T00:00:00`);
20
+ inputEnd = new Date(`${inputStr}-12-31T23:59:59`);
21
+ } else if (/^\d{4}-\d{2}$/.test(inputStr)) {
22
+ // 月份:整月
23
+ const [year, month] = inputStr.split('-').map(Number);
24
+ inputStart = new Date(year, month - 1, 1, 0, 0, 0);
25
+ inputEnd = new Date(year, month, 0, 23, 59, 59);
26
+ } else if (/^\d{4}-\d{2}-\d{2}$/.test(inputStr)) {
27
+ // 日期:整天
28
+ inputStart = new Date(`${inputStr}T00:00:00`);
29
+ inputEnd = new Date(`${inputStr}T23:59:59`);
30
+ } else {
31
+ // 时间点
32
+ const point = new Date(inputStr);
33
+ if (isNaN(point)) return false;
34
+ inputStart = point;
35
+ inputEnd = point;
36
+ }
37
+ } else if (inputStr instanceof Date) {
38
+ inputStart = inputStr;
39
+ inputEnd = inputStr;
40
+ } else {
41
+ return false;
42
+ }
43
+
44
+ return inputStart >= startDate && inputEnd <= endDate;
36
45
  }
37
46
  /**
38
47
  * 判断某个月是否与指定时间范围有交集
39
- * @param {string} monthStr - 如 "2025-07"
48
+ * @param {string|Date} inputStr
49
+ * - 可为 "2020"、"2020-07"、"2020-07-25"、"2020-07-25 12:00:00"
40
50
  * @param {string|Date} startDateStr - 开始时间
41
51
  * @param {string|Date} endDateStr - 结束时间
42
52
  * @returns {boolean}
43
53
  */
44
- export function cc_month_overlap_scope(monthStr, startDateStr, endDateStr) {
45
- const [year, month] = monthStr.split('-').map(Number);
46
- const monthStart = new Date(year, month - 1, 1, 0, 0, 0);
47
- const monthEnd = new Date(year, month, 0, 23, 59, 59);
48
-
54
+ export function cc_date_time_overlap_scope(inputStr, startDateStr, endDateStr) {
49
55
  const startDate = new Date(startDateStr);
50
56
  const endDate = new Date(endDateStr);
51
-
52
- return monthEnd >= startDate && monthStart <= endDate;
57
+ if (isNaN(startDate) || isNaN(endDate)) {
58
+ return false;
59
+ }
60
+ let inputStart, inputEnd;
61
+ if (/^\d{4}$/.test(inputStr)) {
62
+ // 年份:2025 → 2025-01-01 ~ 2025-12-31 23:59:59
63
+ inputStart = new Date(`${inputStr}-01-01T00:00:00`);
64
+ inputEnd = new Date(`${inputStr}-12-31T23:59:59`);
65
+ } else if (/^\d{4}-\d{2}$/.test(inputStr)) {
66
+ // 月份:2025-07 → 2025-07-01 ~ 2025-07-31
67
+ const [year, month] = inputStr.split('-').map(Number);
68
+ inputStart = new Date(year, month - 1, 1, 0, 0, 0);
69
+ inputEnd = new Date(year, month, 0, 23, 59, 59); // 当月最后一天
70
+ } else if (/^\d{4}-\d{2}-\d{2}$/.test(inputStr)) {
71
+ // 日期:2025-07-25 → 当天整天
72
+ inputStart = new Date(`${inputStr}T00:00:00`);
73
+ inputEnd = new Date(`${inputStr}T23:59:59`);
74
+ } else {
75
+ // 其他格式:默认作为精确时间点
76
+ const point = new Date(inputStr);
77
+ if (isNaN(point)) return false;
78
+ inputStart = point;
79
+ inputEnd = point;
80
+ }
81
+ return inputEnd >= startDate && inputStart <= endDate;
53
82
  }