title: How to sort by time.Time
body: <p>I am trying to sort struct in Go by its member which is of type time.Time.
  the structure is as follows.</p>
  
  <pre><code>type reviews_data struct {
      review_id string
      date time.Time
      score int
      firstname string
      anonymous bool
      review_text string
      title_text string
      rating float64
      upcount int
  }
  </code></pre>
  
  <p>I have the below functions for sorting </p>
  
  <pre><code>type timeSlice []reviews_data
  
  // Forward request for length
  func (p timeSlice) Len() int {
      return len(p) 
  }
  
  // Define compare
  func (p timeSlice) Less(i, j int) bool {
      return p[i].date.Before(p[j].date)
  }
  
  // Define swap over an array
  func (p timeSlice) Swap(i, j int) {
      p[i], p[j] = p[j], p[i] 
  }
  </code></pre>
  
  <p>A map is defined as follows</p>
  
  <pre><code>var reviews_data_map = make(map[string]reviews_data)
  </code></pre>
  
  <p>After the map gets filled with values,sorting of the map by values is done as below</p>
  
  <pre><code>//Sort the map by date
      date_sorted_reviews := make(timeSlice, 0, len(reviews_data_map))
      for _, d := range reviews_data_map {
          date_sorted_reviews = append(date_sorted_reviews, d)
      }       
      sort.Sort(date_sorted_reviews)
  </code></pre>
  
  <p>The problem is that the result is not sorted.Can anyone tell me what the problem is.</p>