1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

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
This commit is contained in:
epriestley 2016-07-15 10:10:09 -07:00
parent cf57f6385b
commit e2b6912b9d
6 changed files with 107 additions and 7 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_calendar.calendar_event
ADD allDayDateFrom INT UNSIGNED NOT NULL;

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_calendar.calendar_event
ADD allDayDateTo INT UNSIGNED NOT NULL;

View file

@ -0,0 +1,52 @@
<?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());
}

View file

@ -19,6 +19,8 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
protected $hostPHID;
protected $dateFrom;
protected $dateTo;
protected $allDayDateFrom;
protected $allDayDateTo;
protected $description;
protected $isCancelled;
protected $isAllDay;
@ -62,7 +64,9 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
$view_policy = $app->getPolicy($view_default);
$edit_policy = $app->getPolicy($edit_default);
$start = new DateTime('@'.PhabricatorTime::getNow());
$now = PhabricatorTime::getNow();
$start = new DateTime('@'.$now);
$start->setTimeZone($actor->getTimeZone());
$start->setTime($start->format('H'), 0, 0);
@ -72,6 +76,10 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
$epoch_min = $start->format('U');
$epoch_max = $end->format('U');
$now_date = new DateTime('@'.$now);
$now_min = id(clone $now_date)->setTime(0, 0)->format('U');
$now_max = id(clone $now_date)->setTime(23, 59)->format('U');
$default_icon = 'fa-calendar';
return id(new PhabricatorCalendarEvent())
@ -91,6 +99,8 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
->attachInvitees(array())
->setDateFrom($epoch_min)
->setDateTo($epoch_max)
->setAllDayDateFrom($now_min)
->setAllDayDateTo($now_max)
->applyViewerTimezone($actor);
}
@ -171,9 +181,21 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
$duration = $this->getDuration();
$utc = new DateTimeZone('UTC');
$allday_from = $parent->getAllDayDateFrom();
$allday_date = new DateTime('@'.$allday_from, $utc);
$allday_date->setTimeZone($utc);
$allday_date->modify($modify_key);
$allday_min = $allday_date->format('U');
$allday_duration = ($parent->getAllDayDateTo() - $allday_from);
$this
->setDateFrom($date)
->setDateTo($date + $duration);
->setDateTo($date + $duration)
->setAllDayDateFrom($allday_min)
->setAllDayDateTo($allday_min + $allday_duration);
return $this;
}
@ -227,15 +249,15 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
} else {
$zone = $viewer->getTimeZone();
$this->viewerDateFrom = $this->getDateEpochForTimeZone(
$this->getDateFrom(),
$this->viewerDateFrom = $this->getDateEpochForTimezone(
$this->getAllDayDateFrom(),
new DateTimeZone('UTC'),
'Y-m-d',
null,
$zone);
$this->viewerDateTo = $this->getDateEpochForTimeZone(
$this->getDateTo(),
$this->viewerDateTo = $this->getDateEpochForTimezone(
$this->getAllDayDateTo(),
new DateTimeZone('UTC'),
'Y-m-d 23:59:00',
null,
@ -249,7 +271,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return $this->getDateTo() - $this->getDateFrom();
}
private function getDateEpochForTimeZone(
public function getDateEpochForTimezone(
$epoch,
$src_zone,
$format,
@ -295,6 +317,8 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
'name' => 'text',
'dateFrom' => 'epoch',
'dateTo' => 'epoch',
'allDayDateFrom' => 'epoch',
'allDayDateTo' => 'epoch',
'description' => 'text',
'isCancelled' => 'bool',
'isAllDay' => 'bool',

View file

@ -10,7 +10,17 @@ final class PhabricatorCalendarEventEndDateTransaction
}
public function applyInternalEffects($object, $value) {
$actor = $this->getActor();
$object->setDateTo($value);
$object->setAllDayDateTo(
$object->getDateEpochForTimezone(
$value,
$actor->getTimeZone(),
'Y-m-d 23:59:00',
null,
new DateTimeZone('UTC')));
}
public function getTitle() {

View file

@ -10,7 +10,17 @@ final class PhabricatorCalendarEventStartDateTransaction
}
public function applyInternalEffects($object, $value) {
$actor = $this->getActor();
$object->setDateFrom($value);
$object->setAllDayDateFrom(
$object->getDateEpochForTimezone(
$value,
$actor->getTimeZone(),
'Y-m-d',
null,
new DateTimeZone('UTC')));
}
public function getTitle() {