1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00
phorge-phorge/resources/sql/autopatches/20160715.event.03.allday.php

53 lines
1.5 KiB
PHP
Raw Normal View History

Store "All Day" events in a way that is compatible with EditEngine Summary: Ref T11326. Normally, events occur at a specific epoch, independent of the viewer. For example, if we're having a meeting in 35 hours, every user who looks at the event will see that it starts 35 hours from now. But when an event is "All Day", the start time and end time depend on the //viewer//. A day like "Christmas" does not start at the same time for everyone: it starts sooner if you're in a more-eastern timezone. Baiscally, an event on "July 15th" starts whenever "July 15th" starts for whoever is looking at it. Previously, we stored these events by using the western-most and eastern-most timezones as the start and end times (the earliest possible start and latest possible end). This worked OK, but we get into a bunch of trouble with EditEngine, mostly because each field can be updated individually now. We can't easily tell if an event is all-day or not when reading or updating the start time and end time, and making that easier would introduce a huge amount of complexity. Instead, when we update the start or end time, we write //two// times: - The epoch timestamp of the time the user entered, which is the start time we will use if the event is a normal event. - The epoch timestamp of 12:00 AM in UTC on the same date as the //local// date the user entered. This is pretty much like just storing the date the user actually typed. This is what w'ell use if the event is an all-day event. Then, no matter whether the event is later made all-day or not, we have all the information we need to display it correctly. Test Plan: - Created and edited all-day events. - Migrated existing all-day events, which appeared to survive without problems. (Note that events all-day which were created or edited in the last couple of days `master` won't survive this mutation correctly and will need to be fixed.) - Created and edited normal, recurring, and recurring all-day events. - Swapped back to `stable`, created an event, specifically migrated it forward, made sure it survived with times intact. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11326 Differential Revision: https://secure.phabricator.com/D16305
2016-07-15 19:10:09 +02:00
<?php
$table = new PhabricatorCalendarEvent();
$conn = $table->establishConnection('w');
// Previously, "All Day" events were stored with a start and end date set to
// the earliest possible start and end seconds for the corresponding days. We
// now store all day events with their "date" epochs as UTC, separate from
// individual event times.
$zone_min = new DateTimeZone('Pacific/Midway');
$zone_max = new DateTimeZone('Pacific/Kiritimati');
$zone_utc = new DateTimeZone('UTC');
foreach (new LiskMigrationIterator($table) as $event) {
// If this event has already migrated, skip it.
if ($event->getAllDayDateFrom()) {
continue;
}
$is_all_day = $event->getIsAllDay();
$epoch_min = $event->getDateFrom();
$epoch_max = $event->getDateTo();
$date_min = new DateTime('@'.$epoch_min);
$date_max = new DateTime('@'.$epoch_max);
if ($is_all_day) {
$date_min->setTimeZone($zone_min);
$date_min->modify('+2 days');
$date_max->setTimeZone($zone_max);
$date_max->modify('-2 days');
} else {
$date_min->setTimeZone($zone_utc);
$date_max->setTimeZone($zone_utc);
}
$string_min = $date_min->format('Y-m-d');
$string_max = $date_max->format('Y-m-d 23:59:00');
$allday_min = id(new DateTime($string_min, $zone_utc))->format('U');
$allday_max = id(new DateTime($string_max, $zone_utc))->format('U');
queryfx(
$conn,
'UPDATE %T SET allDayDateFrom = %d, allDayDateTo = %d
WHERE id = %d',
$table->getTableName(),
$allday_min,
$allday_max,
$event->getID());
}