From 5d14089290f3255e274b8faeb05d99976450e075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Zywert?= Date: Mon, 25 Mar 2024 07:36:15 +0100 Subject: [PATCH 1/4] add hour diff in summary --- gojira/summary.go | 31 +++++++++++++++++++++++++++++-- gojira/utils.go | 32 -------------------------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/gojira/summary.go b/gojira/summary.go index b4da2db..14cf41b 100644 --- a/gojira/summary.go +++ b/gojira/summary.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/rivo/tview" "strings" + "time" ) type Summary struct { @@ -16,7 +17,7 @@ func NewSummary() *Summary { app.ui.app.Draw() }), } - summary.SetText("Calendar ?h/?h") + summary.SetText("Loading...") summary.SetTextAlign(tview.AlignCenter) return summary } @@ -26,6 +27,32 @@ func (s *Summary) update() { // that's a hack to remove spaces between hours and minutes totalTimeSpent = strings.Join(strings.Fields(totalTimeSpent), "") workingHours := workingHoursInMonthToPresentDay(app.time.Year(), app.time.Month()) - s.SetText(fmt.Sprintf("Total %s/%dh", totalTimeSpent, workingHours)) + difference := workingHoursAbsoluteDiff(workingHours) + status := fmt.Sprintf("Total %s/%dh", totalTimeSpent, workingHours) + if difference != 0 { + status = fmt.Sprintf("Total %s/%dh (%s)", totalTimeSpent, workingHours, FormatTimeSpent(difference)) + } + s.SetText(status) s.SetTextColor(GetTimeSpentColor(app.workLogs.TotalTimeSpentToPresentDay(), workingHours)) } + +func workingHoursInMonthToPresentDay(year int, month time.Month) int { + t := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC) + totalWorkHours := 0 + + for t.Month() == month && t.Before(time.Now().Local()) { + if t.Weekday() != time.Saturday && t.Weekday() != time.Sunday { + totalWorkHours += 8 + } + t = t.AddDate(0, 0, 1) + } + return totalWorkHours +} + +func workingHoursAbsoluteDiff(workingHours int) int { + difference := workingHours*60*60 - app.workLogs.TotalTimeSpentToPresentDay() + if difference < 0 { + difference = -difference + } + return difference +} diff --git a/gojira/utils.go b/gojira/utils.go index 7a43db4..6aa980a 100644 --- a/gojira/utils.go +++ b/gojira/utils.go @@ -112,40 +112,8 @@ func OpenURL(url string) { } } -func WeekRange(today time.Time) (time.Time, time.Time) { - y, w := today.ISOWeek() - firstDay := time.Date(y, 1, 1, 0, 0, 0, 0, time.UTC) - for firstDay.Weekday() != time.Monday { - firstDay = firstDay.AddDate(0, 0, -1) - } - - for { - y1, w1 := firstDay.ISOWeek() - if y1 == y && w1 == w { - break - } - firstDay = firstDay.AddDate(0, 0, 1) - } - - lastDay := firstDay.AddDate(0, 0, 6) // Adding 6 days to get to Sunday - return firstDay.Truncate(24 * time.Hour), lastDay.Truncate(24 * time.Hour) -} - func MonthRange(t *time.Time) (time.Time, time.Time) { firstDayOfCurrentMonth := time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location()) firstDayOfNextMonth := firstDayOfCurrentMonth.AddDate(0, 1, 0) return firstDayOfCurrentMonth, firstDayOfNextMonth } - -func workingHoursInMonthToPresentDay(year int, month time.Month) int { - t := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC) - totalWorkHours := 0 - - for t.Month() == month && t.Before(time.Now().Local()) { - if t.Weekday() != time.Saturday && t.Weekday() != time.Sunday { - totalWorkHours += 8 - } - t = t.AddDate(0, 0, 1) - } - return totalWorkHours -} From b520a5253ec6191506af32a7b80fb75a6b06dc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Zywert?= Date: Mon, 25 Mar 2024 11:14:55 +0100 Subject: [PATCH 2/4] move loader closer to fetch --- gojira/cli.go | 2 ++ gojira/dayview.go | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gojira/cli.go b/gojira/cli.go index d402a70..994ac5d 100644 --- a/gojira/cli.go +++ b/gojira/cli.go @@ -44,7 +44,9 @@ func NewWorkLogIssues() error { return nil } if app.workLogsIssues.startDate != startDate || app.workLogsIssues.endDate != endDate { + app.ui.loaderView.Show("Fetching worklogs...") app.workLogs, err = GetWorkLogs() + app.ui.loaderView.Hide() if err != nil { return err } diff --git a/gojira/dayview.go b/gojira/dayview.go index 5deee50..39b27e7 100644 --- a/gojira/dayview.go +++ b/gojira/dayview.go @@ -103,13 +103,11 @@ func loadWorklogs() { case loadingWorklogs <- true: go func() { defer func() { <-loadingWorklogs }() - app.ui.loaderView.Show("Fetching worklogs...") err := NewWorkLogIssues() if err != nil { app.ui.errorView.ShowError(err.Error()) } app.ui.dayView.update() - app.ui.loaderView.Hide() }() default: // The goroutine is already loadingWorklogs, do nothing From a1e9ea92003c90aa2a73b36e64a910702abfc679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Zywert?= Date: Mon, 25 Mar 2024 11:16:58 +0100 Subject: [PATCH 3/4] CHANGELOG --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 171e6e3..2b4a4c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Summary now shows time diff for worklogs + +### Fixed +- Loader flickering while moving faster through calendar ## [0.4.0] - 2024-03-23 ### Added @@ -67,4 +72,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), [0.2.2]: https://github.com/jzyinq/gojira/compare/0.2.1...0.2.2 [0.2.1]: https://github.com/jzyinq/gojira/compare/0.2.0...0.2.1 [0.2.0]: https://github.com/jzyinq/gojira/compare/0.1.0...0.2.0 -[0.1.0]: https://github.com/jzyinq/gojira/tree/0.1.0 +[0.1.0]: https://github.com/jzyinq/gojira/tree/0.1.0 \ No newline at end of file From 673f09b52e4581eba85bc74134d46bb7d4c65d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Zywert?= Date: Mon, 25 Mar 2024 11:17:16 +0100 Subject: [PATCH 4/4] summary diff --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b4a4c1..e568a98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.5.0] - 2024-03-25 ### Added - Summary now shows time diff for worklogs @@ -65,7 +67,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added - Initial release of gojira -[Unreleased]: https://github.com/jzyinq/gojira/compare/0.4.0...master +[Unreleased]: https://github.com/jzyinq/gojira/compare/0.5.0...master +[0.5.0]: https://github.com/jzyinq/gojira/compare/0.4.0...0.5.0 [0.4.0]: https://github.com/jzyinq/gojira/compare/0.3.1...0.4.0 [0.3.1]: https://github.com/jzyinq/gojira/compare/0.3.0...0.3.1 [0.3.0]: https://github.com/jzyinq/gojira/compare/0.2.2...0.3.0