ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTDate.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21class ilADTDate extends ilADT
22{
23 protected ?ilDateTime $value;
24
25 // definition
26
27 protected function isValidDefinition(ilADTDefinition $a_def): bool
28 {
29 return ($a_def instanceof ilADTDateDefinition);
30 }
31
32 public function reset(): void
33 {
34 parent::reset();
35
36 $this->value = null;
37 }
38
39 public function setDate(?ilDateTime $a_value = null): void
40 {
41 if ($a_value && $a_value->isNull()) {
42 $a_value = null;
43 }
44 $this->value = $a_value;
45 }
46
47 public function getDate(): ?ilDateTime
48 {
49 return $this->value;
50 }
51
52 // comparison
53
54 public function equals(ilADT $a_adt): ?bool
55 {
56 if ($this->getDefinition()->isComparableTo($a_adt)) {
57 if (!$this->isNull() && !$a_adt->isNull()) {
58 // could use checksum...
59 $value = $this->getDate()->get(IL_CAL_UNIX);
60 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
61 return ($value == $other);
62 }
63 }
64 return null;
65 }
66
67 public function isLarger(ilADT $a_adt): ?bool
68 {
69 if ($this->getDefinition()->isComparableTo($a_adt)) {
70 if (!$this->isNull() && !$a_adt->isNull()) {
71 $value = $this->getDate()->get(IL_CAL_UNIX);
72 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
73 return ($value > $other);
74 }
75 }
76 return null;
77 }
78
79 public function isSmaller(ilADT $a_adt): ?bool
80 {
81 if ($this->getDefinition()->isComparableTo($a_adt)) {
82 if (!$this->isNull() && !$a_adt->isNull()) {
83 $value = $this->getDate()->get(IL_CAL_UNIX);
84 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
85 return ($value < $other);
86 }
87 }
88 return null;
89 }
90
91 // null
92
93 public function isNull(): bool
94 {
95 return !$this->value instanceof ilDate || $this->value->isNull();
96 }
97
98 public function getCheckSum(): ?string
99 {
100 if (!$this->isNull()) {
101 return (string) $this->getDate()->get(IL_CAL_UNIX);
102 }
103 return null;
104 }
105
106 // stdClass
107
108 public function exportStdClass(): ?stdClass
109 {
110 if (!$this->isNull()) {
111 $obj = new stdClass();
112 $obj->value = $this->getDate()->get(IL_CAL_UNIX);
113 return $obj;
114 }
115 return null;
116 }
117
118 public function importStdClass(?stdClass $a_std): void
119 {
120 if (is_object($a_std)) {
121 $this->setDate(new ilDate($a_std->value, IL_CAL_UNIX));
122 }
123 }
124}
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:26
isNull()
Is currently null.
getDefinition()
Get definition.
@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.