diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-10-19 21:56:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-19 21:56:27 +0300 |
commit | d93b4315541f457421170857ea1e10a29f9a5053 (patch) | |
tree | ab4ad6f26a4e64629a0d5fcd05ea323a3f0e3d2a | |
parent | 857a0797b485b551b67f62a1ed2c1de3b5f8ba7c (diff) | |
parent | d00bd159d2a28c01bca8f60ae7aed7d984c7d18d (diff) |
Merge pull request #4115 from nextcloud/bugfix/4112/fix-duedate-format
-rw-r--r-- | lib/Db/Card.php | 18 | ||||
-rw-r--r-- | lib/Db/RelationalEntity.php | 3 | ||||
-rw-r--r-- | lib/Model/CardDetails.php | 2 | ||||
-rw-r--r-- | lib/Notification/NotificationHelper.php | 4 | ||||
-rw-r--r-- | lib/Service/CardService.php | 4 | ||||
-rw-r--r-- | tests/unit/Db/CardTest.php | 8 | ||||
-rw-r--r-- | tests/unit/Service/CardServiceTest.php | 2 |
7 files changed, 11 insertions, 30 deletions
diff --git a/lib/Db/Card.php b/lib/Db/Card.php index 674ee8f8..ed710d71 100644 --- a/lib/Db/Card.php +++ b/lib/Db/Card.php @@ -108,7 +108,7 @@ class Card extends RelationalEntity { $this->addType('archived', 'boolean'); $this->addType('notified', 'boolean'); $this->addType('deletedAt', 'integer'); - $this->addType('duedate', 'string'); + $this->addType('duedate', 'datetime'); $this->addRelation('labels'); $this->addRelation('assignedUsers'); $this->addRelation('attachments'); @@ -126,20 +126,6 @@ class Card extends RelationalEntity { $this->databaseType = $type; } - public function getDueDateTime(): ?DateTime { - return $this->duedate ? new DateTime($this->duedate) : null; - } - - public function getDuedate($isoFormat = false): ?string { - $dt = $this->getDueDateTime(); - $format = 'c'; - if (!$isoFormat && $this->databaseType === 'mysql') { - $format = 'Y-m-d H:i:s'; - } - - return $dt ? $dt->format($format) : null; - } - public function getCalendarObject(): VCalendar { $calendar = new VCalendar(); $event = $calendar->createComponent('VTODO'); @@ -148,7 +134,7 @@ class Card extends RelationalEntity { $creationDate = new DateTime(); $creationDate->setTimestamp($this->createdAt); $event->DTSTAMP = $creationDate; - $event->DUE = new DateTime($this->getDuedate(true), new DateTimeZone('UTC')); + $event->DUE = new DateTime($this->getDuedate()->format('c'), new DateTimeZone('UTC')); } $event->add('RELATED-TO', 'deck-stack-' . $this->getStackId()); diff --git a/lib/Db/RelationalEntity.php b/lib/Db/RelationalEntity.php index 6e2a19ef..8ac6ef45 100644 --- a/lib/Db/RelationalEntity.php +++ b/lib/Db/RelationalEntity.php @@ -72,6 +72,9 @@ class RelationalEntity extends Entity implements \JsonSerializable { $propertyReflection = $reflection->getProperty($property); if (!$propertyReflection->isPrivate() && !in_array($property, $this->_resolvedProperties, true)) { $json[$property] = $this->getter($property); + if ($json[$property] instanceof \DateTimeInterface) { + $json[$property] = $json[$property]->format('c'); + } } } } diff --git a/lib/Model/CardDetails.php b/lib/Model/CardDetails.php index 6c51ef84..58523ab1 100644 --- a/lib/Model/CardDetails.php +++ b/lib/Model/CardDetails.php @@ -54,7 +54,7 @@ class CardDetails extends Card { $today = new DateTime(); $today->setTime(0, 0); - $match_date = $this->card->getDueDateTime(); + $match_date = $this->card->getDuedate(); if (!$match_date) { return Card::DUEDATE_FUTURE; } diff --git a/lib/Notification/NotificationHelper.php b/lib/Notification/NotificationHelper.php index 97b900c7..0105c03f 100644 --- a/lib/Notification/NotificationHelper.php +++ b/lib/Notification/NotificationHelper.php @@ -129,7 +129,7 @@ class NotificationHelper { ->setSubject('card-overdue', [ $card->getTitle(), $board->getTitle() ]) - ->setDateTime(new DateTime($card->getDuedate())); + ->setDateTime($card->getDuedate()); $this->notificationManager->notify($notification); } } @@ -242,7 +242,7 @@ class NotificationHelper { } return $this->boards[$boardId]; } - + private function generateBoardShared(Board $board, string $userId): INotification { $notification = $this->notificationManager->createNotification(); $notification diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 6ee4cf08..af0eb010 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -337,11 +337,11 @@ class CardService { $card->setType($type); $card->setOrder($order); $card->setOwner($owner); - $card->setDuedate($duedate); + $card->setDuedate($duedate ? new \DateTime($duedate) : null); $resetDuedateNotification = false; if ( $card->getDuedate() === null || - (new \DateTime($card->getDuedate())) != (new \DateTime($changes->getBefore()->getDuedate() ?? '')) + ($card->getDuedate()) != ($changes->getBefore()->getDuedate()) ) { $card->setNotified(false); $resetDuedateNotification = true; diff --git a/tests/unit/Db/CardTest.php b/tests/unit/Db/CardTest.php index 15c5c9f5..a32fa3c0 100644 --- a/tests/unit/Db/CardTest.php +++ b/tests/unit/Db/CardTest.php @@ -117,14 +117,6 @@ class CardTest extends TestCase { ], (new CardDetails($card))->jsonSerialize()); } - public function testMysqlDateFallback() { - $date = new DateTime(); - $card = new Card(); - $card->setDuedate($date->format('c')); - $card->setDatabaseType('mysql'); - $this->assertEquals($date->format('Y-m-d H:i:s'), $card->getDuedate(false)); - } - public function testJsonSerializeAsignedUsers() { $card = $this->createCard(); $card->setAssignedUsers([ 'user1' ]); diff --git a/tests/unit/Service/CardServiceTest.php b/tests/unit/Service/CardServiceTest.php index dd18e67e..982c9614 100644 --- a/tests/unit/Service/CardServiceTest.php +++ b/tests/unit/Service/CardServiceTest.php @@ -221,7 +221,7 @@ class CardServiceTest extends TestCase { $this->assertEquals('text', $actual->getType()); $this->assertEquals(999, $actual->getOrder()); $this->assertEquals('foo', $actual->getDescription()); - $this->assertEquals('2017-01-01T00:00:00+00:00', $actual->getDuedate()); + $this->assertEquals(new \DateTime('2017-01-01T00:00:00+00:00'), $actual->getDuedate()); } public function testUpdateArchived() { |