ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilDatePresentation.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once('./Services/Calendar/classes/class.ilDate.php');
25include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
26
36{
37 public static $use_relative_dates = true;
38 private static $lang = null;
39
40 public static $today = null;
41 public static $tomorrow = null;
42 public static $yesterday = null;
43
50 public static function setUseRelativeDates($a_status)
51 {
52 self::$use_relative_dates = $a_status;
53 }
54
61 public static function useRelativeDates()
62 {
64 }
65
72 public static function setLanguage($a_lng)
73 {
74 self::$lang = $a_lng;
75 }
76
83 public static function getLanguage()
84 {
85 global $lng;
86
87 return self::$lang ? self::$lang : $lng;
88 }
89
96 public static function resetToDefaults()
97 {
98 global $lng;
99
102 }
103
104
105
113 public static function formatDate(ilDateTime $date)
114 {
115 global $lng,$ilUser;
116
117 if($date->isNull())
118 {
119 return self::getLanguage()->txt('no_date');
120 }
121
122 $has_time = !is_a($date,'ilDate');
123
124 // Converting pure dates to user timezone might return wrong dates
125 if($has_time)
126 {
127 $date_info = $date->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
128 }
129 else
130 {
131 $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
132 }
133
134
135 if(self::isToday($date) and self::useRelativeDates())
136 {
137 $date_str = self::getLanguage()->txt('today');
138 }
139 elseif(self::isTomorrow($date) and self::useRelativeDates())
140 {
141 $date_str = self::getLanguage()->txt('tomorrow');
142 }
143 elseif(self::isYesterday($date) and self::useRelativeDates())
144 {
145 $date_str = self::getLanguage()->txt('yesterday');
146 }
147 else
148 {
149 include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
150 $date_str = $date->get(IL_CAL_FKT_DATE,'d').'. '.
151 ilCalendarUtil::_numericMonthToString($date_info['mon'],false).' '.
152 $date_info['year'];
153 }
154
155 if(!$has_time)
156 {
157 return $date_str;
158 }
159
160 switch($ilUser->getTimeFormat())
161 {
163 return $date_str.', '.$date->get(IL_CAL_FKT_DATE,'H:i',$ilUser->getTimeZone());
164
166 return $date_str.', '.$date->get(IL_CAL_FKT_DATE,'g:ia',$ilUser->getTimeZone());
167 }
168 }
169
182 public static function formatPeriod(ilDateTime $start,ilDateTime $end)
183 {
184 global $ilUser;
185
186 $has_time = !is_a($start,'ilDate');
187
188 // Same day
189 if(ilDateTime::_equals($start,$end,IL_CAL_DAY,$ilUser->getTimeZone()))
190 {
191 if(!$has_time)
192 {
193 return self::formatDate($start);
194 }
195 else
196 {
197 $date_str = self::formatDate(
198 new ilDate($start->get(IL_CAL_DATE,'',$ilUser->getTimeZone()),IL_CAL_DATE));
199
200 // $start == $end
201 if(ilDateTime::_equals($start,$end))
202 {
203 switch($ilUser->getTimeFormat())
204 {
206 return $date_str.', '.$start->get(IL_CAL_FKT_DATE,'H:i',$ilUser->getTimeZone());
207
209 return $date_str.', '.$start->get(IL_CAL_FKT_DATE,'h:i a',$ilUser->getTimeZone());
210 }
211 }
212 else
213 {
214 switch($ilUser->getTimeFormat())
215 {
217 return $date_str.', '.$start->get(IL_CAL_FKT_DATE,'H:i',$ilUser->getTimeZone()).' - '.
218 $end->get(IL_CAL_FKT_DATE,'H:i',$ilUser->getTimeZone());
219
221 return $date_str.', '.$start->get(IL_CAL_FKT_DATE,'g:ia',$ilUser->getTimeZone()).' - '.
222 $end->get(IL_CAL_FKT_DATE,'g:ia',$ilUser->getTimeZone());
223 }
224 }
225 }
226 }
227 // Different days
228 return self::formatDate($start).' - '.self::formatDate($end);
229 }
230
231
232
241 public static function isToday(ilDateTime $date)
242 {
243 global $ilUser;
244
245 if(!is_object(self::$today))
246 {
247 self::$today = new ilDateTime(time(),IL_CAL_UNIX,$ilUser->getTimeZone());
248 }
249 return ilDateTime::_equals(self::$today,$date,IL_CAL_DAY,$ilUser->getTimeZone());
250 }
251
260 public static function isYesterday(ilDateTime $date)
261 {
262 global $ilUser;
263
264 if(!is_object(self::$yesterday))
265 {
266 self::$yesterday = new ilDateTime(time(),IL_CAL_UNIX,$ilUser->getTimeZone());
267 self::$yesterday->increment(IL_CAL_DAY,-1);
268 }
269
270 return ilDateTime::_equals(self::$yesterday,$date,IL_CAL_DAY,$ilUser->getTimeZone());
271 }
272
281 public static function isTomorrow(ilDateTime $date)
282 {
283 global $ilUser;
284
285 if(!is_object(self::$tomorrow))
286 {
287 self::$tomorrow = new ilDateTime(time(),IL_CAL_UNIX,$ilUser->getTimeZone());
288 self::$tomorrow->increment(IL_CAL_DAY,1);
289 }
290
291 return ilDateTime::_equals(self::$tomorrow,$date,IL_CAL_DAY,$ilUser->getTimeZone());
292 }
293
294}
295?>
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_FKT_DATE
const IL_CAL_DAY
static _numericMonthToString($a_month, $a_long=true)
numeric month to string
Class for date presentation.
static isTomorrow(ilDateTime $date)
Check if date is tomorrow.
static isYesterday(ilDateTime $date)
Check if date is yesterday.
static getLanguage()
set language
static resetToDefaults()
reset to defaults
static setLanguage($a_lng)
set language
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
static useRelativeDates()
check if relative dates are used
static isToday(ilDateTime $date)
Check if date is "today".
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
get($a_format, $a_format_str='', $a_tz='')
get formatted date
isNull()
Check if a date is null (Datetime == '0000-00-00 00:00:00', unixtime == 0,...)
Class for single dates.
global $lng
Definition: privfeed.php:40
global $ilUser
Definition: imgupload.php:15