Skip to content

Commit fca856d

Browse files
authored
Merge pull request #217 from rails/back-to-relative-times
Go back to relative times and a better locale management
2 parents 0c22a02 + b449afe commit fca856d

File tree

18 files changed

+109
-103
lines changed

18 files changed

+109
-103
lines changed

app/controllers/mission_control/jobs/application_controller.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@ class MissionControl::Jobs::ApplicationController < MissionControl::Jobs.base_co
1313
include MissionControl::Jobs::ApplicationScoped, MissionControl::Jobs::NotFoundRedirections
1414
include MissionControl::Jobs::AdapterFeatures
1515

16+
around_action :set_current_locale
17+
1618
private
1719
def default_url_options
1820
{ server_id: MissionControl::Jobs::Current.server }
1921
end
22+
23+
def set_current_locale(&block)
24+
@previous_config = I18n.config
25+
I18n.config = MissionControl::Jobs::I18nConfig.new
26+
I18n.with_locale(:en, &block)
27+
ensure
28+
I18n.config = @previous_config
29+
@previous_config = nil
30+
end
2031
end
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
module MissionControl::Jobs::DatesHelper
2-
def formatted_time(time)
3-
time.in_time_zone.strftime("%Y-%m-%d %H:%M:%S.%3N %Z")
2+
def time_distance_in_words_with_title(time)
3+
tag.span time_ago_in_words_with_default_options(time), title: "Since #{time.to_fs(:long)}"
4+
end
5+
6+
def bidirectional_time_distance_in_words_with_title(time)
7+
time_distance = if time.past?
8+
"#{time_ago_in_words_with_default_options(time)} ago"
9+
else
10+
"in #{time_ago_in_words_with_default_options(time)}"
11+
end
12+
13+
tag.span time_distance, title: time.to_fs(:long)
14+
end
15+
16+
def time_ago_in_words_with_default_options(time)
17+
time_ago_in_words(time, include_seconds: true, locale: :en)
418
end
519
end

app/helpers/mission_control/jobs/jobs_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def attribute_names_for_job_status(status)
2929
when "blocked" then [ "Queue", "Blocked by", "" ]
3030
when "finished" then [ "Queue", "Finished" ]
3131
when "scheduled" then [ "Queue", "Scheduled", "" ]
32-
when "in_progress" then [ "Queue", "Run by", "Running since" ]
32+
when "in_progress" then [ "Queue", "Run by", "Running for" ]
3333
else []
3434
end
3535
end

app/views/mission_control/jobs/jobs/_general_information.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
<tr>
2424
<th>Enqueued</th>
2525
<td>
26-
<%= formatted_time(job.enqueued_at.to_datetime) %>
26+
<%= time_distance_in_words_with_title(job.enqueued_at.to_datetime) %> ago
2727
</td>
2828
</tr>
2929
<% if job.scheduled? %>
3030
<tr>
3131
<th>Scheduled</th>
3232
<td>
33-
<%= formatted_time(job.scheduled_at) %>
33+
<%= bidirectional_time_distance_in_words_with_title(job.scheduled_at) %>
3434
<% if job_delayed?(job) %>
3535
<div class="is-danger tag ml-4">delayed</div>
3636
<% end %>
@@ -41,15 +41,15 @@
4141
<tr>
4242
<th>Failed</th>
4343
<td>
44-
<%= formatted_time(job.failed_at) %>
44+
<%= time_distance_in_words_with_title(job.failed_at) %> ago
4545
</td>
4646
</tr>
4747
<% end %>
4848
<% if job.finished_at.present? %>
4949
<tr>
5050
<th>Finished at</th>
5151
<td>
52-
<%= formatted_time(job.finished_at) %>
52+
<%= time_distance_in_words_with_title(job.finished_at) %> ago
5353
</td>
5454
</tr>
5555
<% end %>

app/views/mission_control/jobs/jobs/_job.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="is-family-monospace"><%= job_arguments(job) %></div>
77
<% end %>
88

9-
<div class="has-text-grey is-size-7">Enqueued <%= formatted_time(job.enqueued_at.to_datetime) %></div>
9+
<div class="has-text-grey is-size-7">Enqueued <%= time_distance_in_words_with_title(job.enqueued_at.to_datetime) %> ago</div>
1010
</td>
1111

1212
<%= render "mission_control/jobs/jobs/#{jobs_status}/job", job: job %>

app/views/mission_control/jobs/jobs/blocked/_job.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<td><%= link_to job.queue_name, application_queue_path(@application, job.queue) %></td>
22
<td><div class="is-family-monospace is-size-7"><%= job.blocked_by %></div>
3-
<div class="has-text-grey is-size-7">Until <%= formatted_time(job.blocked_until) %></div>
3+
<div class="has-text-grey is-size-7">Expires <%= bidirectional_time_distance_in_words_with_title(job.blocked_until) %></div>
44
</td>
55
<td class="pr-0">
66
<%= render "mission_control/jobs/jobs/blocked/actions", job: job %>

app/views/mission_control/jobs/jobs/failed/_job.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<td>
22
<%= link_to failed_job_error(job), application_job_path(@application, job.job_id, anchor: "error") %>
3-
<div class="has-text-grey"><%= formatted_time(job.failed_at) %></div>
3+
<div class="has-text-grey"><%= time_distance_in_words_with_title(job.failed_at) %> ago</div>
44
</td>
55
<td class="pr-0">
66
<%= render "mission_control/jobs/jobs/failed/actions", job: job %>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<td><%= link_to job.queue_name, application_queue_path(@application, job.queue) %></td>
2-
<td><div class="has-text-grey"><%= formatted_time(job.finished_at) %></div></td>
2+
<td><div class="has-text-grey"><%= time_distance_in_words_with_title(job.finished_at) %> ago</div></td>

app/views/mission_control/jobs/jobs/in_progress/_job.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
77
<% end %>
88
</td>
9-
<td><div class="has-text-grey"><%= job.started_at ? formatted_time(job.started_at) : "(Finished)" %></div></td>
9+
<td><div class="has-text-grey"><%= job.started_at ? time_distance_in_words_with_title(job.started_at) : "(Finished)" %></div></td>

app/views/mission_control/jobs/jobs/scheduled/_job.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<td><%= link_to job.queue_name, application_queue_path(@application, job.queue) %></td>
22
<td>
3-
<%= formatted_time(job.scheduled_at) %>
3+
<%= bidirectional_time_distance_in_words_with_title(job.scheduled_at) %>
44
<% if job_delayed?(job) %>
55
<div class="is-danger tag ml-4">delayed</div>
66
<% end %>

0 commit comments

Comments
 (0)