ILIAS  release_8 Revision v8.24
class.ilADTDateTime.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5class ilADTDateTime 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 ilADTDateTimeDefinition;
14 }
15
16 public function reset(): void
17 {
18 parent::reset();
19 $this->value = null;
20 }
21
22 // properties
23
24 public function setDate(ilDateTime $a_value = null)
25 {
26 if ($a_value && $a_value->isNull()) {
27 $a_value = null;
28 }
29 $this->value = $a_value;
30 }
31
32 public function getDate(): ?ilDateTime
33 {
34 return $this->value;
35 }
36
37 // comparison
38
39 public function equals(ilADT $a_adt): ?bool
40 {
41 if ($this->getDefinition()->isComparableTo($a_adt)) {
42 if (!$this->isNull() && !$a_adt->isNull()) {
43 // could use checksum...
44 $value = $this->getDate()->get(IL_CAL_UNIX);
45 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
46 return ($value == $other);
47 }
48 }
49 return null;
50 }
51
52 public function isLarger(ilADT $a_adt): ?bool
53 {
54 if ($this->getDefinition()->isComparableTo($a_adt)) {
55 if (!$this->isNull() && !$a_adt->isNull()) {
56 $value = $this->getDate()->get(IL_CAL_UNIX);
57 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
58 return ($value > $other);
59 }
60 }
61 return null;
62 }
63
64 public function isSmaller(ilADT $a_adt): ?bool
65 {
66 if ($this->getDefinition()->isComparableTo($a_adt)) {
67 if (!$this->isNull() && !$a_adt->isNull()) {
68 $value = $this->getDate()->get(IL_CAL_UNIX);
69 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
70 return ($value < $other);
71 }
72 }
73 return null;
74 }
75
76 // null
77
78 public function isNull(): bool
79 {
80 return !$this->value instanceof ilDateTime || $this->value->isNull();
81 }
82
83 public function getCheckSum(): ?string
84 {
85 if (!$this->isNull()) {
86 return (string) $this->getDate()->get(IL_CAL_UNIX);
87 }
88 return null;
89 }
90
91 // stdClass
92
93 public function exportStdClass(): ?stdClass
94 {
95 if (!$this->isNull()) {
96 $obj = new stdClass();
97 $obj->value = $this->getDate()->get(IL_CAL_UNIX);
98 return $obj;
99 }
100 return null;
101 }
102
103 public function importStdClass(?stdClass $a_std): void
104 {
105 if (is_object($a_std)) {
106 $this->setDate(new ilDateTime($a_std->value, IL_CAL_UNIX));
107 }
108 }
109}
const IL_CAL_UNIX
setDate(ilDateTime $a_value=null)
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.
reset()
Init property defaults.
isNull()
Is currently null.
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,...)