Debian Codegraph @

vendor/ipl/scheduler/src/Contract/Frequency.php

raw
1 <?php
2
3 namespace ipl\Scheduler\Contract;
4
5 use DateTimeInterface;
6 use JsonSerializable;
7
8 /**
9 * Contract for a scheduling frequency
10 *
11 * A frequency determines when a task is due to run, what the next run time is,
12 * whether it has expired, and its optional start and end bounds.
13 * Implementations must also support round-trip JSON serialization via
14 * {@see Frequency::fromJson()} and {@see JsonSerializable::jsonSerialize()}.
15 */
16 interface Frequency extends JsonSerializable
17 {
18 /** @var string Format for representing datetimes when serializing the frequency to JSON */
19 public const SERIALIZED_DATETIME_FORMAT = 'Y-m-d\TH:i:s.ue';
20
21 /**
22 * Create a frequency from its stored JSON representation
23 *
24 * The representation must have been encoded with {@see json_encode()}.
25 *
26 * @param string $json
27 *
28 * @return $this
29 */
30 public static function fromJson(string $json): static;
31
32 /**
33 * Get whether the frequency is due at the specified time
34 *
35 * @param DateTimeInterface $dateTime
36 *
37 * @return bool
38 */
39 public function isDue(DateTimeInterface $dateTime): bool;
40
41 /**
42 * Get the next due date relative to the given time
43 *
44 * @param DateTimeInterface $dateTime
45 *
46 * @return DateTimeInterface
47 */
48 public function getNextDue(DateTimeInterface $dateTime): DateTimeInterface;
49
50 /**
51 * Get whether the specified time is beyond the frequency's expiry time
52 *
53 * @param DateTimeInterface $dateTime
54 *
55 * @return bool
56 */
57 public function isExpired(DateTimeInterface $dateTime): bool;
58
59 /**
60 * Get the start time of this frequency
61 *
62 * @return ?DateTimeInterface
63 */
64 public function getStart(): ?DateTimeInterface;
65
66 /**
67 * Get the end time of this frequency
68 *
69 * @return ?DateTimeInterface
70 */
71 public function getEnd(): ?DateTimeInterface;
72 }