mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 06:30:59 +01:00
fix not working et2-date-since and rename et2-date-time_today to et2-date-time-today
create a new method egw.getTimezoneOffset() return current offset according to user preferences on server-side, like (new Date).getTimezoneOffset()
This commit is contained in:
parent
2442e80cea
commit
3eaed09185
@ -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('/<overlay[^>]* legacy="true"/', $str))
|
||||
{
|
||||
$str = preg_replace('#<date(-time[^\s]*|-duration)?\s([^>]+)/>#', '<et2-date$1 $2></et2-date$1>', $str);
|
||||
$str = preg_replace_callback('#<date(-time[^\s]*|-duration|-since)?\s([^>]+)/>#', static function($matches)
|
||||
{
|
||||
if ($matches[1] === 'date-time_today') $matches[1] = 'date-time-today';
|
||||
return "<et2-date$matches[1] $matches[2]></et2-date$matches[1]>";
|
||||
}, $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 "<et2-button .../>", but "<et2-button ...></et2-button>")
|
||||
(substr($matches[ADD_ET2_PREFIX_LAST_GROUP], -1) === '/' ? substr($matches[ADD_ET2_PREFIX_LAST_GROUP], 0, -1) .
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
customElements.define("et2-date-time-today", Et2DateTimeToday);
|
@ -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);
|
||||
|
28
api/js/jsapi/egw_global.d.ts
vendored
28
api/js/jsapi/egw_global.d.ts
vendored
@ -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();
|
@ -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;
|
Loading…
Reference in New Issue
Block a user