Created
April 12, 2016 01:15
-
-
Save stefansundin/ed2ffc6f3ba2e833bc161864f375d2d8 to your computer and use it in GitHub Desktop.
Convert AWS maintenance window between timezones.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def offset_maintenance_window(w, offset=-7) | |
days = %w[mon tue wed thu fri sat sun] | |
if /(?<day_start>[a-z]{3}):(?<hour_start>\d\d):(?<minute_start>\d\d)-(?<day_end>[a-z]{3}):(?<hour_end>\d\d):(?<minute_end>\d\d)/ =~ w | |
day_start = days.find_index(day_start) | |
day_end = days.find_index(day_end) | |
hour_start = hour_start.to_i + offset | |
minute_start = minute_start.to_i | |
hour_end = hour_end.to_i + offset | |
minute_end = minute_end.to_i | |
if hour_start < 0 | |
hour_start += 24 | |
day_start -= 1 | |
day_start = days.length-1 if day_start < 0 | |
elsif hour_start > 23 | |
hour_start -= 24 | |
day_start += 1 | |
day_start = 0 if day_start >= days.length | |
end | |
if hour_end < 0 | |
hour_end += 24 | |
day_end -= 1 | |
day_end = days.length-1 if day_end < 0 | |
elsif hour_end > 23 | |
hour_end -= 24 | |
day_end += 1 | |
day_end = 0 if day_end >= days.length | |
end | |
"%s:%02d:%02d-%s:%02d:%02d" % [days[day_start], hour_start, minute_start, days[day_end], hour_end, minute_end] | |
else | |
"could not parse maintenance window" | |
end | |
end | |
w = "wed:03:08-wed:03:38" | |
puts "#{w} => #{offset_maintenance_window(w, -7)}" | |
# wed:03:08-wed:03:38 => tue:20:08-tue:20:38 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment