1
0
mirror of https://github.com/thebaer/tildes.git synced 2018-07-20 07:15:21 +00:00

Parse date from timestamp

This commit is contained in:
Matt Baer 2015-01-27 16:17:46 -05:00
parent 43b5413b79
commit 7a55895987

View File

@ -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)
}