Skip to content

Commit

Permalink
Switch ReplaceAll for Replace to support older go versions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbanham committed May 1, 2020
1 parent 6063f37 commit b99d807
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ func String(duration time.Duration, precision string) string {
// fmt.Println(human_duration.ShortString(time.Hour*24), human_duration.Hour)
func ShortString(duration time.Duration, precision string) string {
str := String(duration, precision)
str = strings.ReplaceAll(str, " ", "")
str = strings.ReplaceAll(str, "years", "y")
str = strings.ReplaceAll(str, "year", "y")
str = strings.ReplaceAll(str, "days", "d")
str = strings.ReplaceAll(str, "day", "d")
str = strings.ReplaceAll(str, "hours", "h")
str = strings.ReplaceAll(str, "hour", "h")
str = strings.ReplaceAll(str, "minutes", "m")
str = strings.ReplaceAll(str, "minute", "m")
str = strings.ReplaceAll(str, "seconds", "s")
str = strings.ReplaceAll(str, "second", "s")
str = strings.Replace(str, " ", "", -1)
str = strings.Replace(str, "years", "y", 1)
str = strings.Replace(str, "year", "y", 1)
str = strings.Replace(str, "days", "d", 1)
str = strings.Replace(str, "day", "d", 1)
str = strings.Replace(str, "hours", "h", 1)
str = strings.Replace(str, "hour", "h", 1)
str = strings.Replace(str, "minutes", "m", 1)
str = strings.Replace(str, "minute", "m", 1)
str = strings.Replace(str, "seconds", "s", 1)
str = strings.Replace(str, "second", "s", 1)
return str
}

0 comments on commit b99d807

Please sign in to comment.