Skip to content

Commit 7ac3835

Browse files
authored
Fix datetime shift in job filter for non-UTC timezones (#278)
* use datetime-local format in tests for job filters * test job filters in different time zone * fix date and time parsing in job filters * format
1 parent 1648c00 commit 7ac3835

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

app/controllers/concerns/mission_control/jobs/job_filters.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ def finished_at_range_params
3636
end
3737

3838
def parse_with_time_zone(date)
39-
DateTime.parse(date).in_time_zone if date.present?
39+
Time.zone.parse(date) if date.present?
4040
end
4141
end

test/controllers/jobs_controller_test.rb

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,28 @@ class MissionControl::Jobs::JobsControllerTest < ActionDispatch::IntegrationTest
4343
end
4444

4545
test "get finished jobs filtered by finished_at date" do
46-
job = DummyJob.perform_later(42)
47-
perform_enqueued_jobs_async
48-
49-
get mission_control_jobs.application_jobs_url(@application, :finished)
50-
assert_response :ok
51-
assert_select "tr.job", 1
52-
53-
get mission_control_jobs.application_jobs_url(@application, :finished, filter: { finished_at_start: 1.hour.from_now.to_s })
54-
assert_response :ok
55-
assert_select "tr.job", 0
56-
57-
get mission_control_jobs.application_jobs_url(@application, :finished, filter: { finished_at_start: 1.hour.ago.to_s, finished_at_end: 1.hour.from_now })
58-
assert_response :ok
59-
assert_select "tr.job", 1
60-
61-
get mission_control_jobs.application_jobs_url(@application, :finished, filter: { finished_at_end: 1.hour.from_now })
62-
assert_response :ok
63-
assert_select "tr.job", 1
46+
[ "UTC", "International Date Line West" ].each do |timezone|
47+
Time.use_zone(timezone) do
48+
job = DummyJob.perform_later(42)
49+
perform_enqueued_jobs_async
50+
51+
get mission_control_jobs.application_jobs_url(@application, :finished)
52+
assert_response :ok
53+
assert_select "tr.job", 1
54+
55+
get mission_control_jobs.application_jobs_url(@application, :finished, filter: { finished_at_start: 1.hour.from_now.strftime("%Y-%m-%dT%H:%M") })
56+
assert_response :ok
57+
assert_select "tr.job", 0
58+
59+
get mission_control_jobs.application_jobs_url(@application, :finished, filter: { finished_at_start: 1.hour.ago.strftime("%Y-%m-%dT%H:%M"), finished_at_end: 1.hour.from_now.strftime("%Y-%m-%dT%H:%M") })
60+
assert_response :ok
61+
assert_select "tr.job", 1
62+
63+
get mission_control_jobs.application_jobs_url(@application, :finished, filter: { finished_at_end: 1.hour.from_now.strftime("%Y-%m-%dT%H:%M") })
64+
assert_response :ok
65+
assert_select "tr.job", 1
66+
end
67+
end
6468
end
6569

6670
test "redirect to queue when job doesn't exist" do

0 commit comments

Comments
 (0)