mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Fix clocks module chronological sorting issue #98
This commit is contained in:
commit
6a9695018d
@ -25,7 +25,11 @@ func (clock *Clock) Date() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (clock *Clock) LocalTime() time.Time {
|
func (clock *Clock) LocalTime() time.Time {
|
||||||
return time.Now().In(clock.Location)
|
return clock.ToLocal(time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (clock *Clock) ToLocal(t time.Time) time.Time {
|
||||||
|
return t.In(clock.Location)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clock *Clock) Time() string {
|
func (clock *Clock) Time() string {
|
||||||
|
@ -2,6 +2,7 @@ package clocks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClockCollection struct {
|
type ClockCollection struct {
|
||||||
@ -28,10 +29,11 @@ func (clocks *ClockCollection) SortedAlphabetically() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (clocks *ClockCollection) SortedChronologically() {
|
func (clocks *ClockCollection) SortedChronologically() {
|
||||||
|
now := time.Now()
|
||||||
sort.Slice(clocks.Clocks, func(i, j int) bool {
|
sort.Slice(clocks.Clocks, func(i, j int) bool {
|
||||||
clock := clocks.Clocks[i]
|
clock := clocks.Clocks[i]
|
||||||
other := clocks.Clocks[j]
|
other := clocks.Clocks[j]
|
||||||
|
|
||||||
return clock.LocalTime().Before(other.LocalTime())
|
return clock.ToLocal(now).String() < other.ToLocal(now).String()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user