Page MenuHomePhabricator

D16305.diff
No OneTemporary

D16305.diff

diff --git a/resources/sql/autopatches/20160715.event.01.alldayfrom.sql b/resources/sql/autopatches/20160715.event.01.alldayfrom.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160715.event.01.alldayfrom.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_calendar.calendar_event
+ ADD allDayDateFrom INT UNSIGNED NOT NULL;
diff --git a/resources/sql/autopatches/20160715.event.02.alldayto.sql b/resources/sql/autopatches/20160715.event.02.alldayto.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160715.event.02.alldayto.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_calendar.calendar_event
+ ADD allDayDateTo INT UNSIGNED NOT NULL;
diff --git a/resources/sql/autopatches/20160715.event.03.allday.php b/resources/sql/autopatches/20160715.event.03.allday.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160715.event.03.allday.php
@@ -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());
+}
diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php
--- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php
+++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php
@@ -19,6 +19,8 @@
protected $hostPHID;
protected $dateFrom;
protected $dateTo;
+ protected $allDayDateFrom;
+ protected $allDayDateTo;
protected $description;
protected $isCancelled;
protected $isAllDay;
@@ -62,7 +64,9 @@
$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 @@
$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 @@
->attachInvitees(array())
->setDateFrom($epoch_min)
->setDateTo($epoch_max)
+ ->setAllDayDateFrom($now_min)
+ ->setAllDayDateTo($now_max)
->applyViewerTimezone($actor);
}
@@ -171,9 +181,21 @@
$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 @@
} 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 @@
return $this->getDateTo() - $this->getDateFrom();
}
- private function getDateEpochForTimeZone(
+ public function getDateEpochForTimezone(
$epoch,
$src_zone,
$format,
@@ -295,6 +317,8 @@
'name' => 'text',
'dateFrom' => 'epoch',
'dateTo' => 'epoch',
+ 'allDayDateFrom' => 'epoch',
+ 'allDayDateTo' => 'epoch',
'description' => 'text',
'isCancelled' => 'bool',
'isAllDay' => 'bool',
diff --git a/src/applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php b/src/applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php
--- a/src/applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php
+++ b/src/applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php
@@ -10,7 +10,17 @@
}
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() {
diff --git a/src/applications/calendar/xaction/PhabricatorCalendarEventStartDateTransaction.php b/src/applications/calendar/xaction/PhabricatorCalendarEventStartDateTransaction.php
--- a/src/applications/calendar/xaction/PhabricatorCalendarEventStartDateTransaction.php
+++ b/src/applications/calendar/xaction/PhabricatorCalendarEventStartDateTransaction.php
@@ -10,7 +10,17 @@
}
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() {

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 22, 3:20 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6711391
Default Alt Text
D16305.diff (7 KB)

Event Timeline