diff --git a/clocks/clock.go b/clocks/clock.go index 2ce17e5f..fc4965fc 100644 --- a/clocks/clock.go +++ b/clocks/clock.go @@ -25,7 +25,11 @@ func (clock *Clock) Date() string { } 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 { diff --git a/clocks/clock_collection.go b/clocks/clock_collection.go index d81b18ff..a1c226ea 100644 --- a/clocks/clock_collection.go +++ b/clocks/clock_collection.go @@ -2,6 +2,7 @@ package clocks import ( "sort" + "time" ) type ClockCollection struct { @@ -28,10 +29,11 @@ func (clocks *ClockCollection) SortedAlphabetically() { } func (clocks *ClockCollection) SortedChronologically() { + now := time.Now() sort.Slice(clocks.Clocks, func(i, j int) bool { clock := clocks.Clocks[i] other := clocks.Clocks[j] - return clock.LocalTime().Before(other.LocalTime()) + return clock.ToLocal(now).String() < other.ToLocal(now).String() }) }