33namespace Zee \DateRange \States ;
44
55use DateTimeInterface ;
6- use JsonSerializable ;
76
87/**
98 * Interface RangeState.
109 */
11- interface RangeState extends JsonSerializable
10+ abstract class RangeState
1211{
13- /**
14- * Returns string representation of range.
15- *
16- * @return string
17- */
18- public function __toString (): string ;
19-
20- /**
21- * {@inheritdoc}
22- */
23- public function jsonSerialize (): array ;
24-
2512 /**
2613 * @return bool
2714 */
28- public function hasStartTime (): bool ;
15+ public function hasStartTime (): bool
16+ {
17+ return false ;
18+ }
2919
3020 /**
3121 * @return bool
3222 */
33- public function hasEndTime (): bool ;
23+ public function hasEndTime (): bool
24+ {
25+ return false ;
26+ }
3427
3528 /**
3629 * @return DateTimeInterface
3730 */
38- public function getStartTime (): DateTimeInterface ;
31+ abstract public function getStartTime (): DateTimeInterface ;
3932
4033 /**
4134 * @return DateTimeInterface
4235 */
43- public function getEndTime (): DateTimeInterface ;
36+ abstract public function getEndTime (): DateTimeInterface ;
4437
4538 /**
4639 * @param DateTimeInterface $time
4740 *
4841 * @return RangeState
4942 */
50- public function setStartTime (DateTimeInterface $ time ): RangeState ;
43+ abstract public function setStartTime (DateTimeInterface $ time ): RangeState ;
5144
5245 /**
5346 * @param DateTimeInterface $time
5447 *
5548 * @return RangeState
5649 */
57- public function setEndTime (DateTimeInterface $ time ): RangeState ;
50+ abstract public function setEndTime (DateTimeInterface $ time ): RangeState ;
5851
5952 /**
6053 * Compares start time with specific time.
@@ -66,7 +59,10 @@ public function setEndTime(DateTimeInterface $time): RangeState;
6659 *
6760 * @return int
6861 */
69- public function compareStartTime (DateTimeInterface $ time ): int ;
62+ public function compareStartTime (DateTimeInterface $ time ): int
63+ {
64+ return $ this ->getStartTime ()->getTimestamp () <=> $ time ->getTimestamp ();
65+ }
7066
7167 /**
7268 * Compares end time with specific time.
@@ -78,5 +74,28 @@ public function compareStartTime(DateTimeInterface $time): int;
7874 *
7975 * @return int
8076 */
81- public function compareEndTime (DateTimeInterface $ time ): int ;
77+ public function compareEndTime (DateTimeInterface $ time ): int
78+ {
79+ return $ this ->getEndTime ()->getTimestamp () <=> $ time ->getTimestamp ();
80+ }
81+
82+ /**
83+ * @param string $format
84+ *
85+ * @return null|string
86+ */
87+ public function formatStartTime (string $ format = 'c ' ): ?string
88+ {
89+ return $ this ->getStartTime ()->format ($ format );
90+ }
91+
92+ /**
93+ * @param string $format
94+ *
95+ * @return null|string
96+ */
97+ public function formatEndTime (string $ format = 'c ' ): ?string
98+ {
99+ return $ this ->getEndTime ()->format ($ format );
100+ }
82101}
0 commit comments