1
0
Fork 0
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:
Mikhail Iudin 2024-05-16 13:31:27 +02:00
parent 22a6483867
commit c7b8f550e5
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
2 changed files with 57 additions and 0 deletions

View file

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

View file

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