Skip to content

Commit 7a9da2d

Browse files
committed
polish/fix: control over 'includeTime' of Date
- introduce new methods for actively including time ('include Time') of a Date Properties within a Notion Page - existing init of value for a Date Property will force a date without time - ::valueWithTime(...) in Date Property and ->setDateTime(...) in Page will force the inclusion of time, if pushed to Notion - ! breaking: result of ::value(...) of Date Property and ->setDate(...) of Page are changing (time will not be included)
1 parent 21e07d4 commit 7a9da2d

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

src/Entities/Page.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,19 @@ public function setDate(string $propertyTitle, DateTime $start, ?DateTime $end =
344344
return $this;
345345
}
346346

347+
/**
348+
* @param $propertyTitle
349+
* @param $start
350+
* @param $end
351+
* @return Page
352+
*/
353+
public function setDateTime(string $propertyTitle, DateTime $start, ?DateTime $end = null): Page
354+
{
355+
$this->set($propertyTitle, Date::valueWithTime($start, $end));
356+
357+
return $this;
358+
}
359+
347360
/**
348361
* @param $propertyTitle
349362
* @param $relationIds

src/Entities/Properties/Date.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ public static function value(?DateTime $start, ?DateTime $end = null): Date
2626
$dateProperty = new Date();
2727
$dateProperty->content = $richDate;
2828

29+
if ($richDate->isRange()) {
30+
$dateProperty->rawContent = [
31+
'date' => [
32+
'start' => $start->format('Y-m-d'),
33+
'end' => $end->format('Y-m-d'),
34+
],
35+
];
36+
} else {
37+
$dateProperty->rawContent = [
38+
'date' => [
39+
'start' => $start->format('Y-m-d'),
40+
],
41+
];
42+
}
43+
44+
return $dateProperty;
45+
}
46+
47+
/**
48+
* @param $start
49+
* @param $end
50+
* @return Date
51+
*/
52+
public static function valueWithTime(?DateTime $start, ?DateTime $end = null): Date
53+
{
54+
$richDate = new RichDate();
55+
$richDate->setStart($start);
56+
$richDate->setEnd($end);
57+
$richDate->setHasTime(true);
58+
59+
$dateProperty = new Date();
60+
$dateProperty->content = $richDate;
61+
2962
if ($richDate->isRange()) {
3063
$dateProperty->rawContent = [
3164
'date' => [

src/Entities/PropertyItems/RichDate.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
*/
1212
class RichDate extends Entity
1313
{
14-
/**
15-
* @var string
16-
*/
1714
protected DateTime $start;
1815
protected ?DateTime $end = null;
16+
protected bool $hasTime = false;
1917

2018
/**
2119
* @param array $responseData
@@ -70,6 +68,14 @@ public function getEnd(): ?DateTime
7068
return $this->end;
7169
}
7270

71+
/**
72+
* @return bool
73+
*/
74+
public function getHasTime(): bool
75+
{
76+
return $this->hasTime;
77+
}
78+
7379
public function setStart($start): void
7480
{
7581
$this->start = $start;
@@ -79,4 +85,9 @@ public function setEnd($end): void
7985
{
8086
$this->end = $end;
8187
}
88+
89+
public function setHasTime($hasTime): void
90+
{
91+
$this->hasTime = $hasTime;
92+
}
8293
}

0 commit comments

Comments
 (0)