Skip to content

Commit

Permalink
Added extra check for sorting time Duration and int strings
Browse files Browse the repository at this point in the history
Signed-off-by: kadern0 <[email protected]>
  • Loading branch information
kadern0 committed Apr 12, 2020
1 parent 1de4552 commit e49d112
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/thanos/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,21 @@ func (t Table) Less(i, j int) bool {
}

func compare(s1, s2 string) bool {
// Values can be either Time, Duration or other.
s1Time, s1Err := time.Parse("02-01-2006 15:04:05", s1)
s2Time, s2Err := time.Parse("02-01-2006 15:04:05", s2)
if s1Err != nil || s2Err != nil {
return s1 < s2
s1Duration, s1Err := time.ParseDuration(s1)
s2Duration, s2Err := time.ParseDuration(s2)
if s1Err != nil || s2Err != nil {
s1Int, s1Err := strconv.Atoi(strings.Replace(s1, ",", "", -1))
s2Int, s2Err := strconv.Atoi(strings.Replace(s2, ",", "", -1))
if s1Err != nil || s2Err != nil {
return s1 < s2
}
return s1Int < s2Int
}
return s1Duration < s2Duration
}
return s1Time.Before(s2Time)
}

0 comments on commit e49d112

Please sign in to comment.