The exact issuance and expiry times in the device rows' hover titles were rendered in UTC, which reads as wrong to anyone not living there. - Mark the dates with a <time> element carrying the absolute (UTC) timestamp, rather than a custom data attribute whose name claimed to hold local time - Rewrite those titles in the browser's own zone, keeping the server's UTC rendering as the fallback for when JavaScript is unavailable - Only convert values that carry an explicit offset, so a date-only <time> is not read as UTC midnight and shifted onto the previous day - Give the revoke button a little more room from the device name and dates Part of #254
34 lines
1021 B
Ruby
34 lines
1021 B
Ruby
# frozen_string_literal: true
|
|
|
|
class RsAuthDetailsModalComponent < ViewComponent::Base
|
|
include RsAuthsHelper
|
|
|
|
def initialize(authorizations:)
|
|
@authorizations = authorizations
|
|
@auth = authorizations.first
|
|
@web_app = @auth.web_app
|
|
end
|
|
|
|
# "Expires" / "Expired on", or nothing when there is no expiry to describe.
|
|
def expiry_prefix(auth)
|
|
return nil if auth.expire_at.blank?
|
|
|
|
auth.expired? ? "Expired on" : "Expires"
|
|
end
|
|
|
|
# Fallbacks for the hover titles, used when JavaScript is unavailable.
|
|
# app/javascript/local_time.js replaces them with the reader's own zone.
|
|
def connected_at_title(auth)
|
|
auth.created_at.strftime("%-d %b %Y, %H:%M")
|
|
end
|
|
|
|
def expires_at_title(auth)
|
|
auth.expire_at.strftime("%-d %b %Y, %H:%M")
|
|
end
|
|
|
|
# A <time> element carrying the absolute (UTC) timestamp, so the reader's own
|
|
# local time can be shown alongside the date.
|
|
def timestamp_tag(time, title:)
|
|
tag.time time.strftime("%-d %b %Y"), datetime: time.utc.iso8601, title: title
|
|
end
|
|
end |