Pepperminty-Wiki
Pepperminty-Wiki copied to clipboard
Futureproofing: Improve datetime handling
Currently, Pepperminty Wiki handles dates as UNIX timestamps. This is fine, but it isn't particularly future-proof. I think it's about time we do some proper date and time handling, using PHP's DateTime
class. We should do this soon - the longer we leave it, the bigger job and more unpleasant it's going to be later..... just like a few other issues here (e.g. #187).
This will also have the side effect that the page index will become easier to edit the dates & times by hand, which is a nice addition.
The standard we're going to adopt is ISO 8601, with all datetimes being stored in UTC (regardless of the server's time zone, the time zone of the user who made an edit, or any other timezone). We can set the timezone on a DateTime like this:
$datetime_obj->setTimezone(new DateTimeZone("UTC"));
This will change the timezone to UTC - but it will also adjust the time too so that it still represents the same absolute point in time, just in UTC instead of whatever it was originally.
Things to remember when making this change:
- We need to fix all references to
lastmodified
properties in the page index - Don't forget all references to timestamps everywhere
- History revision timestamp handling will need to be adjusted too.
- We'll need to maintain backwards compatibility - this will probably done via a migration function
Regarding that last point in particular, my current thought is to have a setting that defaults to false
that's checked on start that if it isn't set to true
will trigger the migration function. Perhaps it could be called something like datetime_migration_complete
perhaps?
Relevant docs:
- https://www.php.net/manual/en/datetime.format.php
- https://www.php.net/manual/en/datetime.settimezone.php
- https://www.php.net/manual/en/class.datetimeinterface.php#datetime.constants.types - we want
DateTime::ATOM