🎨 Improve database date field relative between filter https://github.com/siyuan-note/siyuan/issues/14091

This commit is contained in:
Daniel 2025-02-16 15:30:47 +08:00
parent d579e7511f
commit d986cfc911
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017

View File

@ -592,7 +592,23 @@ func filterRelativeTime(valueMills int64, valueIsNotEmpty bool, operator FilterO
return valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd) return valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd)
case FilterOperatorIsBetween: case FilterOperatorIsBetween:
if RelativeDateDirectionBefore == direction { if RelativeDateDirectionBefore == direction {
if RelativeDateDirectionBefore == direction2 || RelativeDateDirectionAfter == direction2 { if RelativeDateDirectionBefore == direction2 {
var leftStart, rightEnd time.Time
if otherValueStart.Before(otherValueStart2) {
leftStart = otherValueStart
} else {
leftStart = otherValueStart2
}
if otherValueEnd.Before(otherValueStart2) {
rightEnd = otherValueEnd
} else {
rightEnd = otherValueStart2
}
return (valueTime.After(leftStart) || valueTime.Equal(leftStart)) && (valueTime.Before(rightEnd) || valueTime.Equal(rightEnd))
} else if RelativeDateDirectionThis == direction2 {
return ((valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))) ||
((valueTime.After(otherValueStart2) || valueTime.Equal(otherValueStart2)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2)))
} else if RelativeDateDirectionAfter == direction2 {
var leftStart, rightEnd time.Time var leftStart, rightEnd time.Time
if otherValueStart.Before(otherValueStart2) { if otherValueStart.Before(otherValueStart2) {
leftStart = otherValueStart leftStart = otherValueStart
@ -605,15 +621,12 @@ func filterRelativeTime(valueMills int64, valueIsNotEmpty bool, operator FilterO
rightEnd = otherValueEnd rightEnd = otherValueEnd
} }
return (valueTime.After(leftStart) || valueTime.Equal(leftStart)) && (valueTime.Before(rightEnd) || valueTime.Equal(rightEnd)) return (valueTime.After(leftStart) || valueTime.Equal(leftStart)) && (valueTime.Before(rightEnd) || valueTime.Equal(rightEnd))
} else if RelativeDateDirectionThis == direction2 {
return ((valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))) ||
((valueTime.After(otherValueStart2) || valueTime.Equal(otherValueStart2)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2)))
} }
} else if RelativeDateDirectionThis == direction { } else if RelativeDateDirectionThis == direction {
return ((valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))) || return ((valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))) ||
((valueTime.After(otherValueStart2) || valueTime.Equal(otherValueStart2)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2))) ((valueTime.After(otherValueStart2) || valueTime.Equal(otherValueStart2)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2)))
} else if RelativeDateDirectionAfter == direction { } else if RelativeDateDirectionAfter == direction {
if RelativeDateDirectionBefore == direction2 || RelativeDateDirectionAfter == direction2 { if RelativeDateDirectionBefore == direction2 {
var leftStart, rightEnd time.Time var leftStart, rightEnd time.Time
if otherValueStart.Before(otherValueStart2) { if otherValueStart.Before(otherValueStart2) {
leftStart = otherValueStart leftStart = otherValueStart
@ -629,6 +642,19 @@ func filterRelativeTime(valueMills int64, valueIsNotEmpty bool, operator FilterO
} else if RelativeDateDirectionThis == direction2 { } else if RelativeDateDirectionThis == direction2 {
return ((valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))) || return ((valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))) ||
((valueTime.After(otherValueStart2) || valueTime.Equal(otherValueStart2)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2))) ((valueTime.After(otherValueStart2) || valueTime.Equal(otherValueStart2)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2)))
} else if RelativeDateDirectionAfter == direction2 {
var leftStart, rightEnd time.Time
if otherValueEnd.Before(otherValueEnd2) {
leftStart = otherValueEnd
} else {
leftStart = otherValueEnd2
}
if otherValueEnd.After(otherValueEnd2) {
rightEnd = otherValueEnd
} else {
rightEnd = otherValueEnd2
}
return (valueTime.After(leftStart) || valueTime.Equal(leftStart)) && (valueTime.Before(rightEnd) || valueTime.Equal(rightEnd))
} }
} }
return false return false