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