mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
fix: linkage rule condition with date variable not working (#5675)
* fix: linkage rule condition with date variable not working * fix: bug * fix: bug
This commit is contained in:
parent
b2bc5ff581
commit
e218bc8d16
@ -100,7 +100,6 @@ export function getJsonLogic() {
|
|||||||
return a % b;
|
return a % b;
|
||||||
},
|
},
|
||||||
log: function (a) {
|
log: function (a) {
|
||||||
console.log(a);
|
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
$in: function (a, b) {
|
$in: function (a, b) {
|
||||||
@ -169,7 +168,6 @@ export function getJsonLogic() {
|
|||||||
// Parse both date strings
|
// Parse both date strings
|
||||||
const dateA = parseDate(a);
|
const dateA = parseDate(a);
|
||||||
const dateB = parseDate(b);
|
const dateB = parseDate(b);
|
||||||
|
|
||||||
if (!dateA || !dateB) {
|
if (!dateA || !dateB) {
|
||||||
throw new Error('Invalid date format');
|
throw new Error('Invalid date format');
|
||||||
}
|
}
|
||||||
@ -654,20 +652,22 @@ function parseYear(dateStr) {
|
|||||||
return new Date(year, 0);
|
return new Date(year, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseDate(dateStr) {
|
function parseDate(targetDateStr) {
|
||||||
dateStr = dateStr.trim();
|
let dateStr = Array.isArray(targetDateStr) ? targetDateStr[1] : targetDateStr;
|
||||||
|
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(dateStr)) {
|
||||||
if (/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) {
|
// ISO 8601 格式:YYYY-MM-DDTHH:mm:ss.sssZ
|
||||||
// It's in "YYYY-MM-DD" format
|
return new Date(dateStr); // 直接解析为 Date 对象
|
||||||
|
} else if (/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) {
|
||||||
|
// YYYY-MM-DD 格式
|
||||||
return parseFullDate(dateStr);
|
return parseFullDate(dateStr);
|
||||||
} else if (/^\d{4}-\d{2}$/.test(dateStr)) {
|
} else if (/^\d{4}-\d{2}$/.test(dateStr)) {
|
||||||
// It's in "YYYY-MM" format
|
// YYYY-MM 格式
|
||||||
return parseMonth(dateStr);
|
return parseMonth(dateStr);
|
||||||
} else if (/^\d{4}Q[1-4]$/.test(dateStr)) {
|
} else if (/^\d{4}Q[1-4]$/.test(dateStr)) {
|
||||||
// It's in "YYYYQn" format
|
// YYYYQn 格式
|
||||||
return parseQuarter(dateStr);
|
return parseQuarter(dateStr);
|
||||||
} else if (/^\d{4}$/.test(dateStr)) {
|
} else if (/^\d{4}$/.test(dateStr)) {
|
||||||
// It's in "YYYY" format
|
// YYYY 格式
|
||||||
return parseYear(dateStr);
|
return parseYear(dateStr);
|
||||||
}
|
}
|
||||||
return null; // Invalid format
|
return null; // Invalid format
|
||||||
|
Loading…
x
Reference in New Issue
Block a user