Open hdodov opened 4 years ago
I like the idea! However I think the option should be called something like userTime
.
@lukasbestle it depends on your point of view. If you're in the panel, it's your local (user) time, yes. But from the perspective of Kirby, it's UTC. I called it utc
because that's what's actually stored and if you're looking at the content files, you'd be less surprised to find the dates there are completely different from those entered in the panel, i.e. userTime
. Since the editor isn't bothered with that option name, it should be more intuitive for the developer?
The option could also be called coordinated
or sync
because it synchronizes the various editors.
Strong vote for utc
because this correctly labels the date while userTime
could be anything.
I have to say that I'm also for utc as option name.
You are right! If we look at it from the perspective of what gets stored, utc
makes sense.
We had a discussion in Slack regarding timezones and calculating relative time.
The gist of it was that I wanted to display how much time has passed since a stored date in Kirby. I thought I had to take the site visitor's timezone into account, but I don't. As I said in Slack:
So the timezone doesn't matter as long as it's the same, which could be a problem if there are multiple editors changing a single date. You might point me to the PHP docs for time formats where there's the RFC 2822
r
format:That
+0100
part is the timezone indeed, but the server's timezone, which is basically useless. If there are two editors in two different timezones, the dates they save will be in the server's timezone, which would always be the same.Example
Let's say we have Cho from Seoul (UTC+9) and Emma from Berlin (UTC+1). They both create a page at March 23-rd, 14:00 UTC by looking at their clocks and entering that date and time in the Kirby Panel. That date is stored in the
r
format mentioned above.Mar 23 23:00
Mar 23 15:00
However, the server is in New York (UTC-4) and it stores the following dates:
...and this is where the problem comes - the dates are stored as if both were entered in the server's timezone, UTC-4, instead of UTC+9 and UTC+1, respectively. Then, if you were to compare the two dates in PHP, you'd get an 8 hour difference for times that were entered simultaneously.
No matter what format you use to store the dates, there would always be a difference. If you use the default format, you'd still get:
Proposal
The
date
field could have a newutc
option that, when set totrue
, will make the panel app convert the user's input to and from UTC.Currently, if Cho saves
Mar 23 23:00
in the Kirby panel, it would send over the following string to the Kirby API:...then Kirby uses its own
timestamp()
helper, which in turn usesstrtotime()
to parse the input.If
utc: true
is set, the panel app could useDate.prototype.toISOString()
to convert Cho's date to this instead:...and store it as
2020-03-23 14:00
, for example.Later, Cho opens the panel again and apparently, Kirby would send the date in this format:
...and Cho would see
Mar 23 14:00
even though he enteredMar 23 23:00
? Yes, but JavaScript can parse that date as UTC and convert it to Cho's timezone if it ends withZ
:So to make that work, this line should be changed to append a
Z
ifutc: true
.Example 2
If this fix is applied and Cho and Emma use that same
date
field but withutc: true
:Mar 23 23:00
(UTC+9), Emma entersMar 23 15:00
(UTC+1)toISOString()
and saves2020-03-23 14:00
for both Cho and Emma2020-03-23 14:00Z
to both of themMar 23 23:00
for Cho andMar 23 15:00
for EmmaEven if someone else in a completely different timezone comes, he would see that time in his own timezone, but save it in UTC. This would synchronize the dates between editors. Otherwise, if Cho visits Emma's page, he'd see
15:00
, and if Emma visits Cho's page, she'd see23:00
, when in fact they entered the same date.