Fix time display on stats page.

This fixes an issue where times are appearing incorrectly on the stats.php page if php's date.timezone is different than the system's timezone.

The daily and monthly graphs are still grouped/counted in the sqlite query, so they will still use the incorrect time zone.

EDIT: I'm delegating the grouping/counting from sqlite to php to allow for proper handling of the time/timezone. Closing this PR as it'll shortly be replaced.