From c2061dc69e7202a22affe8ab18513da17adc3f0e Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Fri, 5 Feb 2016 10:55:38 -0500 Subject: [PATCH] api: fix negative timestamps in notifications --- api/v1/models.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/api/v1/models.go b/api/v1/models.go index d0ae36a113..4f4fdda03b 100644 --- a/api/v1/models.go +++ b/api/v1/models.go @@ -208,12 +208,24 @@ func NotificationFromDatabaseModel(dbNotification database.VulnerabilityNotifica nextPageStr = DBPageNumberToString(nextPage) } + var created, notified, deleted string + if !dbNotification.Created.IsZero() { + created = fmt.Sprintf("%d", dbNotification.Created.Unix()) + } + if !dbNotification.Notified.IsZero() { + notified = fmt.Sprintf("%d", dbNotification.Notified.Unix()) + } + if !dbNotification.Deleted.IsZero() { + deleted = fmt.Sprintf("%d", dbNotification.Deleted.Unix()) + } + // TODO(jzelinskie): implement "changed" key + fmt.Println(dbNotification.Deleted.IsZero()) return Notification{ Name: dbNotification.Name, - Created: fmt.Sprintf("%d", dbNotification.Created.Unix()), - Notified: fmt.Sprintf("%d", dbNotification.Notified.Unix()), - Deleted: fmt.Sprintf("%d", dbNotification.Deleted.Unix()), + Created: created, + Notified: notified, + Deleted: deleted, Limit: limit, Page: DBPageNumberToString(page), NextPage: nextPageStr,