Closed thekid closed 3 years ago
See also:
timeZone=...
& Intl.DateTimeFormatIdea:
$local= TimeZone::getLocal();
$templates= new Handlebars($path);
$templates->output(
timezone: fn($req) => $req->value('user')['tz'] ?? $local,
dateformats: ['day' => 'd.m.Y']
);
Modern browsers support this:
Intl.DateTimeFormat().resolvedOptions().timeZone;
// "Europe/Berlin" in my case
Source: https://stackoverflow.com/questions/13/determine-a-users-timezone
This could be transmitted to the server in a cookie, by redirect or by XHR but would not work for the first request to the page, thus requiring a redirect.
Idea based on use
method which accepts a collection of helpers:
$local= TimeZone::getLocal();
$templates= new Handlebars($path);
$templates->use(new Dates(
timezone : fn($req) => $req->value('user')['tz'] ?? $local,
formats : ['date' => 'd.m.Y', 'time' => 'H:i:s', 'datetime' => 'd.m.Y H:i'],
));
Basic functionality of using a server-side default timezone implemented by #4 , xp-forge/handlebars-templates@de77af5 and xp-forge/handlebars-templates@ce196a1 - extracting the timezone from the request will be handled separately.
Currently, dates are displayed as-is in the frontend. However, the user viewing the frontend may be in a different timezone, and in case we're using timestamps, most commonly will be.
One way would be to pass the timezone as optional argument:
However, a default timezone may be a good idea. It could cascade as follows: