Skip to content

Commit

Permalink
feat(org): display time with timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Aug 29, 2024
1 parent 1032c68 commit a606f38
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
17 changes: 9 additions & 8 deletions cmd/kicker-cli/cmd/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func eventListCommand(cmd *cobra.Command, args []string) {
if len(args) > 0 {
for _, arg := range args {
if e := instance.GetEvent(arg); e != nil {
loadAndShowEventInfo(&table, dataPath, instance.Conf.Players, e)
loadAndShowEventInfo(&table, dataPath, instance.Conf.Players, e, instance.Conf.Organization.Timezone)
}
}
} else {
for _, e := range instance.Conf.Events {
loadAndShowEventInfo(&table, dataPath, instance.Conf.Players, &e)
loadAndShowEventInfo(&table, dataPath, instance.Conf.Players, &e, instance.Conf.Organization.Timezone)
}
}
if len(table) <= 1 {
Expand Down Expand Up @@ -109,13 +109,13 @@ func initEventInfoHeader() [][]string {
return table
}

func loadAndShowEventInfo(table *[][]string, dataPath string, players []entity.Player, e *entity.Event) (*model.Tournament, *entity.Record) {
func loadAndShowEventInfo(table *[][]string, dataPath string, players []entity.Player, e *entity.Event, tz string) (*model.Tournament, *entity.Record) {
t, r, err := loadEventInfo(dataPath, players, e)
if err != nil {
errorMessageAndExit(err)
}

showEvent(table, e, t, r)
showEvent(table, e, t, r, tz)
return t, r
}

Expand All @@ -133,18 +133,18 @@ func loadEventInfo(dataPath string, players []entity.Player, e *entity.Event) (*
return t, trn, nil
}

func showEvent(table *[][]string, e *entity.Event, t *model.Tournament, r *entity.Record) {
func showEvent(table *[][]string, e *entity.Event, t *model.Tournament, r *entity.Record, tz string) {
if len(eventNameTypes) > 0 && !nameTypeIncluded(t.NameType) {
return
}
if !createdBetween(t.Created) {
return
}

showInfo(table, e, t, r)
showInfo(table, e, t, r, tz)
}

func showInfo(table *[][]string, e *entity.Event, t *model.Tournament, r *entity.Record) {
func showInfo(table *[][]string, e *entity.Event, t *model.Tournament, r *entity.Record, tz string) {
var levels []string
if len(e.ITSFLevel) > 0 {
levels = append(levels, e.ITSFLevel)
Expand All @@ -155,10 +155,11 @@ func showInfo(table *[][]string, e *entity.Event, t *model.Tournament, r *entity
if len(e.KickerLevel) > 0 {
levels = append(levels, e.KickerLevel)
}
loc, _ := time.LoadLocation(tz)
*table = append(*table, []string{
e.ID,
e.Name,
t.Created.Format("2006-01-02 15:04"),
t.Created.In(loc).Format("2006-01-02 15:04"),
strings.Join(levels, "|"),
fmt.Sprintf("%d", len(r.Players)),
fmt.Sprintf("%d", len(r.AllGames)),
Expand Down
2 changes: 1 addition & 1 deletion cmd/kicker-cli/cmd/event_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var eventInfoCmd = &cobra.Command{
errorMessageAndExit("No event(s) found")
}
table := initEventInfoHeader()
t, r := loadAndShowEventInfo(&table, instance.DataPath(), instance.Conf.Players, e)
t, r := loadAndShowEventInfo(&table, instance.DataPath(), instance.Conf.Players, e, instance.Conf.Organization.Timezone)
_ = pterm.DefaultTable.WithHasHeader(!globalNoHeaders).WithData(table).WithBoxed(!globalNoBoxes).Render()
table = showGames(r.PreliminaryRounds, t.Options)
if len(table) > 0 {
Expand Down
3 changes: 2 additions & 1 deletion cmd/kicker-cli/cmd/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ var orgCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {

Check warning on line 19 in cmd/kicker-cli/cmd/organization.go

View workflow job for this annotation

GitHub Actions / run

parameter 'cmd' seems to be unused, consider removing or renaming it as _

Check warning on line 19 in cmd/kicker-cli/cmd/organization.go

View workflow job for this annotation

GitHub Actions / run

parameter 'args' seems to be unused, consider removing or renaming it as _
instance := initInstanceAndLoadConf()
var table [][]string
header := []string{"ID", "Name", "Players", "Events", "Kickertool ID"}
header := []string{"ID", "Name", "Timezone", "Players", "Events", "Kickertool ID"}
if !globalNoHeaders {
table = append(table, header)
}
table = append(table, []string{
instance.Conf.Organization.ID,
instance.Conf.Organization.Name,
instance.Conf.Organization.Timezone,
fmt.Sprintf("%d", len(instance.Conf.Players)),
fmt.Sprintf("%d", len(instance.Conf.Events)),
dashIfEmpty(instance.Conf.Organization.KickerToolID),
Expand Down
5 changes: 5 additions & 0 deletions cmd/kicker-cli/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"os"
"strconv"
"time"

"github.com/pterm/pterm"

Expand All @@ -15,6 +16,10 @@ func initInstanceAndLoadConf() *app.App {
if err != nil {
errorMessageAndExit("Not a valid kicker workspace")
}
// migration
if instance.Conf.Organization.Timezone == "" {
instance.Conf.Organization.Timezone = time.Now().Location().String()
}

return instance
}
Expand Down
9 changes: 7 additions & 2 deletions internal/entity/organization.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package entity

import (
"time"

"github.com/crispgm/kicker-cli/internal/util"
)

// Organization .
type Organization struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Timezone string `yaml:"timezone"`
KickerToolID string `yaml:"kicker_tool_id"`
}

// NewOrganization creates an organization with name and UUID
func NewOrganization(name string) *Organization {
curTime := time.Now()
return &Organization{
ID: util.UUID(),
Name: name,
ID: util.UUID(),
Name: name,
Timezone: curTime.Location().String(),
}
}

0 comments on commit a606f38

Please sign in to comment.