Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Date field does not respect end time switch when exporting database block https://github.com/siyuan-note/siyuan/issues/10409

Danield2dc9623a772
diff --git a/kernel/av/table.go b/kernel/av/table.go
index c38922c0ae..d6c029a05c 100644
--- a/kernel/av/table.go
+++ b/kernel/av/table.go
@@ -1298,50 +1298,54 @@ func (table *Table) calcColDate(col *TableColumn, colIndex int) {
}
case CalcOperatorEarliest:
earliest := int64(0)
- var isNotTime bool
+ var isNotTime, hasEndDate bool
for _, row := range table.Rows {
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
if 0 == earliest || earliest > row.Cells[colIndex].Value.Date.Content {
earliest = row.Cells[colIndex].Value.Date.Content
isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
+ hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
}
}
}
if 0 != earliest {
- col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, 0, DateFormatNone, isNotTime)}
+ col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, 0, DateFormatNone, isNotTime, hasEndDate)}
}
case CalcOperatorLatest:
latest := int64(0)
- var isNotTime bool
+ var isNotTime, hasEndDate bool
for _, row := range table.Rows {
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
if 0 == latest || latest < row.Cells[colIndex].Value.Date.Content {
latest = row.Cells[colIndex].Value.Date.Content
isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
+ hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
}
}
}
if 0 != latest {
- col.Calc.Result = &Value{Date: NewFormattedValueDate(latest, 0, DateFormatNone, isNotTime)}
+ col.Calc.Result = &Value{Date: NewFormattedValueDate(latest, 0, DateFormatNone, isNotTime, hasEndDate)}
}
case CalcOperatorRange:
earliest := int64(0)
latest := int64(0)
- var isNotTime bool
+ var isNotTime, hasEndDate bool
for _, row := range table.Rows {
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
if 0 == earliest || earliest > row.Cells[colIndex].Value.Date.Content {
earliest = row.Cells[colIndex].Value.Date.Content
isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
+ hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
}
if 0 == latest || latest < row.Cells[colIndex].Value.Date.Content {
latest = row.Cells[colIndex].Value.Date.Content
isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
+ hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
}
}
}
if 0 != earliest && 0 != latest {
- col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, latest, DateFormatDuration, isNotTime)}
+ col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, latest, DateFormatDuration, isNotTime, hasEndDate)}
}
}
}
diff --git a/kernel/av/value.go b/kernel/av/value.go
index fc7e55c52f..f195af5935 100644
--- a/kernel/av/value.go
+++ b/kernel/av/value.go
@@ -301,7 +301,7 @@ const (
DateFormatDuration DateFormat = "duration"
)
-func NewFormattedValueDate(content, content2 int64, format DateFormat, isNotTime bool) (ret *ValueDate) {
+func NewFormattedValueDate(content, content2 int64, format DateFormat, isNotTime, hasEndDate bool) (ret *ValueDate) {
var formatted string
contentTime := time.UnixMilli(content)
if 0 == content || contentTime.IsZero() {
@@ -321,7 +321,7 @@ func NewFormattedValueDate(content, content2 int64, format DateFormat, isNotTime
formatted = contentTime.Format("2006-01-02 15:04")
}
- if 0 < content2 {
+ if hasEndDate {
var formattedContent2 string
content2Time := time.UnixMilli(content2)
if isNotTime {
@@ -343,7 +343,7 @@ func NewFormattedValueDate(content, content2 int64, format DateFormat, isNotTime
ret = &ValueDate{
Content: content,
Content2: content2,
- HasEndDate: false,
+ HasEndDate: hasEndDate,
IsNotTime: true,
FormattedContent: formatted,
}
diff --git a/kernel/model/export.go b/kernel/model/export.go
index 5740bd5d51..93ba47f3c7 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -117,7 +117,7 @@ func ExportAv2CSV(avID string) (zipPath string, err error) {
if nil != cell.Value {
if av.KeyTypeDate == cell.Value.Type {
if nil != cell.Value.Date {
- cell.Value.Date = av.NewFormattedValueDate(cell.Value.Date.Content, cell.Value.Date.Content2, av.DateFormatNone, cell.Value.Date.IsNotTime)
+ cell.Value.Date = av.NewFormattedValueDate(cell.Value.Date.Content, cell.Value.Date.Content2, av.DateFormatNone, cell.Value.Date.IsNotTime, cell.Value.Date.HasEndDate)
}
} else if av.KeyTypeCreated == cell.Value.Type {
if nil != cell.Value.Created {
@@ -2274,7 +2274,7 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
if nil != cell.Value {
if av.KeyTypeDate == cell.Value.Type {
if nil != cell.Value.Date {
- cell.Value.Date = av.NewFormattedValueDate(cell.Value.Date.Content, cell.Value.Date.Content2, av.DateFormatNone, cell.Value.Date.IsNotTime)
+ cell.Value.Date = av.NewFormattedValueDate(cell.Value.Date.Content, cell.Value.Date.Content2, av.DateFormatNone, cell.Value.Date.IsNotTime, cell.Value.Date.HasEndDate)
}
} else if av.KeyTypeCreated == cell.Value.Type {
if nil != cell.Value.Created {