🎨 Attribute View date column calculate https://github.com/siyuan-note/siyuan/issues/8757

This commit is contained in:
Daniel 2023-07-23 22:15:30 +08:00
parent 74e8ebeae9
commit 43b4c57d01
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 27 additions and 9 deletions

View file

@ -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.35
func 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"`

View file

@ -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)}
}
}
}