Improve display of maintenance windows

Change-Id: Ia0ac56acd9890e8ae82cc1d56979894e30180d22
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/267537
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Jacob Burroughs 2021-06-22 10:31:23 -05:00
parent 10b19ee2b5
commit 8dea6e585b
7 changed files with 38 additions and 9 deletions

View File

@ -140,7 +140,7 @@
<% if @account.shard.database_server.maintenance_window_start_hour %>
<tr>
<td></td>
<td> <%= render partial: 'shared/maintenance_window', locals: { database_server: @account.shard.database_server } %> </td>
<td> <%= render partial: 'shared/maintenance_window', locals: { database_server: @account.shard.database_server, local_zone: @account.default_time_zone } %> </td>
</tr>
<% end %>
<%= f.fields_for :settings do |settings| %>

View File

@ -160,7 +160,7 @@
<% if @user.shard.database_server.maintenance_window_start_hour %>
<tr>
<td></td>
<td> <%= render partial: 'shared/maintenance_window', locals: { database_server: @user.shard.database_server } %> </td>
<td> <%= render partial: 'shared/maintenance_window', locals: { database_server: @user.shard.database_server, local_zone: ::Time.zone } %> </td>
</tr>
<% end %>
<% if @domain_root_account == Account.default %>

View File

@ -1,12 +1,12 @@
<% next_window = database_server.next_maintenance_window %>
<%= t("Maintenance windows: %{days} %{weekday} of the month from %{time_range} (%{utc_time_range} UTC )",
{ days: database_server.maintenance_window_weeks_of_month.map(&:ordinalize).to_sentence,
weekday: I18n.t('date.day_names')[next_window[0].wday],
time_range: time_string(next_window[0], next_window[1]),
utc_time_range: time_string(next_window[0], next_window[1], ActiveSupport::TimeZone['UTC']) }) %>
weekday: I18n.t('date.day_names')[next_window[0].in_time_zone(local_zone).wday],
time_range: time_string(next_window[0], next_window[1], local_zone),
utc_time_range: datetime_string(next_window[0], :weekday_only, next_window[1], false, ActiveSupport::TimeZone['UTC']) }) %>
<br/>
<%= t("Next window: %{window}", {
window: datetime_string(next_window[0], :verbose, next_window[1], with_weekday: true) }) %>
window: datetime_string(next_window[0], :verbose, next_window[1], false, local_zone, with_weekday: true) }) %>
<p>
<%= Setting.get('global_maintenance_notice', '').html_safe %>
<p/>

View File

@ -151,9 +151,9 @@ Rails.application.config.after_initialize do
# This array is effectively 1 indexed
relevant_weeks = maintenance_window_weeks_of_month.map { |i| WeekOfMonth::Constant::WEEKS_IN_SEQUENCE[i] }
maintenance_days = relevant_weeks.map do |ordinal|
Time.zone.local_to_utc(start_day.send("#{ordinal}_#{maintenance_window_weekday}_in_month".downcase))
start_day.send("#{ordinal}_#{maintenance_window_weekday}_in_month".downcase)
end + relevant_weeks.map do |ordinal|
Time.zone.local_to_utc((start_day + 1.month).send("#{ordinal}_#{maintenance_window_weekday}_in_month".downcase))
(start_day + 1.month).send("#{ordinal}_#{maintenance_window_weekday}_in_month".downcase)
end
next_day = maintenance_days.find { |d| d.future? }

View File

@ -31,6 +31,8 @@ module Utils
def as_string(style=:normal)
if style == :full
return i18n_date(:full)
elsif style == :weekday
return i18n_date(:weekday)
elsif style != :long
if style != :no_words && special_value_type != :none
string = special_string(special_value_type)

View File

@ -104,7 +104,14 @@ module Utils
end
def date_style
datetime_type == :verbose ? :long : :no_words
case datetime_type
when :verbose
:long
when :weekday_only
:weekday
else
:no_words
end
end
def datetime_type

View File

@ -83,6 +83,26 @@ describe Switchman::Shard do
expect(window[0].wday).to eq(Date::DAYNAMES.index('Tuesday'))
end
context 'with a positive timezone' do
before do
@old_zone = ::Time.zone
::Time.zone = ActiveSupport::TimeZone['Melbourne']
end
after do
::Time.zone = @old_zone
end
it 'Returns a window on the correct day' do
allow(Setting).to receive(:get).with("maintenance_window_start_hour", anything).and_return('0')
allow(Setting).to receive(:get).with("maintenance_window_weekday", anything).and_return('Tuesday')
window = DatabaseServer.all.first.next_maintenance_window
expect(window[0].wday).to eq(Date::DAYNAMES.index('Tuesday'))
end
end
it 'Returns a window on the correct day of the month' do
allow(Setting).to receive(:get).with("maintenance_window_start_hour", anything).and_return('0')