diff --git a/api/etemplate.php b/api/etemplate.php index 88fd0034d4..03c687f76b 100644 --- a/api/etemplate.php +++ b/api/etemplate.php @@ -13,7 +13,7 @@ use EGroupware\Api; // add et2- prefix to following widgets/tags -const ADD_ET2_PREFIX_REGEXP = '#<((/?)([vh]?box|date(-time[^\s]*|-duration)?|textbox|textarea|button|colorpicker|description|image|url(-email|-phone|-fax)?))(/?|\s[^>]*)>#m'; +const ADD_ET2_PREFIX_REGEXP = '#<((/?)([vh]?box|date(-time[^\s]*|-duration|-since)?|textbox|textarea|button|colorpicker|description|image|url(-email|-phone|-fax)?))(/?|\s[^>]*)>#m'; const ADD_ET2_PREFIX_LAST_GROUP = 6; // switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression @@ -92,7 +92,11 @@ function send_template() // eTemplate marked as legacy --> replace only some widgets (eg. requiring jQueryUI) with web-components if (preg_match('/]* legacy="true"/', $str)) { - $str = preg_replace('#]+)/>#', '', $str); + $str = preg_replace_callback('#]+)/>#', static function($matches) + { + if ($matches[1] === 'date-time_today') $matches[1] = 'date-time-today'; + return ""; + }, $str); } else { @@ -211,6 +215,7 @@ function send_template() }, $str); $str = preg_replace_callback(ADD_ET2_PREFIX_REGEXP, static function (array $matches) { + if ($matches[3] === 'date-time_today') $matches[3] = 'date-time-today'; return '<' . $matches[2] . 'et2-' . $matches[3] . // web-components must not be self-closing (no "", but "") (substr($matches[ADD_ET2_PREFIX_LAST_GROUP], -1) === '/' ? substr($matches[ADD_ET2_PREFIX_LAST_GROUP], 0, -1) . diff --git a/api/js/etemplate/Et2Date/Et2DateSinceReadonly.ts b/api/js/etemplate/Et2Date/Et2DateSinceReadonly.ts index 807c891a4a..30fbc7aaa9 100644 --- a/api/js/etemplate/Et2Date/Et2DateSinceReadonly.ts +++ b/api/js/etemplate/Et2Date/Et2DateSinceReadonly.ts @@ -37,7 +37,7 @@ const formatDate = function(date : Date, options = {units: "YmdHis"}) 's': 1 }; var d = new Date(); - var diff = Math.round(d.valueOf() / 1000) - Math.round(date.valueOf() / 1000); + var diff = Math.round(d.valueOf() / 1000) - Math.round(date.valueOf() / 1000 + egw.getTimezoneOffset() * 60); let display = ''; // limit units used to display diff --git a/api/js/etemplate/Et2Date/Et2DateTimeToday.ts b/api/js/etemplate/Et2Date/Et2DateTimeToday.ts index e7c6b3c514..71923b6145 100644 --- a/api/js/etemplate/Et2Date/Et2DateTimeToday.ts +++ b/api/js/etemplate/Et2Date/Et2DateTimeToday.ts @@ -12,7 +12,7 @@ import {Et2DateReadonly} from "./Et2DateReadonly"; /** * Widget displays date/time with different formatting relative to today - * If the date is today, we show just the time. Otherwise, full date + time. + * If the date is today, we show just the time, otherwise just the date. */ export class Et2DateTimeToday extends Et2DateReadonly { @@ -39,14 +39,14 @@ export class Et2DateTimeToday extends Et2DateReadonly { display = formatTime(date); } - // Before today - date and time + // Before today - just the date else { - display = formatDateTime(date); + display = formatDate(date); } return display; } } // @ts-ignore TypeScript is not recognizing that this is a LitElement -customElements.define("et2-date-time_today", Et2DateTimeToday); \ No newline at end of file +customElements.define("et2-date-time-today", Et2DateTimeToday); \ No newline at end of file diff --git a/api/js/jsapi/egw_calendar.js b/api/js/jsapi/egw_calendar.js index 5a211f2379..00bf9cb8dc 100644 --- a/api/js/jsapi/egw_calendar.js +++ b/api/js/jsapi/egw_calendar.js @@ -36,7 +36,7 @@ egw.extend('calendar', egw.MODULE_WND_LOCAL, function(_app, _wnd) .replace("m","mm") .replace("M", "M") .replace('H', 'hh') - .replace('i', 'mm') // datepicker uses mm for month and minutes, depending where in format it's written! + .replace('i', 'mm') // datepicker uses mm for month and minutes, depending on where in format it's written! .replace('s', 'ss'); } @@ -77,11 +77,21 @@ egw.extend('calendar', egw.MODULE_WND_LOCAL, function(_app, _wnd) { return dateTimeFormat(_php_format); }, - + /** + * Get timezone offset of user in seconds + * + * If browser / OS is configured correct, identical to: (new Date()).getTimezoneOffset() + * + * @return {number} offset to UTC in seconds + */ + getTimezoneOffset: function() { + return isNaN(egw.preference('timezoneoffset')) ? (new Date()).getTimezoneOffset() : parseInt(egw.preference('timezoneoffset')); + }, /** * Calculate the start of the week, according to user's preference * * @param {string} date + * @return {Date} */ week_start: function(date) { var d = new Date(date); diff --git a/api/js/jsapi/egw_global.d.ts b/api/js/jsapi/egw_global.d.ts index 845aade8dd..40c022a65e 100644 --- a/api/js/jsapi/egw_global.d.ts +++ b/api/js/jsapi/egw_global.d.ts @@ -674,6 +674,32 @@ declare interface IegwGlobal * @param {Window|String} closed Window that was closed, or its name */ windowClosed(appname : string, closed : Window|string) : void; + + /** + * implemented in egw_calendar.js + */ + /** + * transform PHP date/time-format to jQuery date/time-format + * + * @param {string} _php_format + * @returns {string} + */ + dateTimeFormat(_php_format : string) : string; + /** + * Get timezone offset of user in seconds + * + * If browser / OS is configured correct, identical to: (new Date()).getTimezoneOffset() + * + * @return {number} offset to UTC in seconds + */ + getTimezoneOffset() : number; + /** + * Calculate the start of the week, according to user's preference + * + * @param {string} date + * @return {Date} + */ + week_start(date : string) : Date; } declare class JsonRequest @@ -1326,4 +1352,4 @@ declare function egw_get_file_editor_prefered_mimes(_mime : string) : {mime:stri // Youtube API golbal vars declare var YT : any; -declare function onYouTubeIframeAPIReady(); +declare function onYouTubeIframeAPIReady(); \ No newline at end of file diff --git a/api/user.php b/api/user.php index 3a016b6879..da0a7d0c4e 100644 --- a/api/user.php +++ b/api/user.php @@ -31,6 +31,8 @@ $GLOBALS['egw']->session->commit_session(); // use an etag over config and link-registry $preferences['common'] = $GLOBALS['egw_info']['user']['preferences']['common']; +// send users timezone offset to client-side +$preferences['common']['timezoneoffset'] = -Api\DateTime::$user_timezone->getOffset(new Api\DateTime('now')) / 60; foreach(['addressbook', 'notifications', 'status', 'filemanager'] as $app) { if (!empty($GLOBALS['egw_info']['user']['apps'][$app])) @@ -68,4 +70,4 @@ if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_ // Content-Lenght header is important, otherwise browsers dont cache! Header('Content-Length: '.bytes($content)); -echo $content; +echo $content; \ No newline at end of file