ILIAS  release_8 Revision v8.24
class.ilADTDate.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5class ilADTDate extends ilADT
6{
7 protected ?ilDateTime $value;
8
9 // definition
10
11 protected function isValidDefinition(ilADTDefinition $a_def): bool
12 {
13 return ($a_def instanceof ilADTDateDefinition);
14 }
15
16 public function reset(): void
17 {
18 parent::reset();
19
20 $this->value = null;
21 }
22
23 public function setDate(?ilDateTime $a_value = null): void
24 {
25 if ($a_value && $a_value->isNull()) {
26 $a_value = null;
27 }
28 $this->value = $a_value;
29 }
30
31 public function getDate(): ?ilDateTime
32 {
33 return $this->value;
34 }
35
36 // comparison
37
38 public function equals(ilADT $a_adt): ?bool
39 {
40 if ($this->getDefinition()->isComparableTo($a_adt)) {
41 if (!$this->isNull() && !$a_adt->isNull()) {
42 // could use checksum...
43 $value = $this->getDate()->get(IL_CAL_UNIX);
44 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
45 return ($value == $other);
46 }
47 }
48 return null;
49 }
50
51 public function isLarger(ilADT $a_adt): ?bool
52 {
53 if ($this->getDefinition()->isComparableTo($a_adt)) {
54 if (!$this->isNull() && !$a_adt->isNull()) {
55 $value = $this->getDate()->get(IL_CAL_UNIX);
56 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
57 return ($value > $other);
58 }
59 }
60 return null;
61 }
62
63 public function isSmaller(ilADT $a_adt): ?bool
64 {
65 if ($this->getDefinition()->isComparableTo($a_adt)) {
66 if (!$this->isNull() && !$a_adt->isNull()) {
67 $value = $this->getDate()->get(IL_CAL_UNIX);
68 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
69 return ($value < $other);
70 }
71 }
72 return null;
73 }
74
75 // null
76
77 public function isNull(): bool
78 {
79 return !$this->value instanceof ilDate || $this->value->isNull();
80 }
81
82 public function getCheckSum(): ?string
83 {
84 if (!$this->isNull()) {
85 return (string) $this->getDate()->get(IL_CAL_UNIX);
86 }
87 return null;
88 }
89
90 // stdClass
91
92 public function exportStdClass(): ?stdClass
93 {
94 if (!$this->isNull()) {
95 $obj = new stdClass();
96 $obj->value = $this->getDate()->get(IL_CAL_UNIX);
97 return $obj;
98 }
99 return null;
100 }
101
102 public function importStdClass(?stdClass $a_std): void
103 {
104 if (is_object($a_std)) {
105 $this->setDate(new ilDate($a_std->value, IL_CAL_UNIX));
106 }
107 }
108}
const IL_CAL_UNIX
getCheckSum()
Get unique checksum.
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
isLarger(ilADT $a_adt)
Check if given ADT is larger than self.
reset()
Init property defaults.
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
setDate(?ilDateTime $a_value=null)
isNull()
Is currently null.
equals(ilADT $a_adt)
Check if given ADT equals self.
importStdClass(?stdClass $a_std)
Import value from stdClass.
ilDateTime $value
exportStdClass()
Export value as stdClass.
ADT definition base class.
ADT base class.
Definition: class.ilADT.php:12
isNull()
Is currently null.
getDefinition()
Get definition.
Definition: class.ilADT.php:92
@classDescription Date and time handling
isNull()
Check if a date is null (Datetime == '0000-00-00 00:00:00', unixtime == 0,...)
Class for single dates.