[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] Make scheduler log times more legible (backport from master/29.x)
"Jonny Bradley \(@jonnybradley\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <697a3954e1e32_3b183b9880382@gitlab-sidekiq-low-urgency-cpu-bound-v2-58c677955c-6mp5b.mail> |
Jonny Bradley pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki Commits: 27e34908 by Jonny Bradley at 2026-01-28T16:21:49+00:00 Make scheduler log times more legible (backport from master/29.x) --- * [FIX] Reapply 4e977a5c to fix time display in scheduler * [NEW] Add UTC datetimes below the current datetimes in the logs list tiki-admin_schedulers.php?scheduler=3&logs=1 Both should display TimeZone (manual cherry pick from 5a4d9e97c0a6337221f2a055ac82fed0f2e8b891 - needed for 4e977a5c backport) --- * [FIX] Pipeline Correct. * [FIX] Correction of the code. * [NEW] Added comment for new forceTimezone parameter * [NEW] Add error if user is not false and forceTimezone is specified. * Add the possibility of passing the timezone directly * [NEW] Add parameter comments * [NEW] Add UTC datetimes below the current datetimes in the logs list tiki-admin_schedulers.php?scheduler=3&logs=1 Both should display TimeZone. See merge request tikiwiki/tiki!7134 (cherry picked from commit 5a4d9e97c0a6337221f2a055ac82fed0f2e8b891) * Make scheduler log times more legible (manually cherry picked from commit 4e977a5ceeeb1489e6a13319095641100a62b8f1) --- * [FIX] scheduler: Correect indentation on tab 3 (logs) Mainly to see if this will unstick the merge train (been merging for over 3 hours) * [FIX] scheduler: Don't use "same day" option when formatting scheduler timestamps (thanks @jyhem) See merge request tikiwiki/tiki!9425 (cherry picked from commit c2bf889a315f0754924132d33d00a9ed48b51a09) d613ea4b [FIX] scheduler: Don't use "same day" option when formatting scheduler timestamps (thanks @jyhem) 04ea5cac [FIX] scheduler: Correect indentation on tab 3 (logs) Co-authored-by: Jonny Bradley <[email protected]> See merge request tikiwiki/tiki!9427 - - - - - 6 changed files: - lib/smarty_tiki/Modifier/TikiDateFormat.php - lib/smarty_tiki/Modifier/TikiShortDateTime.php - lib/smarty_tiki/modifier.tiki_date_format.php - lib/tikilib.php - templates/tiki-admin_schedulers.tpl - tiki-admin_schedulers.php Changes: ===================================== lib/smarty_tiki/Modifier/TikiDateFormat.php ===================================== @@ -16,12 +16,21 @@ namespace SmartyTiki\Modifier; * Input: string: string representing a moment * format: strftime() format for output. For standard formats, see modifiers tiki_{long,short}_{date,datetime,time}. * _user: if specified, use this user timezone instead of the current user + * forceTimezone: the time zone to be applied, if you prefer to use a specific timezone. * ------------------------------------------------------------- */ class TikiDateFormat { - public function handle($string, $format, $_user = false) + /** + * @param string $string the string representing the date to be formatted. + * @param string $format the desired date format. + * @param string|false $_user if specified, use this user's timezone instead of the current user's, if specified forceTimezone must be false. + * @param string|false $forceTimezone the time zone to be applied. Can be a timezone identifier or false, if user is not false forceTimezone must always be false. + * + * @return string + */ + public function handle(string $string, string $format, string|false $_user = false, string|false $forceTimezone = false): string { - return \TikiLib::date_format(tra($format), $string, $_user); + return \TikiLib::date_format(tra($format), $string, $_user, 5, true, $forceTimezone); } } ===================================== lib/smarty_tiki/Modifier/TikiShortDateTime.php ===================================== @@ -15,15 +15,16 @@ class TikiShortDateTime * @param string $string * @param string $intro * @param string $same if set to 'n' will bypass timeago preferences. Useful when markup is illegal in date + * @param bool|string $forceTimezone the time zone to be applied. Can be a timezone identifier or false, if user is not false forceTimezone must always be false * * @return string */ - public function handle($string, $intro = '', $same = 'y') + public function handle($string, $intro = '', $same = 'y', $forceTimezone = false) { global $prefs; $smarty = TikiLib::lib('smarty'); - $date = smarty_modifier_tiki_date_format($string, $prefs['short_date_format']); - $time = smarty_modifier_tiki_date_format($string, $prefs['short_time_format']); + $date = smarty_modifier_tiki_date_format($string, $prefs['short_date_format'], false, $forceTimezone); + $time = smarty_modifier_tiki_date_format($string, $prefs['short_time_format'], false, $forceTimezone); $intro = ! empty($intro) ? tra($intro) . ' ' : ''; ===================================== lib/smarty_tiki/modifier.tiki_date_format.php ===================================== @@ -4,9 +4,17 @@ // // All Rights Reserved. See copyright.txt for details and a complete list of authors. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. +/** + * @param string $string the string representing the date to be formatted. + * @param string $format the desired date format. + * @param string|false $_user if specified, use this user's timezone instead of the current user's, if specified forceTimezone must be false. + * @param string|false $forceTimezone the time zone to be applied. Can be a timezone identifier or false, if user is not false forceTimezone must always be false. + * + * @return string + */ -function smarty_modifier_tiki_date_format($string, $format, $_user = false) +function smarty_modifier_tiki_date_format(string $string, string $format, string|false $_user = false, string|false $forceTimezone = false): string { $tikiDateFormatModifier = new \SmartyTiki\Modifier\TikiDateFormat(); - return $tikiDateFormatModifier->handle($string, $format, $_user); + return $tikiDateFormatModifier->handle($string, $format, $_user, $forceTimezone); } ===================================== lib/tikilib.php ===================================== @@ -5795,18 +5795,20 @@ class TikiLib extends TikiDb_Bridge } /** - * @param $format - * @param bool $timestamp - * @param bool $_user - * @param int $input_format - * @param bool $is_strftime_format + * @param string $format the desired date format. + * @param int|false $timestamp The timestamp to be formatted. Can be an integer representing a UNIX timestamp or false. + * @param string|false $_user if specified, use this user's timezone instead of the current user's, if specified forceTimezone must be false. + * @param int $input_format Input format, default 5 (DATE_FORMAT_UNIXTIME). + * @param bool $is_strftime_format indicates whether the format is strftime. + * @param string|false $forceTimezone the time zone to be applied. Can be a timezone identifier or false, if user is not false forceTimezone must always be false. + * * @return string */ - public static function date_format($format, $timestamp = false, $_user = false, $input_format = 5/*DATE_FORMAT_UNIXTIME*/, $is_strftime_format = true, $use_display_tz = true) + public static function date_format(string $format, int|false $timestamp = false, string|false $_user = false, int $input_format = 5, bool $is_strftime_format = true, string|false $forceTimezone = false): string { + global $user; $tikilib = TikiLib::lib('tiki'); static $currentUserDateByFormat = []; - if (! $timestamp) { $timestamp = $tikilib->now; } @@ -5822,10 +5824,10 @@ class TikiLib extends TikiDb_Bridge return $e->getMessage(); } - $tz = $tikilib->get_display_timezone($_user); - - // If user timezone is not also in UTC, convert the date - if ($tz != 'UTC' && $use_display_tz) { + if ($_user !== false && $forceTimezone !== false) { + throw new InvalidArgumentException('Either $_user or $forceTimezone should be provided, not both.'); + } else { + $tz = $forceTimezone !== false ? $forceTimezone : $tikilib->get_display_timezone($_user); $tikidate->setTZbyID($tz); } ===================================== templates/tiki-admin_schedulers.tpl ===================================== @@ -232,57 +232,69 @@ </form> {/tab} - <a id="tab3"></a> - {if isset($schedulerinfo.id) && $schedulerinfo.id} - {tab name="{tr}Scheduler logs{/tr}"} - <h2>{tr}Scheduler{/tr} {$schedulerinfo.name|escape} Logs</h2> - <h3>{tr}Last {$numOfLogs} Logs{/tr}</h3> - <div class="table-responsive"> - <table class="table normal table-striped table-hover"> - <thead> +<a id="tab3"></a> +{if isset($schedulerinfo.id) && $schedulerinfo.id} + {tab name="{tr}Scheduler logs{/tr}"} + <h2>{tr}Scheduler{/tr} {$schedulerinfo.name|escape} Logs</h2> + <h3>{tr}Last {$numOfLogs} Logs{/tr}</h3> + <div class="table-responsive"> + <table class="table normal table-striped table-hover"> + <thead> + <tr> + <th>ID</th> + <th>Start Time</th> + <th>End Time</th> + <th>Status</th> + <th>Output</th> + </tr> + </thead> + <tbody> + {section name=run loop=$schedulerruns} <tr> - <th>ID</th> - <th>Start Time</th> - <th>End Time</th> - <th>Status</th> - <th>Output</th> - </tr> - </thead> - <tbody> - {section name=run loop=$schedulerruns} - <tr> - <td>{$schedulerruns[run].id}</td> - <td>{$schedulerruns[run].start_time|tiki_short_datetime}</td> - <td>{if $schedulerruns[run].end_time ne null}{$schedulerruns[run].end_time|tiki_short_datetime}{/if}</td> - <td> - {if $schedulerruns[run].status eq 'running'} - <span class="badge bg-warning">{tr}Running{/tr}</span> + <td>{$schedulerruns[run].id}</td> + <td> + {$schedulerruns[run].start_time|tiki_short_datetime:'':'n'} ({$display_timezone}) + {if $display_timezone ne 'UTC'} + <br>{$schedulerruns[run].start_time|tiki_short_datetime:'':'n':'UTC'} (UTC) + {/if} + </td> + <td> + {if $schedulerruns[run].end_time ne null} + {$schedulerruns[run].end_time|tiki_short_datetime:'':'n'} ({$display_timezone}) + {if $display_timezone ne 'UTC'} + <br>{$schedulerruns[run].end_time|tiki_short_datetime:'':'n':'UTC'} (UTC) {/if} - {if $schedulerruns[run].status eq 'failed'} - <span class="badge bg-danger">{tr}Failed{/tr}</span> + {/if} + </td> + <td> + {if $schedulerruns[run].status eq 'running'} + <span class="badge bg-warning">{tr}Running{/tr}</span> + {/if} + {if $schedulerruns[run].status eq 'failed'} + <span class="badge bg-danger">{tr}Failed{/tr}</span> - {/if} - {if $schedulerruns[run].status eq 'done'} - <span class="badge bg-success">{tr}Done{/tr}</span> - {/if} - </td> - <td> - {if isset($schedulerruns[run].can_stop) && $schedulerruns[run].can_stop} - <a class="btn btn-secondary btn-sm" href="{bootstrap_modal controller=scheduler action=reset schedulerId=$schedulerruns[run].scheduler_id startTime=$schedulerruns[run].start_time}"> - {icon name="undo" _menu_text='y' _menu_icon='y' alt="{tr}Reset{/tr}"} - </a> - {else} - {$schedulerruns[run].output|nl2br} - {/if} - </td> - </tr> - {/section} - </tbody> - </table> - </div> + {/if} + {if $schedulerruns[run].status eq 'done'} + <span class="badge bg-success">{tr}Done{/tr}</span> + {/if} + </td> + <td> + {if isset($schedulerruns[run].can_stop) && $schedulerruns[run].can_stop} + <a class="btn btn-secondary btn-sm" href="{bootstrap_modal controller=scheduler action=reset schedulerId=$schedulerruns[run].scheduler_id startTime=$schedulerruns[run].start_time}"> + {icon name="undo" _menu_text='y' _menu_icon='y' alt="{tr}Reset{/tr}"} + </a> + {else} + {$schedulerruns[run].output|nl2br} + {/if} + </td> + </tr> + {/section} + </tbody> + </table> + </div> {pagination_links cant=$cant step=$numrows offset=$offset}tiki-admin_schedulers.php?scheduler={$schedulerinfo.id}&cookietab=3{/pagination_links} - {/tab} - {/if} + {/tab} +{/if} <a id="tab4"></a> {if $jobs|count > 0} ===================================== tiki-admin_schedulers.php ===================================== @@ -233,6 +233,7 @@ if (isset($_REQUEST['add'])) { } $headerlib->add_jsfile('lib/jquery_tiki/tiki-schedulers.js'); +$smarty->assign('display_timezone', TikiLib::lib('tiki')->get_display_timezone(false)); $smarty->assign('schedulerinfo', $schedulerinfo); $smarty->assign('schedulerruns', isset($schedulerRuns) ? $schedulerRuns : []); $smarty->assign('schedulerId', $scheduler); View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/27e34908cfc96aa79100ec311d655bad8918b809 -- View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/27e34908cfc96aa79100ec311d655bad8918b809 You're receiving this email because of your account on gitlab.com. _______________________________________________ TikiWiki-cvs mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs