Skip to content

Commit

Permalink
IndexStatsView: fix "invalid date" error
Browse files Browse the repository at this point in the history
The stats graph on the index page shows hourly answer and user counts on
hover. Though with Safari the label doesn't show the datetime but an
error message "invalid date". This is because the datetime string as
received from the API doesn't adhere to a standard datetime format (by
default, datetime fields are stored as UTC in the format
`2018-01-01 00:00:00`).

Update the scheduled stats routine to send datetime keys in ISO 8601
format (https://en.wikipedia.org/wiki/ISO_8601) and update the frontend
code to use date-fns's `parseISO` to parse the date from the label
context for the local time zone.

Also, change the index stats graph to show at most 4 ticks on the
y-axis.

Resolves #853
  • Loading branch information
schu committed May 6, 2024
1 parent 410d328 commit 66bc531
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 45 deletions.
5 changes: 3 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ protected function schedule(Schedule $schedule): void
$usersByHour = [];
foreach($range as $hour) {
$hourString = $hour->format('Y-m-d H:i:s');
$answersByHour[$hourString] = isset($answerChoicesByHour[$hourString]) ? count($answerChoicesByHour[$hourString]) : 0;
$usersByHour[$hourString] = isset($answerChoicesByHour[$hourString]) ?
$hourStringISO8601 = $hour->format('Y-m-d\TH:i:s\Z');
$answersByHour[$hourStringISO8601] = isset($answerChoicesByHour[$hourString]) ? count($answerChoicesByHour[$hourString]) : 0;
$usersByHour[$hourStringISO8601] = isset($answerChoicesByHour[$hourString]) ?
count(array_unique(
$answerChoicesByHour[$hourString]
->map(function ($ac) { return $ac->session->user_id; })
Expand Down
1 change: 1 addition & 0 deletions public/build/assets/IndexSessionView-BhW6sSfw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/build/assets/IndexSessionView-COqqUes9.js

This file was deleted.

0 comments on commit 66bc531

Please sign in to comment.