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: Attribute View date column calculate https://github.com/siyuan-note/siyuan/issues/8757
Daniel43b4c57d01a2
diff --git a/kernel/av/av.go b/kernel/av/av.goindex 24066d4af7..d31461f804 100644--- a/kernel/av/av.go+++ b/kernel/av/av.go@@ -25,6 +25,7 @@ import ("path/filepath""strconv""strings"+ "time""github.com/88250/gulu""github.com/88250/lute/ast"@@ -166,6 +167,29 @@ func (number *ValueNumber) FormatNumber() {}}+type ValueDate struct {+ Content int64 `json:"content"`+ Content2 int64 `json:"content2"`+ HasEndDate bool `json:"hasEndDate"`+ FormattedContent string `json:"formattedContent"`+}++type DateFormat string++const (+ DateFormatNone DateFormat = ""+)++func NewFormattedValueDate(content int64, format DateFormat) (ret *ValueDate) {+ ret = &ValueDate{+ Content: content,+ Content2: 0,+ HasEndDate: false,+ FormattedContent: time.UnixMilli(content).Format("2006-01-02 15:04:05"),+ }+ return+}+// RoundUp rounds like 12.3416 -> 12.35func RoundUp(val float64, precision int) float64 {return math.Ceil(val*(math.Pow10(precision))) / math.Pow10(precision)@@ -181,12 +205,6 @@ func Round(val float64, precision int) float64 {return math.Round(val*(math.Pow10(precision))) / math.Pow10(precision)}-type ValueDate struct {- Content int64 `json:"content"`- Content2 int64 `json:"content2"`- HasEndDate bool `json:"hasEndDate"`-}-type ValueSelect struct {Content string `json:"content"`Color string `json:"color"`diff --git a/kernel/av/table.go b/kernel/av/table.goindex 5e3947f31e..2d43a32e14 100644--- a/kernel/av/table.go+++ b/kernel/av/table.go@@ -574,7 +574,7 @@ func (table *Table) calcColDate(col *TableColumn, colIndex int) {}}if 0 != earliest {- col.Calc.Result = &Value{Date: &ValueDate{Content: earliest}}+ col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, DateFormatNone)}}case CalcOperatorLatest:latest := int64(0)@@ -586,7 +586,7 @@ func (table *Table) calcColDate(col *TableColumn, colIndex int) {}}if 0 != latest {- col.Calc.Result = &Value{Date: &ValueDate{Content: latest}}+ col.Calc.Result = &Value{Date: NewFormattedValueDate(latest, DateFormatNone)}}case CalcOperatorRange:earliest := int64(0)@@ -602,7 +602,7 @@ func (table *Table) calcColDate(col *TableColumn, colIndex int) {}}if 0 != earliest && 0 != latest {- col.Calc.Result = &Value{Date: &ValueDate{Content: latest - earliest}}+ col.Calc.Result = &Value{Date: NewFormattedValueDate(latest-earliest, DateFormatNone)}}}}