From 77104f4e06ef8a3e5c2e8c4ce3e944c7adb34123 Mon Sep 17 00:00:00 2001 From: thewhitetulip Date: Sat, 14 Nov 2015 15:40:21 +0530 Subject: [PATCH] now we display created timestamp on tasks --- db/db.go | 14 +++++++------- templates/home.gtpl | 6 +++--- types/types.go | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/db/db.go b/db/db.go index aa61dea..d8a03dd 100644 --- a/db/db.go +++ b/db/db.go @@ -6,13 +6,11 @@ import ( _ "github.com/mattn/go-sqlite3" "github.com/thewhitetulip/task/types" "strings" + "time" ) var database *sql.DB var err error -var tag string -var name string -var tags string func init() { database, err = sql.Open("sqlite3", "./tasks.db") @@ -30,11 +28,12 @@ func GetTasks(deleted bool) []types.Task { var TaskId int var TaskTitle string var TaskContent string + var TaskCreated time.Time var getTasksql string if deleted == true { - getTasksql = "select id, title, content from task where is_deleted!='Y' order by created_date asc" + getTasksql = "select id, title, content, created_date from task where is_deleted!='Y' order by created_date asc" } else { - getTasksql = "select id, title, content from task where is_deleted='Y' order by created_date asc" + getTasksql = "select id, title, content, created_date from task where is_deleted='Y' order by created_date asc" } rows, err := database.Query(getTasksql) @@ -43,11 +42,12 @@ func GetTasks(deleted bool) []types.Task { } defer rows.Close() for rows.Next() { - err := rows.Scan(&TaskId, &TaskTitle, &TaskContent) + err := rows.Scan(&TaskId, &TaskTitle, &TaskContent, &TaskCreated) if err != nil { fmt.Println(err) } - a := types.Task{Id: TaskId, Title: TaskTitle, Content: TaskContent} + TaskCreated = TaskCreated.Local() + a := types.Task{Id: TaskId, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]} task = append(task, a) } diff --git a/templates/home.gtpl b/templates/home.gtpl index 52255d4..09e2d60 100755 --- a/templates/home.gtpl +++ b/templates/home.gtpl @@ -149,10 +149,10 @@

{{.Content}}