From d986cfc9119b48160da5babaace8a9df9db2e62c Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 16 Feb 2025 15:30:47 +0800 Subject: [PATCH] :art: Improve database date field relative between filter https://github.com/siyuan-note/siyuan/issues/14091 --- kernel/av/filter.go | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/kernel/av/filter.go b/kernel/av/filter.go index f386691d2..bac2de516 100644 --- a/kernel/av/filter.go +++ b/kernel/av/filter.go @@ -592,7 +592,23 @@ func filterRelativeTime(valueMills int64, valueIsNotEmpty bool, operator FilterO return valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd) case FilterOperatorIsBetween: 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 if otherValueStart.Before(otherValueStart2) { leftStart = otherValueStart @@ -605,15 +621,12 @@ func filterRelativeTime(valueMills int64, valueIsNotEmpty bool, operator FilterO rightEnd = otherValueEnd } 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 { 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 == direction { - if RelativeDateDirectionBefore == direction2 || RelativeDateDirectionAfter == direction2 { + if RelativeDateDirectionBefore == direction2 { var leftStart, rightEnd time.Time if otherValueStart.Before(otherValueStart2) { leftStart = otherValueStart @@ -629,6 +642,19 @@ func filterRelativeTime(valueMills int64, valueIsNotEmpty bool, operator FilterO } 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 + 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