blob: 7ad811bfd6d9eb1b61a7b9d3e11e36101b4eddc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package gallery
import "sort"
func sortQueryPhotos(
photos []Photo,
query Query,
) {
if query.Sort == "" {
return
}
sort.SliceStable(photos, func(i, j int) bool {
switch query.Sort {
case SortByPath:
if query.Order == SortDesc {
return photos[i].RelativePath > photos[j].RelativePath
}
return photos[i].RelativePath < photos[j].RelativePath
case SortByDateTime:
if query.Order == SortAsc {
if !photos[i].DateTaken.Equal(photos[j].DateTaken) {
return photos[i].DateTaken.Before(photos[j].DateTaken)
}
return photos[i].RelativePath < photos[j].RelativePath
}
if !photos[i].DateTaken.Equal(photos[j].DateTaken) {
return photos[i].DateTaken.After(photos[j].DateTaken)
}
return photos[i].RelativePath < photos[j].RelativePath
default:
return false
}
})
}
|