From 4ab54153c1448b6df9701efcd4b86e63e71c0760 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Tue, 1 Feb 2022 02:07:48 -0500 Subject: add internal/feed/time*go --- internal/feed/feed.go | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'internal/feed/feed.go') diff --git a/internal/feed/feed.go b/internal/feed/feed.go index c013877..cf0fd2d 100644 --- a/internal/feed/feed.go +++ b/internal/feed/feed.go @@ -4,8 +4,6 @@ import ( "encoding/json" "fmt" // "strconv" - "regexp" - "time" ) const ( @@ -40,37 +38,6 @@ const ( // TODO: parse cpe -// partial timestamp -type PartialTime time.Time - -var partialTimeRe = regexp.MustCompile("\\A\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}Z\\z") - -// Unmarshal partial timestamp from JSON. -func (me *PartialTime) UnmarshalJSON(b []byte) error { - // decode string, check for error - var s string - if err := json.Unmarshal(b, &s); err != nil { - return err - } - - // match partial string regex - if !partialTimeRe.MatchString(s) { - return fmt.Errorf("invalid partial time string: %s", s) - } - - // correct string suffix - s = s[0:16] + ":00Z" - - // unmarshal time - var t time.Time - if err := t.UnmarshalText([]byte(s)); err != nil { - return err - } - - // return success - return nil -} - // Configuration node boolean operator. type NodeOp int @@ -666,10 +633,10 @@ type Item struct { Impact Impact `json:"impact"` // item published date - PublishedDate PartialTime `json:"publishedDate"` + PublishedDate Time `json:"publishedDate"` // last modification date - LastModifiedDate PartialTime `json:"lastModifiedDate"` + LastModifiedDate Time `json:"lastModifiedDate"` } // NVD feed @@ -687,7 +654,7 @@ type Feed struct { NumCVEs uint64 `json:"CVE_data_numberOfCVEs,string"` // data timestamp - Timestamp PartialTime `json:"CVE_data_timestamp"` + Timestamp Time `json:"CVE_data_timestamp"` // CVE items Items []Item `json:"CVE_Items"` -- cgit v1.2.3