Skip to content

Commit

Permalink
fix(l10n): localize report start and end datetimes
Browse files Browse the repository at this point in the history
The "during" start and end datetimes of "Download Report" (/stats/report)
were using server-rendered times, i.e.: strftime("%Y-%m-%d %H:%M:%S").
When server and client time zones differed, the times of the report
would not match the client time zone.
These datetimes are now localized similarly to the rest of the report.
  • Loading branch information
obradovichv committed Aug 16, 2021
1 parent 1a41541 commit c1d7c3c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion locust/templates/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h1>Locust Test Report</h1>
{% if show_download_link %}
<p class="download"><a href="?download=1">Download the Report</a></p>
{% endif %}
<p>During: <span>{{ start_time }} - {{ end_time }}</span></p>
<p>During: <span class="l10n datetime">{{ start_time }}</span> - <span class="l10n datetime">{{ end_time }}</span></p>
<p>Target Host: <span>{{ host }}</span></p>
</div>

Expand Down Expand Up @@ -219,6 +219,20 @@ <h2>Charts</h2>
]
});
}

$(".l10n.datetime").html((index, currentContent) => {
if (!currentContent || !currentContent.includes(" ") || !currentContent.includes(":")) {
return currentContent;
}

let [date, time] = currentContent.split(" ");
let utcDateTime = new Date();
let [year, month, day] = date.split("-")
utcDateTime.setUTCFullYear(year, parseInt(month) - 1, day);
utcDateTime.setUTCHours(...(time.split(":")));

return utcDateTime.toLocaleString();
});
</script>
</body>
</html>

0 comments on commit c1d7c3c

Please sign in to comment.