Makes user-facing dates local when possible

Also ensures it makes available the hydra timezone in the title of the
dates.
This commit is contained in:
Samuel Dionne-Riel 2019-01-21 19:58:53 -05:00
parent 2430b12ec9
commit a16d0c7d6b
3 changed files with 62 additions and 3 deletions

View file

@ -7,13 +7,27 @@ USE Math;
USE mibs=format("%.2f"); USE mibs=format("%.2f");
# Formatted date time, in hydra-local timezone.
BLOCK renderDateTime; # Use only where an HTML element cannot be used.
BLOCK dateTimeText;
date.format(timestamp, '%Y-%m-%d %H:%M:%S'); date.format(timestamp, '%Y-%m-%d %H:%M:%S');
END; END;
# HTML-rendered date. Formatted in hydra-local timezone.
# It is enhanced with JavaScript to show user-local and UTC time zones.
BLOCK renderDateTime %]
<time [% HTML.attributes(
"data-timestamp" => timestamp,
title => date.format(timestamp, '%Y-%m-%d %H:%M:%S (%Z)'),
datetime => date.format(timestamp, "%Y-%m-%dT%H:%M:%SZ", gmt => 1),
) %] class="date is-absolute">
[% INCLUDE dateTimeText %]
</time>
[% END;
BLOCK renderRelativeDate; # Relative date, as text.
# Use only where an HTML element cannot be used.
BLOCK relativeDateText;
ago = date.now - timestamp; ago = date.now - timestamp;
IF ago >= 0 && ago < 60; THEN; IF ago >= 0 && ago < 60; THEN;
ago _ 's ago'; ago _ 's ago';
@ -28,6 +42,17 @@ BLOCK renderRelativeDate;
END; END;
END; END;
# HTML-rendered relative date.
# It is enhanced with JavaScript to show user-local and UTC time zones.
BLOCK renderRelativeDate %]
<time [% HTML.attributes(
"data-timestamp" => timestamp,
title => date.format(timestamp, '%Y-%m-%d %H:%M:%S (%Z)'),
datetime => date.format(timestamp, "%Y-%m-%dT%H:%M:%SZ", gmt => 1),
) %] class="date is-relative">
[% INCLUDE relativeDateText %]
</time>
[% END;
BLOCK renderProjectName %] BLOCK renderProjectName %]
<a [% IF inRow %]class="row-link"[% END %] href="[% c.uri_for('/project' project) %]"><tt>[% project %]</tt></a> <a [% IF inRow %]class="row-link"[% END %] href="[% c.uri_for('/project' project) %]"><tt>[% project %]</tt></a>

View file

@ -142,3 +142,8 @@ td.step-status span.warn {
color: #aaaa00; color: #aaaa00;
font-weight: bold; font-weight: bold;
} }
.date {
cursor: help;
border-bottom: 1px dotted #999;
}

View file

@ -97,6 +97,35 @@ $(document).ready(function() {
} }
}); });
}); });
/* Makes dates more user friendly. */
// Friendly date format
var DATE_FORMAT = "YYYY-MM-DD HH:mm:ss";
// Local timezone offset to display.
var tz = moment().format("Z");
$("time.date").each(function(i, el) {
var el = $(el);
var localTime = moment(el.data("timestamp"), "%X");
var hydraTime = el.attr("title");
if (el.hasClass("is-absolute")) {
el.attr( "title", [
"Adjusted to local time (" + tz + ")",
"Other timezones:",
" UTC: " + localTime.clone().utc().format(DATE_FORMAT),
" As Hydra reported: " + hydraTime,
].join("\n"));
el.text(localTime.format(DATE_FORMAT));
el.addClass("is-local");
}
else if (el.hasClass("is-relative")) {
el.attr( "title", [
"Local (" + tz + "): " + localTime.format(DATE_FORMAT),
"UTC: " + localTime.clone().utc().format(DATE_FORMAT),
"As Hydra reported: " + hydraTime,
].join("\n"));
el.addClass("is-local");
}
});
}); });
var tabsLoaded = {}; var tabsLoaded = {};