diff options
author | Ben Morrison <ben@gbmor.dev> | 2020-06-21 01:24:23 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2020-06-21 01:24:23 -0400 |
commit | 24e86fbcc7d8c4332290428959228d1df23f8872 (patch) | |
tree | fe72eeea29e2a107d0acaa35766e064ef347aa85 /registry | |
parent | 3278fe2b75b6335a06805a589ddae424dcdc0e89 (diff) | |
download | getwtxt-24e86fbcc7d8c4332290428959228d1df23f8872.tar.gz |
conditionally parsing datestamp as either rfc3339Nano or rfc3339 v0.4.14
Diffstat (limited to 'registry')
-rw-r--r-- | registry/fetch.go | 15 | ||||
-rw-r--r-- | registry/fetch_test.go | 11 |
2 files changed, 7 insertions, 19 deletions
diff --git a/registry/fetch.go b/registry/fetch.go index 9adf4ec..efa9fcf 100644 --- a/registry/fetch.go +++ b/registry/fetch.go @@ -25,7 +25,6 @@ import ( "fmt" "io/ioutil" "net/http" - "regexp" "strings" "sync" "time" @@ -185,8 +184,13 @@ func ParseUserTwtxt(twtxt []byte, nickname, urlKey string) (TimeMap, error) { return nil, fmt.Errorf("improperly formatted data in twtxt file") } - normalizedDatestamp := fixTimestamp(columns[0]) - thetime, err := time.Parse(time.RFC3339, normalizedDatestamp) + var thetime time.Time + var err error + if strings.Contains(columns[0], ".") { + thetime, err = time.Parse(time.RFC3339Nano, columns[0]) + } else { + thetime, err = time.Parse(time.RFC3339, columns[0]) + } if err != nil { erz = append(erz, []byte(fmt.Sprintf("unable to retrieve date: %v\n", err))...) } @@ -200,11 +204,6 @@ func ParseUserTwtxt(twtxt []byte, nickname, urlKey string) (TimeMap, error) { return timemap, fmt.Errorf("%v", string(erz)) } -func fixTimestamp(ts string) string { - normalizeTimestamp := regexp.MustCompile(`[\+][\d][\d][:][\d][\d]`) - return strings.TrimSpace(normalizeTimestamp.ReplaceAllString(ts, "Z")) -} - // ParseRegistryTwtxt takes output from a remote registry and outputs // the accessible user data via a slice of Users. func ParseRegistryTwtxt(twtxt []byte) ([]*User, error) { diff --git a/registry/fetch_test.go b/registry/fetch_test.go index 4eab2a4..0bf7920 100644 --- a/registry/fetch_test.go +++ b/registry/fetch_test.go @@ -273,14 +273,3 @@ var timestampCases = []struct { expected: "2020-01-14T00:19:45.092344Z", }, } - -func Test_fixTimestamp(t *testing.T) { - for _, tt := range timestampCases { - t.Run(tt.name, func(t *testing.T) { - tsout := fixTimestamp(tt.orig) - if tsout != tt.expected { - t.Errorf("Failed :: %s :: got %s expected %s", tt.name, tsout, tt.expected) - } - }) - } -} |