fork(2) download
  1. package main
  2.  
  3. import "fmt"
  4. import "time"
  5. import "sort"
  6.  
  7. func main() {
  8. var events []time.Time
  9. // Functions can take types?
  10. events = make([]time.Time, 2)
  11. events[0], _ = time.Parse("15:04", "04:30")
  12. events[1], _ = time.Parse("15:04", "15:12")
  13. sort.Sort(TimeSlice(events))
  14.  
  15. fmt.Println(events)
  16. }
  17. // WTF
  18. type TimeSlice []time.Time
  19.  
  20. // Oh, the user does do it...
  21. func (p TimeSlice) Len() int { return len(p) }
  22. func (p TimeSlice) Less(i, j int) bool { return p[i].Before(p[j]) }
  23. func (p TimeSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
Success #stdin #stdout 0s 420672KB
stdin
Standard input is empty
stdout
[0000-01-01 04:30:00 +0000 UTC 0000-01-01 15:12:00 +0000 UTC]