Skip to content

Commit

Permalink
Merge pull request #41 from y0rune/update-docs-2024-12
Browse files Browse the repository at this point in the history
Changed a time.UTC into your own Local TimeZone
  • Loading branch information
y0rune authored Dec 23, 2024
2 parents 5394f32 + a8d4dea commit b8bb849
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 25 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module opsgenie-scheduler-creator

go 1.21.5
go 1.23.4

require (
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.22
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.23
github.com/sirupsen/logrus v1.9.3
)

require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.28.0 // indirect
)
22 changes: 14 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-retryablehttp v0.5.1/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.22 h1:0h+YoXSyipf6XQGyIaDg6z5jwRik1JSm+sQetnD7vGY=
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.22/go.mod h1:4OjcxgwdXzezqytxN534MooNmrxRD50geWZxTD7845s=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.23 h1:EFOD/cRfMeq+PCibHddoRTXu8CTN1m8Oj1Tk6eoz8Dw=
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.23/go.mod h1:1BK0BG3Mz//zeujilvvu3GJ0jnyZwFdT9XjznoPv6kk=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -30,8 +36,8 @@ golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ func createApi(apiKey string) *schedule.Client {
}

func getFirstMonday(year int, month time.Month) int {
t := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
t := time.Date(year, month, 1, 0, 0, 0, 0, time.Now().Local().Location())
firstMonday := ((8-int(t.Weekday()))%7 + 1)

return firstMonday
}

func getNumberOfWeeks(year int) int {
firstOfYear := time.Date(year, time.January, 1, 0, 0, 0, 0, time.UTC)
firstOfYear := time.Date(year, time.January, 1, 0, 0, 0, 0, time.Now().Local().Location())
weekday := int(firstOfYear.Weekday())
daysUntilFirstThursday := (4 - weekday + 7) % 7
daysAfterFirstThursday := 365 - daysUntilFirstThursday
Expand Down Expand Up @@ -148,7 +148,7 @@ func restrictionCreator(scheduleClient schedule.Client, scheduleID string, year
numberOfWeeks := getNumberOfWeeks(year)

// Set the next Monday at 9:00 AM
nextMonday := time.Date(year, month, int(firstMonday), startEndTime, 0, 0, 0, time.UTC)
nextMonday := time.Date(year, month, int(firstMonday), startEndTime, 0, 0, 0, time.Now().Local().Location())
for week := 1; week <= numberOfWeeks; week++ {
monday := nextMonday
nextMonday = nextMonday.AddDate(0, 0, 7)
Expand Down Expand Up @@ -224,7 +224,10 @@ func getListRotation(scheduleClient schedule.Client, scheduleID string) *schedul
func createTeamClient(apiKey string) *team.Client {
apiKey = checkApiKey(apiKey)

teamClient, err := team.NewClient(&client.Config{ApiKey: apiKey})
teamClient, err := team.NewClient(&client.Config{
ApiKey: apiKey,
LogLevel: logrus.ErrorLevel,
})

if err != nil {
fmt.Printf("TeamClient can NOT be created.\n")
Expand Down
32 changes: 23 additions & 9 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"regexp"
"testing"
"time"

"github.com/opsgenie/opsgenie-go-sdk-v2/schedule"
"github.com/opsgenie/opsgenie-go-sdk-v2/team"
Expand All @@ -26,7 +27,7 @@ const scheduleTeam string = "TestTeam"
const scheduleYear int = 2022
const scheduleEnabledFlag bool = false
const scheduleStartEndTimeOfRotation int = 9
const expetedNameOfRotation string = "w21-23.5-30.5"
const expetedNameOfRotation string = "w11-14.3-21.3"
const expectedStartDateOfRotation string = "2022-03-14"
const expectedStartEndTimeOfRotation string = "09"

Expand Down Expand Up @@ -93,24 +94,37 @@ func TestOneCreateRestriction(t *testing.T) {
restrictionCreator(*scheduleClient, scheduleTest.Id, scheduleYear, scheduleStartEndTimeOfRotation)

listRotation := getListRotation(*scheduleClient, scheduleTest.Id)
localLocation := time.Now().Local().Location()

// w21-23.5-30.5
if (listRotation.Rotations[20].Name) != expetedNameOfRotation {
exampleRotationName := listRotation.Rotations[10].Name
exampleRotationStartDate := listRotation.Rotations[10].StartDate.Format("2006-01-02")
exampleRotationStartHour := listRotation.Rotations[10].StartDate.In(localLocation).Format("15")

exampleRotationStartHourSecond := listRotation.Rotations[49].StartDate.In(localLocation).Format("15")

// w11-14.3-21.3
if exampleRotationName != expetedNameOfRotation {
fmt.Printf("Current Value: %s", exampleRotationName)
fmt.Printf("Expected: %s", expetedNameOfRotation)
t.Fatalf("Schedule has been NOT created correctly.")
}

// w11-14.3-21.3
if (listRotation.Rotations[10].StartDate).Format("2006-01-02") != expectedStartDateOfRotation {
if exampleRotationStartDate != expectedStartDateOfRotation {
fmt.Printf("Current Value: %s", exampleRotationStartDate)
fmt.Printf("Expected: %s", expectedStartDateOfRotation)
t.Fatalf("Schedule has been NOT created correctly.")
}

// w11-14.3-21.3
if (listRotation.Rotations[10].StartDate).Format("15") != expectedStartEndTimeOfRotation {
if exampleRotationStartHour != expectedStartEndTimeOfRotation {
fmt.Printf("Current Value: %s", exampleRotationStartHour)
fmt.Printf("Expected: %s", expectedStartEndTimeOfRotation)
t.Fatalf("Schedule has been NOT created correctly.")
}

// w49-5.12-12.12
if (listRotation.Rotations[49].StartDate).Format("15") != expectedStartEndTimeOfRotation {
// w49-28.11-5.12
if exampleRotationStartHourSecond != expectedStartEndTimeOfRotation {
fmt.Printf("Current Value: %s", exampleRotationStartHourSecond)
fmt.Printf("Expected: %s", expectedStartEndTimeOfRotation)
t.Fatalf("Schedule has been NOT created correctly.")
}
}
Expand Down
Binary file modified release/opsgenie-scheduler-creator-darwin-amd64
Binary file not shown.
Binary file modified release/opsgenie-scheduler-creator-linux-amd64
Binary file not shown.
Binary file modified release/opsgenie-scheduler-creator-linux-arm
Binary file not shown.
Binary file modified release/opsgenie-scheduler-creator-linux-arm64
Binary file not shown.

0 comments on commit b8bb849

Please sign in to comment.