mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Maintenance window now scheduled weekly on Tuesdays (#20089)
#19031 - Maintenance window now scheduled weekly on Tuesdays # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Added/updated tests - [x] Manual QA for all new/changed functionality
This commit is contained in:
parent
4a159dd0cc
commit
f17bbb587d
3 changed files with 41 additions and 53 deletions
1
changes/19031-maintenance-windows-every-week
Normal file
1
changes/19031-maintenance-windows-every-week
Normal file
|
|
@ -0,0 +1 @@
|
|||
- Maintenance window now scheduled weekly on Tuesdays (previously monthly on the third Tuesday of the month)
|
||||
|
|
@ -475,27 +475,14 @@ func attemptCreatingEventOnUserCalendar(
|
|||
|
||||
func getPreferredCalendarEventDate(year int, month time.Month, today int) time.Time {
|
||||
const (
|
||||
// 3rd Tuesday of Month
|
||||
// Any Tuesday of Month
|
||||
preferredWeekDay = time.Tuesday
|
||||
preferredOrdinal = 3
|
||||
)
|
||||
|
||||
firstDayOfMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
|
||||
offset := int(preferredWeekDay - firstDayOfMonth.Weekday())
|
||||
if offset < 0 {
|
||||
offset += 7
|
||||
currentDate := time.Date(year, month, today, 0, 0, 0, 0, time.UTC)
|
||||
for currentDate.Weekday() != preferredWeekDay {
|
||||
currentDate = currentDate.AddDate(0, 0, 1)
|
||||
}
|
||||
preferredDate := firstDayOfMonth.AddDate(0, 0, offset+(7*(preferredOrdinal-1)))
|
||||
if today > preferredDate.Day() {
|
||||
// We are past the preferred date, so we move to next month and calculate again.
|
||||
month := month + 1
|
||||
if month == 13 {
|
||||
month = 1
|
||||
year += 1
|
||||
}
|
||||
return getPreferredCalendarEventDate(year, month, 1)
|
||||
}
|
||||
return preferredDate
|
||||
return currentDate
|
||||
}
|
||||
|
||||
func addBusinessDay(date time.Time) time.Time {
|
||||
|
|
|
|||
|
|
@ -39,28 +39,28 @@ func TestGetPreferredCalendarEventDate(t *testing.T) {
|
|||
expected time.Time
|
||||
}{
|
||||
{
|
||||
name: "March 2024 (before 3rd Tuesday)",
|
||||
name: "March 2024 (before 1st Tuesday)",
|
||||
year: 2024,
|
||||
month: 3,
|
||||
daysStart: 1,
|
||||
daysEnd: 19,
|
||||
daysEnd: 5,
|
||||
|
||||
expected: date(2024, 3, 19),
|
||||
expected: date(2024, 3, 5),
|
||||
},
|
||||
{
|
||||
name: "March 2024 (past 3rd Tuesday)",
|
||||
name: "March 2024 (past 1st Tuesday)",
|
||||
year: 2024,
|
||||
month: 3,
|
||||
daysStart: 20,
|
||||
daysEnd: 31,
|
||||
daysStart: 6,
|
||||
daysEnd: 12,
|
||||
|
||||
expected: date(2024, 4, 16),
|
||||
expected: date(2024, 3, 12),
|
||||
},
|
||||
{
|
||||
name: "April 2024 (before 3rd Tuesday)",
|
||||
year: 2024,
|
||||
month: 4,
|
||||
daysStart: 1,
|
||||
daysStart: 10,
|
||||
daysEnd: 16,
|
||||
|
||||
expected: date(2024, 4, 16),
|
||||
|
|
@ -70,45 +70,45 @@ func TestGetPreferredCalendarEventDate(t *testing.T) {
|
|||
year: 2024,
|
||||
month: 4,
|
||||
daysStart: 17,
|
||||
daysEnd: 30,
|
||||
daysEnd: 23,
|
||||
|
||||
expected: date(2024, 5, 21),
|
||||
expected: date(2024, 4, 23),
|
||||
},
|
||||
{
|
||||
name: "May 2024 (before 3rd Tuesday)",
|
||||
year: 2024,
|
||||
month: 5,
|
||||
daysStart: 1,
|
||||
daysEnd: 21,
|
||||
|
||||
expected: date(2024, 5, 21),
|
||||
},
|
||||
{
|
||||
name: "May 2024 (after 3rd Tuesday)",
|
||||
name: "May 2024 (before last Tuesday)",
|
||||
year: 2024,
|
||||
month: 5,
|
||||
daysStart: 22,
|
||||
daysEnd: 31,
|
||||
daysEnd: 28,
|
||||
|
||||
expected: date(2024, 6, 18),
|
||||
expected: date(2024, 5, 28),
|
||||
},
|
||||
{
|
||||
name: "Dec 2024 (before 3rd Tuesday)",
|
||||
name: "May 2024 (after last Tuesday)",
|
||||
year: 2024,
|
||||
month: 12,
|
||||
daysStart: 1,
|
||||
daysEnd: 17,
|
||||
|
||||
expected: date(2024, 12, 17),
|
||||
},
|
||||
{
|
||||
name: "Dec 2024 (after 3rd Tuesday)",
|
||||
year: 2024,
|
||||
month: 12,
|
||||
daysStart: 18,
|
||||
month: 5,
|
||||
daysStart: 29,
|
||||
daysEnd: 31,
|
||||
|
||||
expected: date(2025, 1, 21),
|
||||
expected: date(2024, 6, 4),
|
||||
},
|
||||
{
|
||||
name: "Dec 2025 (before last Tuesday)",
|
||||
year: 2025,
|
||||
month: 12,
|
||||
daysStart: 24,
|
||||
daysEnd: 30,
|
||||
|
||||
expected: date(2025, 12, 30),
|
||||
},
|
||||
{
|
||||
name: "Dec 2025 (after last Tuesday)",
|
||||
year: 2025,
|
||||
month: 12,
|
||||
daysStart: 31,
|
||||
daysEnd: 31,
|
||||
|
||||
expected: date(2026, 1, 6),
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue