ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
29 $a_value = null;
30 }
31 $this->value = $a_value;
32 }
33
34 public function getDate()
35 {
36 return $this->value;
37 }
38
39
40 // comparison
41
42 public function equals(ilADT $a_adt)
43 {
44 if($this->getDefinition()->isComparableTo($a_adt))
45 {
46 if(!$this->isNull() && !$a_adt->isNull())
47 {
48 // could use checksum...
49 $value = $this->getDate()->get(IL_CAL_UNIX);
50 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
51 return ($value == $other);
52 }
53 }
54 // null?
55 }
56
57 public function isLarger(ilADT $a_adt)
58 {
59 if($this->getDefinition()->isComparableTo($a_adt))
60 {
61 if(!$this->isNull() && !$a_adt->isNull())
62 {
63 $value = $this->getDate()->get(IL_CAL_UNIX);
64 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
65 return ($value > $other);
66 }
67 }
68 }
69
70 public function isSmaller(ilADT $a_adt)
71 {
72 if($this->getDefinition()->isComparableTo($a_adt))
73 {
74 if(!$this->isNull() && !$a_adt->isNull())
75 {
76 $value = $this->getDate()->get(IL_CAL_UNIX);
77 $other = $a_adt->getDate()->get(IL_CAL_UNIX);
78 return ($value < $other);
79 }
80 }
81 }
82
83
84 // null
85
86 public function isNull()
87 {
88 return (!($this->value instanceof ilDate) || $this->value->isNull());
89 }
90
91
92 // validation
93
94 public function isValid()
95 {
96 $valid = parent::isValid();
97
98 /* timestamp is "always" valid
99 if(!$this->isNull())
100 {
101 $value = getdate($this->getDate()->get(IL_CAL_UNIX));
102 if(!checkdate($value["mon"], $value["mday"], $value["year"]))
103 {
104 $valid = false;
105 $this->addValidationError(self::ADT_VALIDATION_DATE);
106 }
107 }
108 */
109
110 return $valid;
111 }
112
113
114 // check
115
116 public function getCheckSum()
117 {
118 if(!$this->isNull())
119 {
120 return (string)$this->getDate()->get(IL_CAL_UNIX);
121 }
122 }
123}
124
125?>
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:99
@classDescription Date and time handling
Class for single dates.
$valid