An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Support database date field relative to today's filtering https://github.com/siyuan-note/siyuan/issues/10451
Daniel3a5f222e3615
diff --git a/kernel/av/filter.go b/kernel/av/filter.goindex 25040a8bd5..adac2ddabc 100644--- a/kernel/av/filter.go+++ b/kernel/av/filter.go@@ -42,6 +42,8 @@ const (RelativeDateUnitYear)+type RelativeDateDirection int+const (RelativeDateDirectionBefore = -1RelativeDateDirectionThis = 0@@ -49,9 +51,9 @@ const ()type RelativeDate struct {- Count int // 数量- Unit RelativeDateUnit // 单位:0 天、1 周、2 月、3 年- Direction int // 方向:-1 前、0 这、1 后+ Count int // 数量+ Unit RelativeDateUnit // 单位:0 天、1 周、2 月、3 年+ Direction RelativeDateDirection // 方向:-1 前、0 这、1 后}type FilterOperator stringdiff --git a/kernel/av/table.go b/kernel/av/table.goindex 3abe9a4931..9d618304bc 100644--- a/kernel/av/table.go+++ b/kernel/av/table.go@@ -384,13 +384,34 @@ func (value *Value) compareOperator(filter *ViewFilter) bool {var relativeTime time.Timeswitch unit {case RelativeDateUnitDay:- relativeTime = now.AddDate(0, 0, count*direction)+ relativeTime = now.AddDate(0, 0, count*int(direction))+ if FilterOperatorIsBetween == operator && RelativeDateDirectionThis == direction {+ // 计算今天的起始时间+ relativeTime = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())+ }+case RelativeDateUnitWeek:- relativeTime = now.AddDate(0, 0, count*7*direction)+ relativeTime = now.AddDate(0, 0, count*7*int(direction))+ if FilterOperatorIsBetween == operator && RelativeDateDirectionThis == direction {+ // 计算本周的起始时间+ weekday := int(now.Weekday())+ if 0 == weekday {+ weekday = 7+ }+ relativeTime = time.Date(now.Year(), now.Month(), now.Day()-weekday+1, 0, 0, 0, 0, now.Location())+ }case RelativeDateUnitMonth:- relativeTime = now.AddDate(0, count*direction, 0)+ relativeTime = now.AddDate(0, count*int(direction), 0)+ if FilterOperatorIsBetween == operator && RelativeDateDirectionThis == direction {+ // 计算本月的起始时间+ relativeTime = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())+ }case RelativeDateUnitYear:- relativeTime = now.AddDate(count*direction, 0, 0)+ relativeTime = now.AddDate(count*int(direction), 0, 0)+ if FilterOperatorIsBetween == operator && RelativeDateDirectionThis == direction {+ // 计算今年的起始时间+ relativeTime = time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())+ }}valueTime := time.UnixMilli(value.Date.Content)@@ -412,13 +433,33 @@ func (value *Value) compareOperator(filter *ViewFilter) bool {unit2 := filter.RelativeDate2.Unitswitch unit2 {case RelativeDateUnitDay:- relativeTime2 = now.AddDate(0, 0, count*direction)+ relativeTime2 = now.AddDate(0, 0, count*int(direction))+ if RelativeDateDirectionThis == direction {+ // 计算今天的结束时间+ relativeTime2 = time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999999999, now.Location())+ }case RelativeDateUnitWeek:- relativeTime2 = now.AddDate(0, 0, count*7*direction)+ relativeTime2 = now.AddDate(0, 0, count*7*int(direction))+ if RelativeDateDirectionThis == direction {+ // 计算本周的结束时间+ weekday := int(now.Weekday())+ if 0 == weekday {+ weekday = 7+ }+ relativeTime2 = time.Date(now.Year(), now.Month(), now.Day()-weekday+7, 23, 59, 59, 999999999, now.Location())+ }case RelativeDateUnitMonth:- relativeTime2 = now.AddDate(0, count*direction, 0)+ relativeTime2 = now.AddDate(0, count*int(direction), 0)+ if RelativeDateDirectionThis == direction {+ // 计算本月的结束时间+ relativeTime2 = time.Date(now.Year(), now.Month()+1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)+ }case RelativeDateUnitYear:- relativeTime2 = now.AddDate(count*direction, 0, 0)+ relativeTime2 = now.AddDate(count*int(direction), 0, 0)+ if RelativeDateDirectionThis == direction {+ // 计算今年的结束时间+ relativeTime2 = time.Date(now.Year()+1, 1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)+ }}return (valueTime.After(relativeTime) || valueTime.Equal(relativeTime)) && (valueTime.Before(relativeTime2) || valueTime.Equal(relativeTime2))}