response times example needs some ergonomic love.

This commit is contained in:
Will Charczuk 2016-07-17 14:25:42 -07:00
parent 7ae7cc13a8
commit cea31c6c23
4 changed files with 305 additions and 3 deletions

View file

@ -18,16 +18,21 @@ func TimeHourValueFormatter(v interface{}) string {
return TimeValueFormatterWithFormat(v, DefaultDateHourFormat)
}
// TimeMinuteValueFormatter is a ValueFormatter for timestamps.
func TimeMinuteValueFormatter(v interface{}) string {
return TimeValueFormatterWithFormat(v, DefaultDateMinuteFormat)
}
// TimeValueFormatterWithFormat is a ValueFormatter for timestamps with a given format.
func TimeValueFormatterWithFormat(v interface{}, dateFormat string) string {
if typed, isTyped := v.(time.Time); isTyped {
return typed.Format(dateFormat)
}
if typed, isTyped := v.(int64); isTyped {
return time.Unix(typed, 0).Format(dateFormat)
return time.Unix(0, typed).Format(dateFormat)
}
if typed, isTyped := v.(float64); isTyped {
return time.Unix(int64(typed), 0).Format(dateFormat)
return time.Unix(0, int64(typed)).Format(dateFormat)
}
return ""
}