Skip to content

Commit e1a9525

Browse files
authored
add hour diff in summary (#4)
1 parent be9e597 commit e1a9525

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
## [0.5.0] - 2024-03-25
10+
### Added
11+
- Summary now shows time diff for worklogs
12+
13+
### Fixed
14+
- Loader flickering while moving faster through calendar
15+
916
## [0.4.0] - 2024-03-23
1017
### Added
1118
- `gojira worklogs` now have a calendar which tracks month of currently selected date
@@ -60,11 +67,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6067
### Added
6168
- Initial release of gojira
6269

63-
[Unreleased]: https://github.com/jzyinq/gojira/compare/0.4.0...master
70+
[Unreleased]: https://github.com/jzyinq/gojira/compare/0.5.0...master
71+
[0.5.0]: https://github.com/jzyinq/gojira/compare/0.4.0...0.5.0
6472
[0.4.0]: https://github.com/jzyinq/gojira/compare/0.3.1...0.4.0
6573
[0.3.1]: https://github.com/jzyinq/gojira/compare/0.3.0...0.3.1
6674
[0.3.0]: https://github.com/jzyinq/gojira/compare/0.2.2...0.3.0
6775
[0.2.2]: https://github.com/jzyinq/gojira/compare/0.2.1...0.2.2
6876
[0.2.1]: https://github.com/jzyinq/gojira/compare/0.2.0...0.2.1
6977
[0.2.0]: https://github.com/jzyinq/gojira/compare/0.1.0...0.2.0
70-
[0.1.0]: https://github.com/jzyinq/gojira/tree/0.1.0
78+
[0.1.0]: https://github.com/jzyinq/gojira/tree/0.1.0

gojira/cli.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ func NewWorkLogIssues() error {
4444
return nil
4545
}
4646
if app.workLogsIssues.startDate != startDate || app.workLogsIssues.endDate != endDate {
47+
app.ui.loaderView.Show("Fetching worklogs...")
4748
app.workLogs, err = GetWorkLogs()
49+
app.ui.loaderView.Hide()
4850
if err != nil {
4951
return err
5052
}

gojira/dayview.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,11 @@ func loadWorklogs() {
103103
case loadingWorklogs <- true:
104104
go func() {
105105
defer func() { <-loadingWorklogs }()
106-
app.ui.loaderView.Show("Fetching worklogs...")
107106
err := NewWorkLogIssues()
108107
if err != nil {
109108
app.ui.errorView.ShowError(err.Error())
110109
}
111110
app.ui.dayView.update()
112-
app.ui.loaderView.Hide()
113111
}()
114112
default:
115113
// The goroutine is already loadingWorklogs, do nothing

gojira/summary.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/rivo/tview"
66
"strings"
7+
"time"
78
)
89

910
type Summary struct {
@@ -16,7 +17,7 @@ func NewSummary() *Summary {
1617
app.ui.app.Draw()
1718
}),
1819
}
19-
summary.SetText("Calendar ?h/?h")
20+
summary.SetText("Loading...")
2021
summary.SetTextAlign(tview.AlignCenter)
2122
return summary
2223
}
@@ -26,6 +27,32 @@ func (s *Summary) update() {
2627
// that's a hack to remove spaces between hours and minutes
2728
totalTimeSpent = strings.Join(strings.Fields(totalTimeSpent), "")
2829
workingHours := workingHoursInMonthToPresentDay(app.time.Year(), app.time.Month())
29-
s.SetText(fmt.Sprintf("Total %s/%dh", totalTimeSpent, workingHours))
30+
difference := workingHoursAbsoluteDiff(workingHours)
31+
status := fmt.Sprintf("Total %s/%dh", totalTimeSpent, workingHours)
32+
if difference != 0 {
33+
status = fmt.Sprintf("Total %s/%dh (%s)", totalTimeSpent, workingHours, FormatTimeSpent(difference))
34+
}
35+
s.SetText(status)
3036
s.SetTextColor(GetTimeSpentColor(app.workLogs.TotalTimeSpentToPresentDay(), workingHours))
3137
}
38+
39+
func workingHoursInMonthToPresentDay(year int, month time.Month) int {
40+
t := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
41+
totalWorkHours := 0
42+
43+
for t.Month() == month && t.Before(time.Now().Local()) {
44+
if t.Weekday() != time.Saturday && t.Weekday() != time.Sunday {
45+
totalWorkHours += 8
46+
}
47+
t = t.AddDate(0, 0, 1)
48+
}
49+
return totalWorkHours
50+
}
51+
52+
func workingHoursAbsoluteDiff(workingHours int) int {
53+
difference := workingHours*60*60 - app.workLogs.TotalTimeSpentToPresentDay()
54+
if difference < 0 {
55+
difference = -difference
56+
}
57+
return difference
58+
}

gojira/utils.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -112,40 +112,8 @@ func OpenURL(url string) {
112112
}
113113
}
114114

115-
func WeekRange(today time.Time) (time.Time, time.Time) {
116-
y, w := today.ISOWeek()
117-
firstDay := time.Date(y, 1, 1, 0, 0, 0, 0, time.UTC)
118-
for firstDay.Weekday() != time.Monday {
119-
firstDay = firstDay.AddDate(0, 0, -1)
120-
}
121-
122-
for {
123-
y1, w1 := firstDay.ISOWeek()
124-
if y1 == y && w1 == w {
125-
break
126-
}
127-
firstDay = firstDay.AddDate(0, 0, 1)
128-
}
129-
130-
lastDay := firstDay.AddDate(0, 0, 6) // Adding 6 days to get to Sunday
131-
return firstDay.Truncate(24 * time.Hour), lastDay.Truncate(24 * time.Hour)
132-
}
133-
134115
func MonthRange(t *time.Time) (time.Time, time.Time) {
135116
firstDayOfCurrentMonth := time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
136117
firstDayOfNextMonth := firstDayOfCurrentMonth.AddDate(0, 1, 0)
137118
return firstDayOfCurrentMonth, firstDayOfNextMonth
138119
}
139-
140-
func workingHoursInMonthToPresentDay(year int, month time.Month) int {
141-
t := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
142-
totalWorkHours := 0
143-
144-
for t.Month() == month && t.Before(time.Now().Local()) {
145-
if t.Weekday() != time.Saturday && t.Weekday() != time.Sunday {
146-
totalWorkHours += 8
147-
}
148-
t = t.AddDate(0, 0, 1)
149-
}
150-
return totalWorkHours
151-
}

0 commit comments

Comments
 (0)