Skip to content

Commit

Permalink
Better date formatting: show weekday not year
Browse files Browse the repository at this point in the history
  • Loading branch information
myabc committed Feb 6, 2025
1 parent f069162 commit 1cd9a3e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion components/printer/time_entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func printTimeEntry(timeEntry *models.TimeEntry, maxIdLength int, maxActivityLen
parts = append(parts, activityStr)
}

parts = append(parts, Cyan(timeEntry.SpentOn))
parts = append(parts, Cyan(timeEntry.SpentOn.Format("Mon Jan _2")))

hoursStr := fmt.Sprintf("%.2fh", timeEntry.Hours.Hours())
parts = append(parts, hoursStr)
Expand Down
20 changes: 10 additions & 10 deletions components/printer/time_entries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func TestTimeEntry_Default(t *testing.T) {
Comment: "Glad it works!",
Project: "OpenProject",
WorkPackage: "Create Go CLI",
SpentOn: "2009-11-10",
SpentOn: time.Date(2009, time.November, 10, 0, 0, 0, 0, time.UTC),
Hours: time.Hour + 45*time.Minute,
Activity: "Development",
}

expected := fmt.Sprintf("%s %s %s %s %s %s %s\n",
printer.Red("#42"),
printer.Green("DEVELOPMENT"),
printer.Cyan("2009-11-10"),
printer.Cyan("Tue Nov 10"),
"1.75h",
printer.Yellow("OpenProject"),
printer.Cyan("Create Go CLI"),
Expand All @@ -46,7 +46,7 @@ func TestTimeEntry_Ongoing(t *testing.T) {
Comment: "Glad it works!",
Project: "OpenProject",
WorkPackage: "Create Go CLI",
SpentOn: "2009-11-10",
SpentOn: time.Date(2009, time.November, 10, 0, 0, 0, 0, time.UTC),
Hours: time.Hour + 45*time.Minute,
Activity: "Development",
Ongoing: true,
Expand All @@ -55,7 +55,7 @@ func TestTimeEntry_Ongoing(t *testing.T) {
expected := fmt.Sprintf("%s %s %s %s %s %s %s (%s)\n",
printer.Red("#42"),
printer.Green("DEVELOPMENT"),
printer.Cyan("2009-11-10"),
printer.Cyan("Tue Nov 10"),
"1.75h",
printer.Yellow("OpenProject"),
printer.Cyan("Create Go CLI"),
Expand All @@ -78,25 +78,25 @@ func TestTimeEntryList(t *testing.T) {
Comment: "Almost lost count!",
Project: "Mobile App",
WorkPackage: "Sprint Meeting",
SpentOn: "2025-02-04",
Hours: 4 * time.Hour,
SpentOn: time.Date(2025, time.February, 4, 0, 0, 0, 0, time.UTC),
Activity: "Accounting",
},
{
Id: 61,
Project: "Frontend App",
WorkPackage: "Rewrite in React",
SpentOn: "2024-11-08",
Hours: 2*time.Hour + 15*time.Minute,
SpentOn: time.Date(2024, time.November, 8, 0, 0, 0, 0, time.UTC),
Activity: "Development",
},
{
Id: 99,
Comment: "",
Project: "Customer Feedback",
WorkPackage: "Stakeholder Testing",
SpentOn: "2025-01-02",
Hours: 35 * time.Minute,
SpentOn: time.Date(2025, time.January, 2, 0, 0, 0, 0, time.UTC),
Activity: "Coordination",
Ongoing: true,
},
Expand All @@ -105,22 +105,22 @@ func TestTimeEntryList(t *testing.T) {
expected := fmt.Sprintf("%s %s %s %s %s %s %s\n",
printer.Red(" #8"),
printer.Green("ACCOUNTING"),
printer.Cyan("2025-02-04"),
printer.Cyan("Tue Feb 4"),
"4.00h",
printer.Yellow("Mobile App"),
printer.Cyan("Sprint Meeting"),
"Almost lost count!")
expected += fmt.Sprintf("%s %s %s %s %s %s\n",
printer.Red("#61"),
printer.Green("DEVELOPMENT"),
printer.Cyan("2024-11-08"),
printer.Cyan("Fri Nov 8"),
"2.25h",
printer.Yellow("Frontend App"),
printer.Cyan("Rewrite in React"))
expected += fmt.Sprintf("%s %s %s %s %s %s (%s)\n",
printer.Red("#99"),
printer.Green("COORDINATION"),
printer.Cyan("2025-01-02"),
printer.Cyan("Thu Jan 2"),
"0.58h",
printer.Yellow("Customer Feedback"),
printer.Cyan("Stakeholder Testing"),
Expand Down
5 changes: 4 additions & 1 deletion dtos/time_entry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dtos

import (
"time"

"github.com/opf/openproject-cli/models"
"github.com/sosodev/duration"
)
Expand Down Expand Up @@ -38,13 +40,14 @@ type timeEntryLinksDto struct {

func (dto *TimeEntryDto) Convert() *models.TimeEntry {
hours, _ := duration.Parse(dto.Hours)
spentOn, _ := time.Parse(time.DateOnly, dto.SpentOn)

return &models.TimeEntry{
Id: uint64(dto.Id),
Comment: dto.Comment.Raw,
Project: dto.Links.Project.Title,
WorkPackage: dto.Links.WorkPackage.Title,
SpentOn: dto.SpentOn,
SpentOn: spentOn,
Hours: hours.ToTimeDuration(),
Ongoing: dto.Ongoing,
User: dto.Links.User.Title,
Expand Down
2 changes: 1 addition & 1 deletion models/time_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type TimeEntry struct {
Comment string
Project string
WorkPackage string
SpentOn string
SpentOn time.Time
Hours time.Duration
Ongoing bool
User string
Expand Down

0 comments on commit 1cd9a3e

Please sign in to comment.