Skip to content

Commit

Permalink
Fixed schedule editor to convert/save start time correctly
Browse files Browse the repository at this point in the history
Need to only pass date to create_time_in_utc method call, prior to fix code was passing in datetime as "Mon Mar 12 2018 20:00:00 GMT-0400 (EDT) 1:5:00", having timezone and time in the start_date parameter was messing the conversion up. Changed miq_datepicker.js to convert string into moment first and then convert it to utc, that solves the issue where Date being sent upto server was -1 day of selected day.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1558627
  • Loading branch information
h-kataria committed Mar 22, 2018
1 parent 265ba60 commit 413e81d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ManageIQ.angular.app.controller('scheduleFormController', ['$http', '$scope', 's
$scope.scheduleModel.name = data.schedule_name;
$scope.scheduleModel.timer_typ = data.schedule_timer_type;
$scope.scheduleModel.timer_value = data.schedule_timer_value;
$scope.scheduleModel.start_date = moment.utc(data.schedule_start_date, 'MM/DD/YYYY').toDate();
$scope.scheduleModel.start_date = moment(data.schedule_start_date, 'MM/DD/YYYY').utc().toDate();
$scope.scheduleModel.start_hour = data.schedule_start_hour.toString();
$scope.scheduleModel.start_min = data.schedule_start_min.toString();
$scope.scheduleModel.time_zone = data.schedule_time_zone;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/directives/miq_datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ManageIQ.angular.app.directive('miqDatepicker', function() {

ctrl.$parsers.push(function(value) {
if (value) {
return moment.utc(value, 'MM/DD/YYYY').toDate();
return moment(value, 'MM/DD/YYYY').utc().toDate();
}
});

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ops_controller/settings/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def schedule_set_timer_record_vars(schedule)
end

def schedule_set_start_time_record_vars(schedule)
run_at = create_time_in_utc("#{params[:start_date]} #{params[:start_hour]}:#{params[:start_min]}:00",
run_at = create_time_in_utc("#{Date.parse(params[:start_date])} #{params[:start_hour]}:#{params[:start_min]}:00",
params[:time_zone])
schedule.run_at[:start_time] = "#{run_at} Z"
end
Expand Down
11 changes: 11 additions & 0 deletions spec/controllers/ops_controller/settings/schedules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@
expect(schedule.filter.exp[key]["field"]).to eq("Vm-name")
expect(schedule.sched_action).to eq(:method=>"check_compliance")
end

it "sets start time correctly" do
params[:start_date] = "Mon Mar 12 2018 20:00:00 GMT-0400 (EDT)"
params[:start_hour] = "1"
params[:start_min] = "5"
params[:time_zone] = "UTC"

allow(controller).to receive(:params).and_return(params)
controller.send(:schedule_set_start_time_record_vars, schedule)
expect(schedule.run_at[:start_time]).to eq("2018-03-12 01:05:00 UTC")
end
end

context "#build_attrs_from_params" do
Expand Down

0 comments on commit 413e81d

Please sign in to comment.