Skip to content

Commit

Permalink
Merge pull request #1851 from obradovichv/fix-time-l10n
Browse files Browse the repository at this point in the history
Use UTC time for server stats history, localize times on the client
  • Loading branch information
cyberw authored Aug 17, 2021
2 parents 4966195 + dccf5d4 commit d7efc71
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def stats_history(runner):
break
if runner.state != "stopped":
r = {
"time": datetime.datetime.now().strftime("%H:%M:%S"),
"time": datetime.datetime.utcnow().strftime("%H:%M:%S"),
"current_rps": stats.total.current_rps or 0,
"current_fail_per_sec": stats.total.current_fail_per_sec or 0,
"response_time_percentile_95": stats.total.get_current_response_time_percentile(0.95) or 0,
Expand Down
10 changes: 9 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,14 @@ <h2>Charts</h2>
]
});
}

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

return new Date(Date.parse(currentContent.replace(" ", "T") + ".000Z")).toLocaleString();
});
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion locust/templates/stats_data.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set time_data = [] %}{% set user_count_data = [] %}{% set current_rps_data = [] %}{% set current_fail_per_sec_data = [] %}{% set response_time_percentile_50_data = [] %}{% set response_time_percentile_95_data = [] %}{% for r in history %}{% do time_data.append(r.time) %}{% do user_count_data.append({"value": r.user_count}) %}{% do current_rps_data.append({"value": r.current_rps, "users": r.user_count}) %}{% do current_fail_per_sec_data.append({"value": r.current_fail_per_sec, "users": r.user_count}) %}{% do response_time_percentile_50_data.append({"value": r.response_time_percentile_50, "users": r.user_count}) %}{% do response_time_percentile_95_data.append({"value": r.response_time_percentile_95, "users": r.user_count}) %}{% endfor %}
var stats_history = {
"time": {{ time_data | tojson }},
"time": {{ time_data | tojson }}.map(server_time => new Date(new Date().setUTCHours(...(server_time.split(":")))).toLocaleTimeString()),
"user_count": {{ user_count_data | tojson }},
"current_rps": {{ current_rps_data | tojson }},
"current_fail_per_sec": {{ current_fail_per_sec_data | tojson }},
Expand Down

0 comments on commit d7efc71

Please sign in to comment.