From 67aa8b642a7140f736adc5da607914148ba77b5f Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 23 Jul 2023 23:46:17 +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 | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kernel/av/av.go b/kernel/av/av.go index d2601ed83..8f8bb09ad 100644 --- a/kernel/av/av.go +++ b/kernel/av/av.go @@ -177,15 +177,22 @@ type ValueDate struct { type DateFormat string const ( - DateFormatNone DateFormat = "" + DateFormatNone DateFormat = "" + DateFormatDuration DateFormat = "duration" ) func NewFormattedValueDate(content int64, format DateFormat) (ret *ValueDate) { + formatted := time.UnixMilli(content).Format("2006-01-02 15:04") + switch format { + case DateFormatNone: + case DateFormatDuration: + formatted = time.Duration(content).String() + } ret = &ValueDate{ Content: content, Content2: 0, HasEndDate: false, - FormattedContent: time.UnixMilli(content).Format("2006-01-02 15:04"), + FormattedContent: formatted, } return } diff --git a/kernel/av/table.go b/kernel/av/table.go index 2d43a32e1..ee061fd2f 100644 --- a/kernel/av/table.go +++ b/kernel/av/table.go @@ -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, DateFormatNone)} + col.Calc.Result = &Value{Date: NewFormattedValueDate(latest-earliest, DateFormatDuration)} } } }