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:
parent
43b5413b79
commit
7a55895987
11
tablizer.go
11
tablizer.go
@ -70,6 +70,14 @@ func sortScore(table *Table) *Table {
|
|||||||
return 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 {
|
func readData(path string, delimiter string, headers []string) *Table {
|
||||||
f, _ := os.Open(path)
|
f, _ := os.Open(path)
|
||||||
|
|
||||||
@ -80,8 +88,11 @@ func readData(path string, delimiter string, headers []string) *Table {
|
|||||||
s := bufio.NewScanner(f)
|
s := bufio.NewScanner(f)
|
||||||
s.Split(bufio.ScanLines)
|
s.Split(bufio.ScanLines)
|
||||||
|
|
||||||
|
const layout = "Jan 2, 2006 3:04pm MST"
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
data := strings.Split(s.Text(), delimiter)
|
data := strings.Split(s.Text(), delimiter)
|
||||||
|
t := parseTimestamp(data[2])
|
||||||
|
data[2] = t.UTC().Format(layout)
|
||||||
row := &Row{Data: data}
|
row := &Row{Data: data}
|
||||||
rows = append(rows, *row)
|
rows = append(rows, *row)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user