-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moodle timezone set but on-demand reports show as not run #92
Comments
Thank you for the bug report. We don't see on our system (which is Europe/London). I cannot immediately see why adding that line of code would fix the problem. I would be better to understand it more before changing things, so any extra information you can give would be helpful. |
We have encountered the same situation. In "Reports" > "Ad-hoc database queries" page, On-demand queries show information on the last runs, such as: "This query was last run on Friday, 29 December 2023, 7:48 PM. It took 0.017s to run. Available to ...", with correct timestamps in local timezone Asia/Tokyo. However, clicking any On-demand queries returns "This query has not yet been run." At the same time, under /moodledata/admin_report_customsql/temp/X directory, new csv file with the UTC timestamp is created. Our environment is as follows:
As suggested by @mikehenry1979-bah, putting date_default_timezone_set('Asia/Tokyo'); into the top of report_customsql_generate_csv funtion in locallib.php resolves the issue; query result is correctly shown in the query result page, and new csv file with its name including local timezone timestamp created. Some further investigation revealed that, in view.php file, date_default_timezone_get returns "Asia/Tokyo" at first, but "Europe/London" is returned just after admin_externalpage_setup function is called at the line 43, until I could not figure out why admin_externalpage_setup function changes date_default_timezone variable, but putting Hope this helps in further investigation. |
So, if I understand your analysis correctly, something in admin_externalpage_setup is setting the timezone to "Europe/London". It would be really good to work out what is doing that, since it seems like a bug to me. |
Hi, To fix that, you have to create a new DateTime obect and set the timestamp and timezone manually before formatting: function report_customsql_temp_cvs_name($reportid, $timestamp) {
global $CFG;
$path = 'admin_report_customsql/temp/'.$reportid;
make_upload_directory($path);
return array($CFG->dataroot.'/'.$path.'/'. report_customsql_formatdatetime_from_timestamp($timestamp).'.csv',
$timestamp);
}
function report_customsql_scheduled_cvs_name($reportid, $timestart) {
global $CFG;
$path = 'admin_report_customsql/'.$reportid;
make_upload_directory($path);
return array($CFG->dataroot.'/'.$path.'/'.report_customsql_formatdatetime_from_timestamp($timestart).'.csv',
$timestart);
}
function report_customsql_formatdatetime_from_timestamp($timestamp) {
global $CFG;
return (new DateTime())->setTimestamp($timestamp)->setTimezone(new DateTimeZone($CFG->timezone))->format('Ymd-His');
} |
Hi, My setup is Europe/Berlin for the system, PHP, Moodle and the user! As workaround I have moved the OUTPUT->header() up behind get_renderer.
Also I deleted the duplicate
Hope this could be helpful. |
Hi,
See here: #97 |
Moodle config.php has date_default_timezone_set('America/New_York'); and Site Administration/Location/Location Settings shows default timezone as the same, but on-demand reports show as "this query has not yet been run". Adding date_default_timezone_set('America/New_York'); to line 101 of locallib.php fixes this issue. Our system encountered this issue with version 4.0 of this plugin and it is still present in 4.1. I thought about involvement of the setting "allow users to select their own timezone" but the profile of the user attempting the report shows "server timezone (America/New_York)". Is there also some PHP-level setting?
The text was updated successfully, but these errors were encountered: