]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/4349'
authorTom Hughes <tom@compton.nu>
Wed, 15 Nov 2023 22:30:41 +0000 (22:30 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 15 Nov 2023 22:30:41 +0000 (22:30 +0000)
17 files changed:
app/assets/stylesheets/common.scss
app/helpers/application_helper.rb
app/helpers/changesets_helper.rb
app/helpers/note_helper.rb
app/views/browse/_common_details.html.erb
app/views/browse/changeset.html.erb
app/views/dashboards/_contact.html.erb
app/views/diary_entries/comments.html.erb
app/views/issues/index.html.erb
app/views/notes/show.html.erb
app/views/traces/_trace.html.erb
app/views/user_blocks/revoke.html.erb
config/locales/en.yml
test/helpers/application_helper_test.rb
test/helpers/changesets_helper_test.rb
test/helpers/note_helper_test.rb
test/helpers/user_blocks_helper_test.rb

index f91f380b2fcc357e93498fed878c1e6f5c6262ca..1f5d0398e97b2b11433355821a69f11e4ee6c215 100644 (file)
@@ -47,6 +47,10 @@ small, aside {
   font-size: 12px;
 }
 
+time[title] {
+  text-decoration: underline dotted;
+}
+
 #container { position: relative; }
 
 .small_icon {
index 2fc0d808d53c87566318ac254b8f523587952726..17c36bdfe043066b81c518c9602546f3013af212 100644 (file)
@@ -26,11 +26,11 @@ module ApplicationHelper
   end
 
   def friendly_date(date)
-    tag.span(time_ago_in_words(date), :title => l(date, :format => :friendly))
+    tag.time(time_ago_in_words(date), :title => l(date, :format => :friendly), :datetime => date.xmlschema)
   end
 
   def friendly_date_ago(date)
-    tag.span(time_ago_in_words(date, :scope => :"datetime.distance_in_words_ago"), :title => l(date, :format => :friendly))
+    tag.time(time_ago_in_words(date, :scope => :"datetime.distance_in_words_ago"), :title => l(date, :format => :friendly), :datetime => date.xmlschema)
   end
 
   def body_class
index 9d46de12009ca89a8e80f71f341a754a4078e82e..3a26c2001c9dc5884c1fd996d8f13bfcb483d977 100644 (file)
@@ -14,16 +14,18 @@ module ChangesetsHelper
       action = :created
       time = time_ago_in_words(changeset.created_at, :scope => :"datetime.distance_in_words_ago")
       title = l(changeset.created_at)
+      datetime = changeset.created_at.xmlschema
     else
       action = :closed
       time = time_ago_in_words(changeset.closed_at, :scope => :"datetime.distance_in_words_ago")
       title = safe_join([t("browse.created"), ": ", l(changeset.created_at), "&#10;".html_safe, t("browse.closed"), ": ", l(changeset.closed_at)])
+      datetime = changeset.closed_at.xmlschema
     end
 
     if params.key?(:display_name)
-      t "browse.#{action}_ago_html", :time_ago => tag.abbr(time, :title => title)
+      t "browse.#{action}_ago_html", :time_ago => tag.time(time, :title => title, :datetime => datetime)
     else
-      t "browse.#{action}_ago_by_html", :time_ago => tag.abbr(time, :title => title),
+      t "browse.#{action}_ago_by_html", :time_ago => tag.time(time, :title => title, :datetime => datetime),
                                         :user => changeset_user_link(changeset)
     end
   end
index 42fd089e47ef1105b09a4e1a0c5e024044bd4ab4..21c8fa51e8c4326cd37182aeda636b4898c15d20 100644 (file)
@@ -4,12 +4,10 @@ module NoteHelper
   def note_event(event, at, by)
     if by.nil?
       t("notes.show.event_#{event}_by_anonymous_html",
-        :time_ago => tag.abbr(friendly_date_ago(at),
-                              :title => l(at)))
+        :time_ago => friendly_date_ago(at))
     else
       t("notes.show.event_#{event}_by_html",
-        :time_ago => tag.abbr(friendly_date_ago(at),
-                              :title => l(at)),
+        :time_ago => friendly_date_ago(at),
         :user => note_author(by))
     end
   end
@@ -23,9 +21,4 @@ module NoteHelper
       link_to h(author.display_name), link_options.merge(:controller => "/users", :action => "show", :display_name => author.display_name)
     end
   end
-
-  def disappear_in(note)
-    date = note.freshly_closed_until
-    tag.span(distance_of_time_in_words(date, Time.now.utc), :title => l(date, :format => :friendly))
-  end
 end
index 9eb6b5bfe55988f76d99e1487012cb9c3b619158..4726799e7342966a5c018d1fe93fbaba4f225825 100644 (file)
@@ -14,8 +14,7 @@
 <ul class="list-unstyled">
   <li>
     <%= t "browse.#{common_details.visible? ? :edited : :deleted}_ago_by_html",
-          :time_ago => tag.abbr(time_ago_in_words(common_details.timestamp, :scope => :"datetime.distance_in_words_ago"),
-                                :title => l(common_details.timestamp)),
+          :time_ago => friendly_date_ago(common_details.timestamp),
           :user => changeset_user_link(common_details.changeset) %>
   </li>
   <li>
index 74596e529c6e1ed5f8926161c71fa227c4e1131a..ec4e0c1c200e6f16889744f5340d3751a254da7c 100644 (file)
@@ -35,8 +35,7 @@
               <li id="c<%= comment.id %>">
                 <small class='text-muted'>
                   <%= t(".comment_by_html",
-                        :time_ago => tag.abbr(friendly_date_ago(comment.created_at),
-                                              :title => l(comment.created_at)),
+                        :time_ago => friendly_date_ago(comment.created_at),
                         :user => link_to(comment.author.display_name, user_path(comment.author))) %>
                   <% if current_user and current_user.moderator? %>
                     — <span class="action-button" data-comment-id="<%= comment.id %>" data-method="POST" data-url="<%= changeset_comment_hide_url(comment.id) %>"><%= t("javascripts.changesets.show.hide_comment") %></span>
@@ -50,8 +49,7 @@
               <li id="c<%= comment.id %>">
                 <small class='text-muted'>
                   <%= t(".hidden_comment_by_html",
-                        :time_ago => tag.abbr(friendly_date_ago(comment.created_at),
-                                              :title => l(comment.created_at)),
+                        :time_ago => friendly_date_ago(comment.created_at),
                         :user => link_to(comment.author.display_name, user_path(comment.author))) %>
                   — <span class="action-button text-muted" data-comment-id="<%= comment.id %>" data-method="POST" data-url="<%= changeset_comment_unhide_url(comment.id) %>"><%= t("javascripts.changesets.show.unhide_comment") %></span>
                  </small>
index 0c012cec90040c9921abb64cb9805ea990c12dae..7e78a6895a59ddc0da7dedb136da0fa3157a8476 100644 (file)
@@ -23,7 +23,7 @@
     <p class="mb-0">
       <% changeset = contact.changesets.first %>
       <% if changeset %>
-        <%= t("users.show.latest edit", :ago => time_ago_in_words(changeset.created_at, :scope => :"datetime.distance_in_words_ago")) %>
+        <%= t(".latest_edit_html", :ago => friendly_date_ago(changeset.created_at)) %>
         <% comment = changeset.tags["comment"].to_s == "" ? t("browse.no_comment") : changeset.tags["comment"] %>
         <q><%= link_to(comment,
                        { :controller => "browse", :action => "changeset", :id => changeset.id },
index f82373af0c5558d7678ec0df78e7f90aa7b959f3..61ceccdc06635cc07ffd2a0f317cc51a2fe2a8e2 100644 (file)
@@ -18,7 +18,9 @@
     <% @comments.each do |comment| -%>
     <tr>
       <td width="25%" class="<%= "text-muted" unless comment.visible? %>"><%= link_to comment.diary_entry.title, diary_entry_path(comment.diary_entry.user, comment.diary_entry) %></td>
-      <td width="25%" class="<%= "text-muted" unless comment.visible? %>"><span title="<%= l comment.created_at, :format => :friendly %>"><%= time_ago_in_words(comment.created_at, :scope => :"datetime.distance_in_words_ago") %></span></td>
+      <td width="25%" class="<%= "text-muted" unless comment.visible? %>">
+        <%= friendly_date_ago(comment.created_at) %>
+      </td>
       <td width="50%" class="richtext text-break<%= " text-muted" unless comment.visible? %>"><%= comment.body.to_html %></td>
     </tr>
     <% end -%>
index da00b5fea27a8455fdd1b0951feb26070bff511d..12ddf2b32a162f6e77c909eb4458dbd9a771571f 100644 (file)
           <td><%= link_to reportable_title(issue.reportable), reportable_url(issue.reportable) %></td>
           <td><%= link_to issue.reported_user.display_name, user_path(issue.reported_user) if issue.reported_user %></td>
           <td>
-            <% time_ago_tag = tag.abbr(time_ago_in_words(issue.updated_at, :scope => :"datetime.distance_in_words_ago"),
-                                       :title => l(issue.updated_at)) %>
             <% if issue.user_updated %>
               <%= t ".last_updated_time_ago_user_html", :user => link_to(issue.user_updated.display_name, user_path(issue.user_updated)),
-                                                        :time_ago => time_ago_tag %>
+                                                        :time_ago => friendly_date_ago(issue.updated_at) %>
             <% else %>
-              <%= time_ago_tag %>
+              <%= friendly_date_ago(issue.updated_at) %>
             <% end %>
           </td>
         </tr>
index 3bb97b484289396ffeec14167cff936401c52ad0..fda8946b6b18378ce483c53c0bf267963d5f3df2 100644 (file)
@@ -95,7 +95,7 @@
 
   <% if @note.freshly_closed? %>
     <small class="text-muted">
-      <%= t ".disappear_date_html", :disappear_in => disappear_in(@note) %>
+      <%= t ".disappear_date_html", :disappear_in => friendly_date(@note.freshly_closed_until) %>
     </small>
   <% end %>
 </div>
index 832187b79306acda89b58896a595daf054b01ca7..9ee58cf22122beff7633c1f02bd71c73f5c67e73 100644 (file)
@@ -29,9 +29,7 @@
       </li>
     </ul>
     <p class="text-muted mb-0">
-      <span title="<%= trace.timestamp %>">
-        <%= time_ago_in_words(trace.timestamp, :scope => :"datetime.distance_in_words_ago") %>
-      </span>
+      <%= friendly_date_ago(trace.timestamp) %>
       <%= t ".by" %> <%= link_to trace.user.display_name, user_path(trace.user) %>
       <% if !trace.tags.empty? %>
         <%= t ".in" %>
index 9a86177fc7dedcb030f3bb94f29f7186600a185e..eb1cc4cbebb4e9414043f828b753f03577ba25f8 100644 (file)
@@ -12,7 +12,7 @@
 
 <% if @user_block.ends_at > Time.now %>
   <p>
-    <%= t(".time_future", :time => distance_of_time_in_words_to_now(@user_block.ends_at)) %>
+    <%= t(".time_future_html", :time => friendly_date(@user_block.ends_at)) %>
   </p>
 
   <%= bootstrap_form_for :revoke, :url => { :action => "revoke" } do |f| %>
@@ -28,6 +28,6 @@
 
 <% else %>
   <p>
-    <%= t(".past", :time => time_ago_in_words(@user_block.ends_at, :scope => :"datetime.distance_in_words_ago")) %>
+    <%= t(".past_html", :time => friendly_date_ago(@user_block.ends_at)) %>
   </p>
 <% end %>
index ce84600d2870cf6a681d544ca5963e053faee832..1a41dcce814de5f00882f7393c780f5b616f12c6 100644 (file)
@@ -465,6 +465,7 @@ en:
     contact:
       km away: "%{count}km away"
       m away: "%{count}m away"
+      latest_edit_html: "Latest edit (%{ago}):"
     popup:
       your location: "Your location"
       nearby mapper: "Nearby mapper"
@@ -2731,7 +2732,6 @@ en:
       ct status: "Contributor terms:"
       ct undecided: Undecided
       ct declined: Declined
-      latest edit: "Latest edit (%{ago}):"
       email address: "Email address:"
       created from: "Created from:"
       status: "Status:"
@@ -2847,8 +2847,8 @@ en:
     revoke:
       title: "Revoking block on %{block_on}"
       heading_html: "Revoking block on %{block_on} by %{block_by}"
-      time_future: "This block will end in %{time}."
-      past: "This block ended %{time} and cannot be revoked now."
+      time_future_html: "This block will end in %{time}."
+      past_html: "This block ended %{time} and cannot be revoked now."
       confirm: "Are you sure you wish to revoke this block?"
       revoke: "Revoke!"
       flash: "This block has been revoked."
index 7cd6bce89417fb40ae497c1debdc032817d2ab90..34120e2078781ad732e69e5664a2e5324093157a 100644 (file)
@@ -57,19 +57,36 @@ class ApplicationHelperTest < ActionView::TestCase
 
   def test_friendly_date
     date = friendly_date(Time.utc(2014, 3, 5, 18, 58, 23))
-    assert_match %r{^<span title=" *5 March 2014 at 18:58">.*</span>$}, date
+    assert_match %r{^<time title=" *5 March 2014 at 18:58" datetime="2014-03-05T18:58:23Z">.*</time>$}, date
 
     date = friendly_date(Time.now.utc - 1.hour)
-    assert_match %r{^<span title=".*">about 1 hour</span>$}, date
+    assert_match %r{^<time title=".*">about 1 hour</time>$}, date
 
     date = friendly_date(Time.now.utc - 2.days)
-    assert_match %r{^<span title=".*">2 days</span>$}, date
+    assert_match %r{^<time title=".*">2 days</time>$}, date
 
     date = friendly_date(Time.now.utc - 3.weeks)
-    assert_match %r{^<span title=".*">21 days</span>$}, date
+    assert_match %r{^<time title=".*">21 days</time>$}, date
 
     date = friendly_date(Time.now.utc - 4.months)
-    assert_match %r{^<span title=".*">4 months</span>$}, date
+    assert_match %r{^<time title=".*">4 months</time>$}, date
+  end
+
+  def test_friendly_date_ago
+    date = friendly_date_ago(Time.utc(2014, 3, 5, 18, 58, 23))
+    assert_match %r{^<time title=" *5 March 2014 at 18:58" datetime="2014-03-05T18:58:23Z">.*</time>$}, date
+
+    date = friendly_date_ago(Time.now.utc - 1.hour)
+    assert_match %r{^<time title=".*">about 1 hour ago</time>$}, date
+
+    date = friendly_date_ago(Time.now.utc - 2.days)
+    assert_match %r{^<time title=".*">2 days ago</time>$}, date
+
+    date = friendly_date_ago(Time.now.utc - 3.weeks)
+    assert_match %r{^<time title=".*">21 days ago</time>$}, date
+
+    date = friendly_date_ago(Time.now.utc - 4.months)
+    assert_match %r{^<time title=".*">4 months ago</time>$}, date
   end
 
   def test_body_class; end
index f6cfb3c0679a467490926adfa21fcfbc83f0aee1..067c2b071e41711004ba62551a65debf73e12fc0 100644 (file)
@@ -17,11 +17,11 @@ class ChangesetsHelperTest < ActionView::TestCase
     # We need to explicitly reset the closed_at to some point in the future, and avoid the before_save callback
     changeset.update_column(:closed_at, Time.now.utc + 1.day) # rubocop:disable Rails/SkipsModelValidations
 
-    assert_match %r{^Created <abbr title="Mon, 01 Jan 2007 00:00:00 \+0000">.*</abbr> by anonymous$}, changeset_details(changeset)
+    assert_match %r{^Created <time title="Mon, 01 Jan 2007 00:00:00 \+0000" datetime="2007-01-01T00:00:00Z">.*</time> by anonymous$}, changeset_details(changeset)
 
     changeset = create(:changeset, :created_at => Time.utc(2007, 1, 1, 0, 0, 0), :closed_at => Time.utc(2007, 1, 2, 0, 0, 0))
     user_link = %(<a href="/user/#{ERB::Util.u(changeset.user.display_name)}">#{changeset.user.display_name}</a>)
 
-    assert_match %r{^Closed <abbr title="Created: Mon, 01 Jan 2007 00:00:00 \+0000&#10;Closed: Tue, 02 Jan 2007 00:00:00 \+0000">.*</abbr> by #{user_link}$}, changeset_details(changeset)
+    assert_match %r{^Closed <time title="Created: Mon, 01 Jan 2007 00:00:00 \+0000&#10;Closed: Tue, 02 Jan 2007 00:00:00 \+0000" datetime="2007-01-02T00:00:00Z">.*</time> by #{user_link}$}, changeset_details(changeset)
   end
 end
index 37518fb3d22b01765e5afade169ad93eaea476fa..bee1cdc2c5485291cf52cdfb5d09e3b0520ee6cd 100644 (file)
@@ -8,8 +8,8 @@ class NoteHelperTest < ActionView::TestCase
     date = Time.utc(2014, 3, 5, 21, 37, 45)
     user = create(:user)
 
-    assert_match %r{^Created by anonymous <abbr title="Wed, 05 Mar 2014 21:37:45 \+0000"><span title=" 5 March 2014 at 21:37">.* ago</span></abbr>$}, note_event("opened", date, nil)
-    assert_match %r{^Resolved by <a href="/user/#{ERB::Util.u(user.display_name)}">#{user.display_name}</a> <abbr title="Wed, 05 Mar 2014 21:37:45 \+0000"><span title=" 5 March 2014 at 21:37">.* ago</span></abbr>$}, note_event("closed", date, user)
+    assert_match %r{^Created by anonymous <time title=" 5 March 2014 at 21:37" datetime="2014-03-05T21:37:45Z">.* ago</time>$}, note_event("opened", date, nil)
+    assert_match %r{^Resolved by <a href="/user/#{ERB::Util.u(user.display_name)}">#{user.display_name}</a> <time title=" 5 March 2014 at 21:37" datetime="2014-03-05T21:37:45Z">.* ago</time>$}, note_event("closed", date, user)
   end
 
   def test_note_author
@@ -21,13 +21,4 @@ class NoteHelperTest < ActionView::TestCase
     assert_equal "<a href=\"/user/#{ERB::Util.u(user.display_name)}\">#{user.display_name}</a>", note_author(user)
     assert_equal "<a href=\"http://test.host/user/#{ERB::Util.u(user.display_name)}\">#{user.display_name}</a>", note_author(user, :only_path => false)
   end
-
-  def test_disappear_in
-    note_closed_date = Time.utc(2022, 1, 1, 12, 0, 0)
-    note = create(:note, :closed_at => note_closed_date)
-
-    travel_to note_closed_date + 1.day do
-      assert_match %r{^<span title=" 8 January 2022 at 12:00">6 days</span>$}, disappear_in(note)
-    end
-  end
 end
index 0c2ab42b5810ad13683a5e317ea43fd81964ecdf..db4fd87a49a8d9672bd0785437f64f0cc5b1ca28 100644 (file)
@@ -8,10 +8,10 @@ class UserBlocksHelperTest < ActionView::TestCase
     assert_equal "Active until the user logs in.", block_status(block)
 
     block = create(:user_block, :needs_view, :ends_at => Time.now.utc + 1.hour)
-    assert_match %r{^Ends in <span title=".*">about 1 hour</span> and after the user has logged in\.$}, block_status(block)
+    assert_match %r{^Ends in <time title=".*" datetime=".*">about 1 hour</time> and after the user has logged in\.$}, block_status(block)
 
     block = create(:user_block, :ends_at => Time.now.utc + 1.hour)
-    assert_match %r{^Ends in <span title=".*">about 1 hour</span>\.$}, block_status(block)
+    assert_match %r{^Ends in <time title=".* datetime=".*">about 1 hour</time>\.$}, block_status(block)
   end
 
   def test_block_duration_in_words