diff --git a/command/list.go b/command/list.go index 1e546f6..898aae5 100644 --- a/command/list.go +++ b/command/list.go @@ -5,6 +5,7 @@ import ( "log" "os" "strconv" + "time" "github.com/codegangsta/cli" "github.com/olekukonko/tablewriter" @@ -20,9 +21,9 @@ func CmdList(c *cli.Context) { var s string if isAllMode == "true" { - s = "SELECT id, title, is_done FROM todos" + s = "SELECT id, title, is_done, created_at FROM todos" } else { - s = "SELECT id, title, is_done FROM todos WHERE is_done = 0" + s = "SELECT id, title, is_done, created_at FROM todos WHERE is_done = 0" } db, err := sql.Open("sqlite3", dbPath()) @@ -43,13 +44,14 @@ func CmdList(c *cli.Context) { var id int var title string var isDone int - rows.Scan(&id, &title, &isDone) - data = append(data, []string{strconv.Itoa(id), title, doneLabel(isDone)}) + var createdAt int64 + rows.Scan(&id, &title, &isDone, &createdAt) + data = append(data, []string{strconv.Itoa(id), title, doneLabel(isDone), dateForView(createdAt)}) } if len(data) > 0 { table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"No", "Title", "Status"}) + table.SetHeader([]string{"No", "Title", "Status", "Created"}) table.SetBorder(true) table.AppendBulk(data) table.Render() @@ -62,3 +64,7 @@ func doneLabel(isDone int) string { } return "Done" } + +func dateForView(at int64) string { + return time.Unix(at, 0).Format("2006-01-02 15:04:05") +}