Better datetime display for problems

This commit is contained in:
Magnus Åhall 2024-07-04 09:21:24 +02:00
parent df714c750b
commit a985f531ea

View File

@ -147,11 +147,29 @@ func ProblemAcknowledge(id int, state bool) (err error) { // {{{
func (p Problem) FormattedValues() string {
out := []string{}
for key, val := range p.DatapointValues {
timeVal, ok := val.(time.Time)
if ok {
logger.Info("FOO", "timeVal", timeVal)
var keyval string
switch val.(type) {
case int:
keyval = fmt.Sprintf("%s: %d", key, val)
case string:
if str, ok := val.(string); ok {
timeVal, err := time.Parse(time.RFC3339, str)
if err == nil {
formattedTime := timeVal.Format("2006-01-02 15:04:05")
keyval = fmt.Sprintf("%s: %s", key, formattedTime)
} else {
keyval = fmt.Sprintf("%s: %s", key, val)
}
}
default:
keyval = fmt.Sprintf("%s: %v", key, val)
}
out = append(out, fmt.Sprintf("%s: %v", key, val))
out = append(out, keyval)
}
sort.Strings(out)