From 83143e3289b56c403d88a0a63a7b2069192081fa Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 24 Jul 2023 00:26:56 +0800 Subject: [PATCH] :art: Attribute View date column calculate https://github.com/siyuan-note/siyuan/issues/8757 --- kernel/av/av.go | 11 ++++++++--- kernel/av/table.go | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kernel/av/av.go b/kernel/av/av.go index 8f8bb09ad..7a9e4eb36 100644 --- a/kernel/av/av.go +++ b/kernel/av/av.go @@ -181,16 +181,21 @@ const ( DateFormatDuration DateFormat = "duration" ) -func NewFormattedValueDate(content int64, format DateFormat) (ret *ValueDate) { +func NewFormattedValueDate(content, content2 int64, format DateFormat) (ret *ValueDate) { formatted := time.UnixMilli(content).Format("2006-01-02 15:04") + if 0 < content2 { + formatted += " → " + time.UnixMilli(content2).Format("2006-01-02 15:04") + } switch format { case DateFormatNone: case DateFormatDuration: - formatted = time.Duration(content).String() + t1 := time.UnixMilli(content) + t2 := time.UnixMilli(content2) + formatted = util.HumanizeRelTime(t1, t2, util.Lang) } ret = &ValueDate{ Content: content, - Content2: 0, + Content2: content2, HasEndDate: false, FormattedContent: formatted, } diff --git a/kernel/av/table.go b/kernel/av/table.go index ee061fd2f..a59d11b82 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: NewFormattedValueDate(earliest, DateFormatNone)} + col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, 0, 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: NewFormattedValueDate(latest, DateFormatNone)} + col.Calc.Result = &Value{Date: NewFormattedValueDate(latest, 0, 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: NewFormattedValueDate(latest-earliest, DateFormatDuration)} + col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, latest, DateFormatDuration)} } } }