???
This commit is contained in:
parent
fc75f205ee
commit
da432bc1db
2 changed files with 37 additions and 18 deletions
|
|
@ -10,21 +10,33 @@ type ValueFormatter func(v interface{}) string
|
|||
|
||||
// TimeValueFormatter is a ValueFormatter for timestamps.
|
||||
func TimeValueFormatter(v interface{}) string {
|
||||
return TimeValueFormatterWithFormat(v, DefaultDateFormat)
|
||||
return formatTime(v, DefaultDateFormat)
|
||||
}
|
||||
|
||||
// TimeHourValueFormatter is a ValueFormatter for timestamps.
|
||||
func TimeHourValueFormatter(v interface{}) string {
|
||||
return TimeValueFormatterWithFormat(v, DefaultDateHourFormat)
|
||||
return formatTime(v, DefaultDateHourFormat)
|
||||
}
|
||||
|
||||
// TimeMinuteValueFormatter is a ValueFormatter for timestamps.
|
||||
func TimeMinuteValueFormatter(v interface{}) string {
|
||||
return TimeValueFormatterWithFormat(v, DefaultDateMinuteFormat)
|
||||
return formatTime(v, DefaultDateMinuteFormat)
|
||||
}
|
||||
|
||||
// TimeDateValueFormatter is a ValueFormatter for timestamps.
|
||||
func TimeDateValueFormatter(v interface{}) string {
|
||||
return formatTime(v, "2006-01-02")
|
||||
}
|
||||
|
||||
// TimeValueFormatterWithFormat returns a time formatter with a given format.
|
||||
func TimeValueFormatterWithFormat(format string) ValueFormatter {
|
||||
return func(v interface{}) string {
|
||||
return formatTime(v, format)
|
||||
}
|
||||
}
|
||||
|
||||
// TimeValueFormatterWithFormat is a ValueFormatter for timestamps with a given format.
|
||||
func TimeValueFormatterWithFormat(v interface{}, dateFormat string) string {
|
||||
func formatTime(v interface{}, dateFormat string) string {
|
||||
if typed, isTyped := v.(time.Time); isTyped {
|
||||
return typed.Format(dateFormat)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue