From 7a5589598763d20c287e8bbe93453ff2065e7495 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 27 Jan 2015 16:17:46 -0500 Subject: [PATCH] Parse date from timestamp --- tablizer.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tablizer.go b/tablizer.go index 6115a60..5d7e43b 100644 --- a/tablizer.go +++ b/tablizer.go @@ -70,6 +70,14 @@ func sortScore(table *Table) *Table { return table } +func parseTimestamp(ts string) time.Time { + t, err := strconv.ParseInt(ts, 10, 64) + if err != nil { + panic(err) + } + return time.Unix(t, 0) +} + func readData(path string, delimiter string, headers []string) *Table { f, _ := os.Open(path) @@ -80,8 +88,11 @@ func readData(path string, delimiter string, headers []string) *Table { s := bufio.NewScanner(f) s.Split(bufio.ScanLines) + const layout = "Jan 2, 2006 3:04pm MST" for s.Scan() { data := strings.Split(s.Text(), delimiter) + t := parseTimestamp(data[2]) + data[2] = t.UTC().Format(layout) row := &Row{Data: data} rows = append(rows, *row) }