Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include timestamp in events #13

Merged
merged 3 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/doneill/er-cli/data"
"github.com/doneill/er-cli/utils"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -60,7 +61,7 @@ func open(file string) {
events := data.SelectPendingSyncEvents()

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "User", "Title"})
table.SetHeader([]string{"ID", "User", "Title", "Created At"})

for _, event := range events {
if event.ProfileID != 0 {
Expand All @@ -70,7 +71,8 @@ func open(file string) {
user := data.SelectUser()
users = append(users, user.Username)
}
table.Append([]string{fmt.Sprintf("%d", event.ID), users[len(users)-1], event.Title})
isoTime := utils.ConvertUnixToIso(event.CreatedAt)
table.Append([]string{fmt.Sprintf("%d", event.ID), users[len(users)-1], event.Title, isoTime})
}
table.Render()
default:
Expand Down
1 change: 1 addition & 0 deletions data/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Event struct {
RemoteID string `json:"remote_id" gorm:"column:remote_id"`
ProfileID int `json:"profile_id" gorm:"column:profile_id"`
Title string `json:"title" gorm:"column:title"`
CreatedAt int64 `json:"created_at" gorm:"created_at"`
}

type User_Profile struct {
Expand Down
17 changes: 17 additions & 0 deletions utils/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package utils

import (
"fmt"
"time"
)

// ----------------------------------------------
// exported funtions
// ----------------------------------------------

func ConvertUnixToIso(unixTime int64) string {
t := time.UnixMilli(unixTime)
fmt.Println(t)
isoTime := t.Format("2006-01-02T15:04:05.000Z")
return isoTime
}