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

add hour diff in summary #4

Merged
merged 4 commits into from
Mar 25, 2024
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
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [0.5.0] - 2024-03-25
### Added
- Summary now shows time diff for worklogs

### Fixed
- Loader flickering while moving faster through calendar

## [0.4.0] - 2024-03-23
### Added
- `gojira worklogs` now have a calendar which tracks month of currently selected date
Expand Down Expand Up @@ -60,11 +67,12 @@ 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
[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
2 changes: 2 additions & 0 deletions gojira/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions gojira/dayview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 29 additions & 2 deletions gojira/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/rivo/tview"
"strings"
"time"
)

type Summary struct {
Expand All @@ -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
}
Expand All @@ -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
}
32 changes: 0 additions & 32 deletions gojira/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading