Skip to content

Commit

Permalink
oncallcalc: update date definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
brittonjg committed Sep 21, 2023
1 parent 1c2d923 commit 0130b77
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
4 changes: 4 additions & 0 deletions tools/oncallcalc/app/get_bankholiday.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package app

import (
"context"

log "github.com/sirupsen/logrus"
)

func (a *App) GetBankHolidays(ctx context.Context, year int) error {
Expand All @@ -18,5 +20,7 @@ func (a *App) GetBankHolidays(ctx context.Context, year int) error {

a.bankholidays = m

log.Infof("Bank Holiday List\n %+v\n\n", m)

return nil
}
12 changes: 1 addition & 11 deletions tools/oncallcalc/app/is_bankholiday.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@ import (
"time"
)

// isBankholiday determines if a date matches Cuvva's defintion of a bank holiday
// isBankholiday determines if a date is within the list of bankholidays
func (a *App) isBankholiday(today time.Time) bool {
tomorrow := today.Add(12 * time.Hour)
yesterday := today.Add(-12 * time.Hour)

if _, ok := a.bankholidays[yesterday.Format("2006-01-02")]; ok {
return true
}

if _, ok := a.bankholidays[today.Format("2006-01-02")]; ok {
return true
}

if _, ok := a.bankholidays[tomorrow.Format("2006-01-02")]; ok {
return true
}

return false
}
9 changes: 1 addition & 8 deletions tools/oncallcalc/app/is_weekend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ import (
"time"
)

// isWeekend determines if a date matches Cuvva's defintion of a weekend
// isWeekend determines if a times day is a Saturday or Sunday
func isWeekend(t time.Time) bool {
if t.Weekday() == time.Friday && t.Hour() >= 12 {
return true
}

if t.Weekday() == time.Saturday || t.Weekday() == time.Sunday {
return true
}

if t.Weekday() == time.Monday && t.Hour() < 12 {
return true
}

return false
}
5 changes: 4 additions & 1 deletion tools/oncallcalc/app/list_pd_shifts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
)

// PDShift is a PagerDuty representation of an on-call shift
Expand Down Expand Up @@ -49,10 +50,12 @@ func (a *App) ListPagerDutyShifts(scheduleIDs []string, start, end time.Time) ([

// if you weren't on the shift for at least 1 hour, we're skipping you
if end.Sub(start).Seconds() < (60 * time.Minute).Seconds() {
fmt.Println("Skipping short shift for [ ", pgShift.User.ID, " ] as duration was ", end.Sub(start).Minutes(), " minutes on ", pgShift.Start)
fmt.Println("Skipping short shift for [ ", pgShift.User.Email, " ] as duration was ", end.Sub(start).Minutes(), " minutes on ", pgShift.Start)
continue
}

log.Infof("Email %+v\nStart %+v End %+v\n", pgShift.User.Email, start, end)

shifts = append(shifts, &PDShift{
Email: pgShift.User.Email,
Start: start,
Expand Down
3 changes: 3 additions & 0 deletions tools/oncallcalc/commands/generate_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cuvva/cuvva-public-go/tools/oncallcalc/app"
"github.com/cuvva/cuvva-public-go/tools/oncallcalc/config"
"github.com/cuvva/cuvva-public-go/tools/oncallcalc/lib/govuk"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -19,6 +20,8 @@ func init() {
GenerateReportCmd.Flags().StringArrayVarP(&ScheduleIDs, "schedule_id", "s", []string{"PKICNIO", "PKW2AKK"}, "Schedule IDs from PagerDuty")
GenerateReportCmd.Flags().StringVarP(&TimeIn, "time", "t", "Jan 2020", "Which month and year should we look at?")
GenerateReportCmd.Flags().BoolVarP(&Verbose, "verbose", "v", false, "Verbose mode?")
// Update the log level if
log.SetLevel(log.ErrorLevel)
}

var GenerateReportCmd = &cobra.Command{
Expand Down

0 comments on commit 0130b77

Please sign in to comment.