mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-10 01:51:07 +09:00
GO-2604 Fix sorting
This commit is contained in:
parent
22a6483867
commit
c7b8f550e5
2 changed files with 57 additions and 0 deletions
|
@ -109,6 +109,60 @@ func TestKeyOrder_Compare(t *testing.T) {
|
|||
assert.Equal(t, 1, asc.Compare(a, b))
|
||||
})
|
||||
|
||||
date := time.Unix(-1, 0)
|
||||
|
||||
t.Run("asc_date_end_empty", func(t *testing.T) {
|
||||
a := testGetter{"k": pbtypes.Int64(date.Unix())}
|
||||
b := testGetter{"k": nil}
|
||||
asc := KeyOrder{
|
||||
Key: "k",
|
||||
Type: model.BlockContentDataviewSort_Asc,
|
||||
EmptyPlacement: model.BlockContentDataviewSort_End,
|
||||
IncludeTime: false,
|
||||
RelationFormat: model.RelationFormat_date,
|
||||
}
|
||||
assert.Equal(t, -1, asc.Compare(a, b))
|
||||
})
|
||||
|
||||
t.Run("desc_date_end_empty", func(t *testing.T) {
|
||||
a := testGetter{"k": pbtypes.Int64(date.Unix())}
|
||||
b := testGetter{"k": nil}
|
||||
asc := KeyOrder{
|
||||
Key: "k",
|
||||
Type: model.BlockContentDataviewSort_Desc,
|
||||
EmptyPlacement: model.BlockContentDataviewSort_End,
|
||||
IncludeTime: false,
|
||||
RelationFormat: model.RelationFormat_date,
|
||||
}
|
||||
assert.Equal(t, -1, asc.Compare(a, b))
|
||||
})
|
||||
|
||||
t.Run("asc_date_start_empty", func(t *testing.T) {
|
||||
a := testGetter{"k": pbtypes.Int64(date.Unix())}
|
||||
b := testGetter{"k": nil}
|
||||
asc := KeyOrder{
|
||||
Key: "k",
|
||||
Type: model.BlockContentDataviewSort_Asc,
|
||||
EmptyPlacement: model.BlockContentDataviewSort_Start,
|
||||
IncludeTime: false,
|
||||
RelationFormat: model.RelationFormat_date,
|
||||
}
|
||||
assert.Equal(t, 1, asc.Compare(a, b))
|
||||
})
|
||||
|
||||
t.Run("desc_date_start", func(t *testing.T) {
|
||||
a := testGetter{"k": pbtypes.Int64(date.Unix())}
|
||||
b := testGetter{"k": nil}
|
||||
asc := KeyOrder{
|
||||
Key: "k",
|
||||
Type: model.BlockContentDataviewSort_Desc,
|
||||
EmptyPlacement: model.BlockContentDataviewSort_Start,
|
||||
IncludeTime: false,
|
||||
RelationFormat: model.RelationFormat_date,
|
||||
}
|
||||
assert.Equal(t, 1, asc.Compare(a, b))
|
||||
})
|
||||
|
||||
t.Run("asc_nil_emptylast", func(t *testing.T) {
|
||||
a := testGetter{"k": pbtypes.String("a")}
|
||||
b := testGetter{"k": nil}
|
||||
|
|
|
@ -9,6 +9,9 @@ import (
|
|||
)
|
||||
|
||||
func CutValueToDay(val *types.Value) *types.Value {
|
||||
if val == nil {
|
||||
return val
|
||||
}
|
||||
t := time.Unix(int64(val.GetNumberValue()), 0)
|
||||
roundTime := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
|
||||
return pbtypes.Int64(roundTime.Unix())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue