Commit 2b1dd9c5 authored by Pablo Carranza's avatar Pablo Carranza 🦄

Simplified code and fixed datetime test

parent 11fa38ed
Pipeline #13310304 passed with stage
in 47 seconds
......@@ -2,7 +2,6 @@ package oncall
import (
"fmt"
"strconv"
"time"
pagerduty "github.com/PagerDuty/go-pagerduty"
......@@ -39,26 +38,7 @@ func GetOncallPerson(c *Config, shift string, period string) (string, error) {
// getOncallDates returns formatted dates as string for the current or future oncall shift
func getOncallDates(c *Config, offset int) (start string, end string) {
t := time.Now()
year := strconv.Itoa(t.Year())
var month string
if t.Month() < 10 {
month = "0" + strconv.Itoa(int(t.Month()))
} else {
month = strconv.Itoa(int(t.Month()))
}
// get day (considering offset too)
var day string
if (t.Day() + offset) < 10 {
day = "0" + strconv.Itoa(t.Day()+offset)
} else {
day = strconv.Itoa(t.Day() + offset)
}
// return formatted start/end dates
start = fmt.Sprintf("%s-%s-%sT%sZ", year, month, day, c.OncallStartTime)
end = fmt.Sprintf("%s-%s-%sT%sZ", year, month, day, c.OncallEndTime)
return start, end
start = fmt.Sprintf("%sT%sZ", time.Now().Add(24*time.Duration(offset)*time.Hour).Format("2006-01-02"), c.OncallStartTime)
end = fmt.Sprintf("%sT%sZ", time.Now().Add(24*time.Duration(offset)*time.Hour).Format("2006-01-02"), c.OncallEndTime)
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment