Skip to content

Instantly share code, notes, and snippets.

@genedna
Created August 25, 2015 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genedna/43f36e31423f1944336a to your computer and use it in GitHub Desktop.
Save genedna/43f36e31423f1944336a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sort"
"time"
)
type Master []time.Time
func (m Master) Len() int {
return len(m)
}
func (m Master) Swap(i, j int) {
m[i], m[j] = m[j], m[i]
}
func (m Master) Less(i, j int) bool {
return m[i].Before(m[j])
}
func main() {
fmt.Println("Sort begin ... ")
day := 1 * 24 * time.Hour
is := Master{
time.Now(),
time.Now().Add(1 * day),
time.Now().Add(2 * day),
time.Now().Add(5 * day),
time.Now().Add(7 * day),
time.Now().Add(-1 * day),
time.Now().Add(-2 * day),
}
sort.Sort(is)
fmt.Println(is)
fmt.Println("Sort end ...")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment