Skip to content

Commit

Permalink
🎨 Improve database date filed sorting #12127
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jul 29, 2024
1 parent 9a8802b commit e5078e8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions kernel/av/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package av
import (
"bytes"
"strings"
"time"

"github.com/siyuan-note/siyuan/kernel/util"
)
Expand Down Expand Up @@ -84,10 +85,23 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
if !other.Date.IsNotEmpty {
return -1
}
if value.Date.Content > other.Date.Content {

valueContent := value.Date.Content
otherContent := other.Date.Content

if value.Date.IsNotTime {
v := time.UnixMilli(valueContent)
valueContent = time.Date(v.Year(), v.Month(), v.Day(), 0, 0, 0, 0, time.Local).UnixMilli()
}
if other.Date.IsNotTime {
o := time.UnixMilli(otherContent)
otherContent = time.Date(o.Year(), o.Month(), o.Day(), 0, 0, 0, 0, time.Local).UnixMilli()
}

if valueContent > otherContent {
return 1
}
if value.Date.Content < other.Date.Content {
if valueContent < otherContent {
return -1
}
return 0
Expand Down

0 comments on commit e5078e8

Please sign in to comment.