ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTDateTime.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 class 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 }
importStdClass(?stdClass $a_std)
equals(ilADT $a_adt)
setDate(ilDateTime $a_value=null)
const IL_CAL_UNIX
ADT base class.
Definition: class.ilADT.php:11
isSmaller(ilADT $a_adt)
isNull()
Is currently null.
isLarger(ilADT $a_adt)
isValidDefinition(ilADTDefinition $a_def)
ADT definition base class.
getDefinition()
Get definition.
Definition: class.ilADT.php:92