ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilADTDate.php
Go to the documentation of this file.
1<?php
2
3class ilADTDate extends ilADT
4{
5 protected $value; // [ilDateTime]
6
7
8 // definition
9
10 protected function isValidDefinition(ilADTDefinition $a_def)
11 {
12 return ($a_def instanceof ilADTDateDefinition);
13 }
14
15 public function reset()
16 {
17 parent::reset();
18
19 $this->value = null;
20 }
21
22
23 // properties
24
25 public function setDate(ilDateTime $a_value = null)
26 {
27 if ($a_value && $a_value->isNull()) {
28 $a_value = null;
29 }
30 $this->value = $a_value;
31 }
32
33 public function getDate()
34 {
35 return $this->value;
36 }
37
38
39 // comparison
40
41 public function equals(ilADT $a_adt)
42 {
43 if ($this->getDefinition()->isComparableTo($a_adt)) {
44 if (!$this->isNull() && !$a_adt->isNull()) {
45 // could use checksum...
46 $value = $this->getDate()->get(IL_CAL_UNIX);
47 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
48 return ($value == $other);
49 }
50 }
51 // null?
52 }
53
54 public function isLarger(ilADT $a_adt)
55 {
56 if ($this->getDefinition()->isComparableTo($a_adt)) {
57 if (!$this->isNull() && !$a_adt->isNull()) {
58 $value = $this->getDate()->get(IL_CAL_UNIX);
59 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
60 return ($value > $other);
61 }
62 }
63 }
64
65 public function isSmaller(ilADT $a_adt)
66 {
67 if ($this->getDefinition()->isComparableTo($a_adt)) {
68 if (!$this->isNull() && !$a_adt->isNull()) {
69 $value = $this->getDate()->get(IL_CAL_UNIX);
70 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
71 return ($value < $other);
72 }
73 }
74 }
75
76
77 // null
78
79 public function isNull()
80 {
81 return (!($this->value instanceof ilDate) || $this->value->isNull());
82 }
83
84
85 // validation
86
87 public function isValid()
88 {
89 $valid = parent::isValid();
90
91 /* timestamp is "always" valid
92 if(!$this->isNull())
93 {
94 $value = getdate($this->getDate()->get(IL_CAL_UNIX));
95 if(!checkdate($value["mon"], $value["mday"], $value["year"]))
96 {
97 $valid = false;
98 $this->addValidationError(self::ADT_VALIDATION_DATE);
99 }
100 }
101 */
102
103 return $valid;
104 }
105
106
107 // check
108
109 public function getCheckSum()
110 {
111 if (!$this->isNull()) {
112 return (string) $this->getDate()->get(IL_CAL_UNIX);
113 }
114 }
115}
An exception for terminatinating execution or to throw for unit testing.
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.
setDate(ilDateTime $a_value=null)
reset()
Init property defaults.
isValid()
Is currently valid.
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
isNull()
Is currently null.
equals(ilADT $a_adt)
Check if given ADT equals self.
ADT definition base class.
ADT base class.
Definition: class.ilADT.php:12
isNull()
Is currently null.
getDefinition()
Get definition.
Definition: class.ilADT.php:97
@classDescription Date and time handling
Class for single dates.
$valid