blob: 095e460a9e1a6c91d826ab11576f7d5eda1cbae5 [file] [log] [blame]
Derek Jones0b59f272008-05-13 04:22:33 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard83894872007-03-13 20:51:52 +00002/**
Derek Allardd2df9bc2007-04-15 17:41:17 +00003 * CodeIgniter
Derek Allard83894872007-03-13 20:51:52 +00004 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allard83894872007-03-13 20:51:52 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
Derek Allardd2df9bc2007-04-15 17:41:17 +000019 * CodeIgniter Date Helpers
Derek Allard83894872007-03-13 20:51:52 +000020 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/date_helper.html
Derek Allard83894872007-03-13 20:51:52 +000026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Get "now" time
32 *
33 * Returns time() or its GMT equivalent based on the config file preference
34 *
35 * @access public
36 * @return integer
37 */
Derek Jones0b59f272008-05-13 04:22:33 +000038if ( ! function_exists('now'))
Derek Allard83894872007-03-13 20:51:52 +000039{
Derek Jones269b9422008-01-28 21:00:20 +000040 function now()
Derek Allard83894872007-03-13 20:51:52 +000041 {
Derek Jones269b9422008-01-28 21:00:20 +000042 $CI =& get_instance();
Derek Allard83894872007-03-13 20:51:52 +000043
Derek Jones269b9422008-01-28 21:00:20 +000044 if (strtolower($CI->config->item('time_reference')) == 'gmt')
Derek Allard83894872007-03-13 20:51:52 +000045 {
Derek Jones269b9422008-01-28 21:00:20 +000046 $now = time();
47 $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now));
Derek Allard83894872007-03-13 20:51:52 +000048
Derek Jones269b9422008-01-28 21:00:20 +000049 if (strlen($system_time) < 10)
50 {
51 $system_time = time();
52 log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.');
53 }
54
55 return $system_time;
56 }
57 else
58 {
59 return time();
60 }
Derek Allard83894872007-03-13 20:51:52 +000061 }
62}
63
64// ------------------------------------------------------------------------
65
66/**
67 * Convert MySQL Style Datecodes
68 *
69 * This function is identical to PHPs date() function,
70 * except that it allows date codes to be formatted using
71 * the MySQL style, where each code letter is preceded
72 * with a percent sign: %Y %m %d etc...
73 *
74 * The benefit of doing dates this way is that you don't
75 * have to worry about escaping your text letters that
76 * match the date codes.
77 *
78 * @access public
79 * @param string
80 * @param integer
81 * @return integer
82 */
Derek Jones0b59f272008-05-13 04:22:33 +000083if ( ! function_exists('mdate'))
Derek Allard83894872007-03-13 20:51:52 +000084{
Derek Jones269b9422008-01-28 21:00:20 +000085 function mdate($datestr = '', $time = '')
86 {
87 if ($datestr == '')
88 return '';
Derek Allard83894872007-03-13 20:51:52 +000089
Derek Jones269b9422008-01-28 21:00:20 +000090 if ($time == '')
91 $time = now();
Derek Allard83894872007-03-13 20:51:52 +000092
Derek Jones269b9422008-01-28 21:00:20 +000093 $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr));
94 return date($datestr, $time);
95 }
Derek Allard83894872007-03-13 20:51:52 +000096}
97
98// ------------------------------------------------------------------------
99
100/**
101 * Standard Date
102 *
103 * Returns a date formatted according to the submitted standard.
104 *
105 * @access public
106 * @param string the chosen format
107 * @param integer Unix timestamp
108 * @return string
109 */
Derek Jones0b59f272008-05-13 04:22:33 +0000110if ( ! function_exists('standard_date'))
Derek Allard83894872007-03-13 20:51:52 +0000111{
Derek Jones269b9422008-01-28 21:00:20 +0000112 function standard_date($fmt = 'DATE_RFC822', $time = '')
Derek Allard83894872007-03-13 20:51:52 +0000113 {
Derek Jones269b9422008-01-28 21:00:20 +0000114 $formats = array(
115 'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%Q',
116 'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC',
117 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%O',
118 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O',
119 'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i UTC',
120 'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O',
121 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O',
122 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O',
123 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q'
124 );
Derek Allard83894872007-03-13 20:51:52 +0000125
Derek Jones0b59f272008-05-13 04:22:33 +0000126 if ( ! isset($formats[$fmt]))
Derek Jones269b9422008-01-28 21:00:20 +0000127 {
128 return FALSE;
129 }
130
131 return mdate($formats[$fmt], $time);
132 }
133}
Derek Allard83894872007-03-13 20:51:52 +0000134
135// ------------------------------------------------------------------------
136
137/**
138 * Timespan
139 *
140 * Returns a span of seconds in this format:
141 * 10 days 14 hours 36 minutes 47 seconds
142 *
143 * @access public
144 * @param integer a number of seconds
145 * @param integer Unix timestamp
146 * @return integer
147 */
Derek Jones0b59f272008-05-13 04:22:33 +0000148if ( ! function_exists('timespan'))
Derek Allard83894872007-03-13 20:51:52 +0000149{
Derek Jones269b9422008-01-28 21:00:20 +0000150 function timespan($seconds = 1, $time = '')
151 {
152 $CI =& get_instance();
153 $CI->lang->load('date');
Derek Allard83894872007-03-13 20:51:52 +0000154
Derek Jones0b59f272008-05-13 04:22:33 +0000155 if ( ! is_numeric($seconds))
Derek Jones269b9422008-01-28 21:00:20 +0000156 {
157 $seconds = 1;
158 }
Derek Allard83894872007-03-13 20:51:52 +0000159
Derek Jones0b59f272008-05-13 04:22:33 +0000160 if ( ! is_numeric($time))
Derek Jones269b9422008-01-28 21:00:20 +0000161 {
162 $time = time();
163 }
Derek Allard83894872007-03-13 20:51:52 +0000164
Derek Jones269b9422008-01-28 21:00:20 +0000165 if ($time <= $seconds)
166 {
167 $seconds = 1;
168 }
169 else
170 {
171 $seconds = $time - $seconds;
172 }
Derek Allard83894872007-03-13 20:51:52 +0000173
Derek Jones269b9422008-01-28 21:00:20 +0000174 $str = '';
175 $years = floor($seconds / 31536000);
Derek Allard83894872007-03-13 20:51:52 +0000176
Derek Jones269b9422008-01-28 21:00:20 +0000177 if ($years > 0)
Derek Allard83894872007-03-13 20:51:52 +0000178 {
Derek Jones269b9422008-01-28 21:00:20 +0000179 $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', ';
Derek Allard83894872007-03-13 20:51:52 +0000180 }
181
Derek Jones269b9422008-01-28 21:00:20 +0000182 $seconds -= $years * 31536000;
183 $months = floor($seconds / 2628000);
Derek Allard83894872007-03-13 20:51:52 +0000184
Derek Jones269b9422008-01-28 21:00:20 +0000185 if ($years > 0 OR $months > 0)
Derek Allard83894872007-03-13 20:51:52 +0000186 {
Derek Jones269b9422008-01-28 21:00:20 +0000187 if ($months > 0)
188 {
189 $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', ';
190 }
191
192 $seconds -= $months * 2628000;
Derek Allard83894872007-03-13 20:51:52 +0000193 }
Derek Jones269b9422008-01-28 21:00:20 +0000194
195 $weeks = floor($seconds / 604800);
196
197 if ($years > 0 OR $months > 0 OR $weeks > 0)
198 {
199 if ($weeks > 0)
200 {
201 $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', ';
202 }
Derek Allard83894872007-03-13 20:51:52 +0000203
Derek Jones269b9422008-01-28 21:00:20 +0000204 $seconds -= $weeks * 604800;
205 }
206
207 $days = floor($seconds / 86400);
Derek Allard83894872007-03-13 20:51:52 +0000208
Derek Jones269b9422008-01-28 21:00:20 +0000209 if ($months > 0 OR $weeks > 0 OR $days > 0)
210 {
211 if ($days > 0)
212 {
213 $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', ';
214 }
Derek Allard83894872007-03-13 20:51:52 +0000215
Derek Jones269b9422008-01-28 21:00:20 +0000216 $seconds -= $days * 86400;
Derek Allard83894872007-03-13 20:51:52 +0000217 }
Derek Allard83894872007-03-13 20:51:52 +0000218
Derek Jones269b9422008-01-28 21:00:20 +0000219 $hours = floor($seconds / 3600);
220
221 if ($days > 0 OR $hours > 0)
222 {
223 if ($hours > 0)
224 {
225 $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', ';
226 }
227
228 $seconds -= $hours * 3600;
229 }
230
231 $minutes = floor($seconds / 60);
232
233 if ($days > 0 OR $hours > 0 OR $minutes > 0)
234 {
235 if ($minutes > 0)
236 {
237 $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', ';
238 }
239
240 $seconds -= $minutes * 60;
241 }
242
243 if ($str == '')
244 {
245 $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', ';
246 }
Derek Allard83894872007-03-13 20:51:52 +0000247
Derek Jones269b9422008-01-28 21:00:20 +0000248 return substr(trim($str), 0, -1);
249 }
Derek Allard83894872007-03-13 20:51:52 +0000250}
251
252// ------------------------------------------------------------------------
253
254/**
255 * Number of days in a month
256 *
257 * Takes a month/year as input and returns the number of days
258 * for the given month/year. Takes leap years into consideration.
259 *
260 * @access public
261 * @param integer a numeric month
262 * @param integer a numeric year
263 * @return integer
264 */
Derek Jones0b59f272008-05-13 04:22:33 +0000265if ( ! function_exists('days_in_month'))
Derek Allard83894872007-03-13 20:51:52 +0000266{
Derek Jones269b9422008-01-28 21:00:20 +0000267 function days_in_month($month = 0, $year = '')
Derek Allard83894872007-03-13 20:51:52 +0000268 {
Derek Jones269b9422008-01-28 21:00:20 +0000269 if ($month < 1 OR $month > 12)
Derek Allard83894872007-03-13 20:51:52 +0000270 {
Derek Jones269b9422008-01-28 21:00:20 +0000271 return 0;
Derek Allard83894872007-03-13 20:51:52 +0000272 }
Derek Jones269b9422008-01-28 21:00:20 +0000273
Derek Jones0b59f272008-05-13 04:22:33 +0000274 if ( ! is_numeric($year) OR strlen($year) != 4)
Derek Jones269b9422008-01-28 21:00:20 +0000275 {
276 $year = date('Y');
277 }
278
279 if ($month == 2)
280 {
281 if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0))
282 {
283 return 29;
284 }
285 }
Derek Allard83894872007-03-13 20:51:52 +0000286
Derek Jones269b9422008-01-28 21:00:20 +0000287 $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
288 return $days_in_month[$month - 1];
289 }
Derek Allard83894872007-03-13 20:51:52 +0000290}
291
292// ------------------------------------------------------------------------
293
294/**
295 * Converts a local Unix timestamp to GMT
296 *
297 * @access public
298 * @param integer Unix timestamp
299 * @return integer
300 */
Derek Jones0b59f272008-05-13 04:22:33 +0000301if ( ! function_exists('local_to_gmt'))
Derek Allard83894872007-03-13 20:51:52 +0000302{
Derek Jones269b9422008-01-28 21:00:20 +0000303 function local_to_gmt($time = '')
304 {
305 if ($time == '')
306 $time = time();
Derek Allard83894872007-03-13 20:51:52 +0000307
Derek Jones269b9422008-01-28 21:00:20 +0000308 return mktime( gmdate("H", $time), gmdate("i", $time), gmdate("s", $time), gmdate("m", $time), gmdate("d", $time), gmdate("Y", $time));
309 }
Derek Allard83894872007-03-13 20:51:52 +0000310}
311
312// ------------------------------------------------------------------------
313
314/**
315 * Converts GMT time to a localized value
316 *
317 * Takes a Unix timestamp (in GMT) as input, and returns
318 * at the local value based on the timezone and DST setting
319 * submitted
320 *
321 * @access public
322 * @param integer Unix timestamp
323 * @param string timezone
324 * @param bool whether DST is active
325 * @return integer
326 */
Derek Jones0b59f272008-05-13 04:22:33 +0000327if ( ! function_exists('gmt_to_local'))
Derek Jones269b9422008-01-28 21:00:20 +0000328{
329 function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE)
330 {
331 if ($time == '')
332 {
333 return now();
334 }
Derek Allard83894872007-03-13 20:51:52 +0000335
Derek Jones269b9422008-01-28 21:00:20 +0000336 $time += timezones($timezone) * 3600;
Derek Allard83894872007-03-13 20:51:52 +0000337
Derek Jones269b9422008-01-28 21:00:20 +0000338 if ($dst == TRUE)
339 {
340 $time += 3600;
341 }
Derek Allard83894872007-03-13 20:51:52 +0000342
Derek Jones269b9422008-01-28 21:00:20 +0000343 return $time;
344 }
Derek Allard83894872007-03-13 20:51:52 +0000345}
346
347// ------------------------------------------------------------------------
348
349/**
350 * Converts a MySQL Timestamp to Unix
351 *
352 * @access public
353 * @param integer Unix timestamp
354 * @return integer
355 */
Derek Jones0b59f272008-05-13 04:22:33 +0000356if ( ! function_exists('mysql_to_unix'))
Derek Allard83894872007-03-13 20:51:52 +0000357{
Derek Jones269b9422008-01-28 21:00:20 +0000358 function mysql_to_unix($time = '')
359 {
360 // We'll remove certain characters for backward compatibility
361 // since the formatting changed with MySQL 4.1
362 // YYYY-MM-DD HH:MM:SS
Derek Allard83894872007-03-13 20:51:52 +0000363
Derek Jones269b9422008-01-28 21:00:20 +0000364 $time = str_replace('-', '', $time);
365 $time = str_replace(':', '', $time);
366 $time = str_replace(' ', '', $time);
Derek Allard83894872007-03-13 20:51:52 +0000367
Derek Jones269b9422008-01-28 21:00:20 +0000368 // YYYYMMDDHHMMSS
369 return mktime(
370 substr($time, 8, 2),
371 substr($time, 10, 2),
372 substr($time, 12, 2),
373 substr($time, 4, 2),
374 substr($time, 6, 2),
375 substr($time, 0, 4)
376 );
377 }
Derek Allard83894872007-03-13 20:51:52 +0000378}
379
380// ------------------------------------------------------------------------
381
382/**
383 * Unix to "Human"
384 *
385 * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM
386 *
387 * @access public
388 * @param integer Unix timestamp
389 * @param bool whether to show seconds
390 * @param string format: us or euro
391 * @return string
392 */
Derek Jones0b59f272008-05-13 04:22:33 +0000393if ( ! function_exists('unix_to_human'))
Derek Allard83894872007-03-13 20:51:52 +0000394{
Derek Jones269b9422008-01-28 21:00:20 +0000395 function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us')
396 {
397 $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' ';
Derek Allard83894872007-03-13 20:51:52 +0000398
Derek Jones269b9422008-01-28 21:00:20 +0000399 if ($fmt == 'us')
400 {
401 $r .= date('h', $time).':'.date('i', $time);
402 }
403 else
404 {
405 $r .= date('H', $time).':'.date('i', $time);
406 }
Derek Allard83894872007-03-13 20:51:52 +0000407
Derek Jones269b9422008-01-28 21:00:20 +0000408 if ($seconds)
409 {
410 $r .= ':'.date('s', $time);
411 }
Derek Allard83894872007-03-13 20:51:52 +0000412
Derek Jones269b9422008-01-28 21:00:20 +0000413 if ($fmt == 'us')
414 {
415 $r .= ' '.date('A', $time);
416 }
Derek Allard83894872007-03-13 20:51:52 +0000417
Derek Jones269b9422008-01-28 21:00:20 +0000418 return $r;
419 }
Derek Allard83894872007-03-13 20:51:52 +0000420}
421
422// ------------------------------------------------------------------------
423
424/**
425 * Convert "human" date to GMT
426 *
427 * Reverses the above process
428 *
429 * @access public
430 * @param string format: us or euro
431 * @return integer
432 */
Derek Jones0b59f272008-05-13 04:22:33 +0000433if ( ! function_exists('human_to_unix'))
Derek Allard83894872007-03-13 20:51:52 +0000434{
Derek Jones269b9422008-01-28 21:00:20 +0000435 function human_to_unix($datestr = '')
Derek Allard83894872007-03-13 20:51:52 +0000436 {
Derek Jones269b9422008-01-28 21:00:20 +0000437 if ($datestr == '')
438 {
439 return FALSE;
440 }
Derek Allard83894872007-03-13 20:51:52 +0000441
Derek Jones269b9422008-01-28 21:00:20 +0000442 $datestr = trim($datestr);
443 $datestr = preg_replace("/\040+/", "\040", $datestr);
Derek Allard83894872007-03-13 20:51:52 +0000444
Derek Jones0b59f272008-05-13 04:22:33 +0000445 if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr))
Derek Jones269b9422008-01-28 21:00:20 +0000446 {
447 return FALSE;
448 }
Derek Allard83894872007-03-13 20:51:52 +0000449
Derek Jones269b9422008-01-28 21:00:20 +0000450 $split = preg_split("/\040/", $datestr);
Derek Allard83894872007-03-13 20:51:52 +0000451
Derek Jones269b9422008-01-28 21:00:20 +0000452 $ex = explode("-", $split['0']);
Derek Allard83894872007-03-13 20:51:52 +0000453
Derek Jones269b9422008-01-28 21:00:20 +0000454 $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0'];
455 $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1'];
456 $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2'];
Derek Allard83894872007-03-13 20:51:52 +0000457
Derek Jones269b9422008-01-28 21:00:20 +0000458 $ex = explode(":", $split['1']);
Derek Allard83894872007-03-13 20:51:52 +0000459
Derek Jones269b9422008-01-28 21:00:20 +0000460 $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0'];
461 $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1'];
Derek Allard83894872007-03-13 20:51:52 +0000462
Derek Jones269b9422008-01-28 21:00:20 +0000463 if (isset($ex['2']) AND ereg("[0-9]{1,2}", $ex['2']))
464 {
465 $sec = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2'];
466 }
467 else
468 {
469 // Unless specified, seconds get set to zero.
470 $sec = '00';
471 }
Derek Allard83894872007-03-13 20:51:52 +0000472
Derek Jones269b9422008-01-28 21:00:20 +0000473 if (isset($split['2']))
474 {
475 $ampm = strtolower($split['2']);
Derek Allard83894872007-03-13 20:51:52 +0000476
Derek Jones269b9422008-01-28 21:00:20 +0000477 if (substr($ampm, 0, 1) == 'p' AND $hour < 12)
478 $hour = $hour + 12;
Derek Allard83894872007-03-13 20:51:52 +0000479
Derek Jones269b9422008-01-28 21:00:20 +0000480 if (substr($ampm, 0, 1) == 'a' AND $hour == 12)
481 $hour = '00';
Derek Allard83894872007-03-13 20:51:52 +0000482
Derek Jones269b9422008-01-28 21:00:20 +0000483 if (strlen($hour) == 1)
484 $hour = '0'.$hour;
485 }
486
487 return mktime($hour, $min, $sec, $month, $day, $year);
Derek Allard83894872007-03-13 20:51:52 +0000488 }
Derek Allard83894872007-03-13 20:51:52 +0000489}
490
491// ------------------------------------------------------------------------
492
493/**
494 * Timezone Menu
495 *
496 * Generates a drop-down menu of timezones.
497 *
498 * @access public
499 * @param string timezone
500 * @param string classname
501 * @param string menu name
502 * @return string
503 */
Derek Jones0b59f272008-05-13 04:22:33 +0000504if ( ! function_exists('timezone_menu'))
Derek Allard83894872007-03-13 20:51:52 +0000505{
Derek Jones269b9422008-01-28 21:00:20 +0000506 function timezone_menu($default = 'UTC', $class = "", $name = 'timezones')
Derek Allard83894872007-03-13 20:51:52 +0000507 {
Derek Jones269b9422008-01-28 21:00:20 +0000508 $CI =& get_instance();
509 $CI->lang->load('date');
Derek Allard83894872007-03-13 20:51:52 +0000510
Derek Jones269b9422008-01-28 21:00:20 +0000511 if ($default == 'GMT')
512 $default = 'UTC';
513
514 $menu = '<select name="'.$name.'"';
Derek Allard83894872007-03-13 20:51:52 +0000515
Derek Jones269b9422008-01-28 21:00:20 +0000516 if ($class != '')
517 {
518 $menu .= ' class="'.$class.'"';
519 }
520
521 $menu .= ">\n";
522
523 foreach (timezones() as $key => $val)
524 {
525 $selected = ($default == $key) ? " selected='selected'" : '';
526 $menu .= "<option value='{$key}'{$selected}>".$CI->lang->line($key)."</option>\n";
527 }
528
529 $menu .= "</select>";
530
531 return $menu;
Derek Allard83894872007-03-13 20:51:52 +0000532 }
Derek Allard83894872007-03-13 20:51:52 +0000533}
534
535// ------------------------------------------------------------------------
536
537/**
538 * Timezones
539 *
540 * Returns an array of timezones. This is a helper function
541 * for various other ones in this library
542 *
543 * @access public
544 * @param string timezone
545 * @return string
546 */
Derek Jones0b59f272008-05-13 04:22:33 +0000547if ( ! function_exists('timezones'))
Derek Allard83894872007-03-13 20:51:52 +0000548{
Derek Jones269b9422008-01-28 21:00:20 +0000549 function timezones($tz = '')
Derek Allard83894872007-03-13 20:51:52 +0000550 {
Derek Jones269b9422008-01-28 21:00:20 +0000551 // Note: Don't change the order of these even though
552 // some items appear to be in the wrong order
553
554 $zones = array(
555 'UM12' => -12,
556 'UM11' => -11,
557 'UM10' => -10,
558 'UM9' => -9,
559 'UM8' => -8,
560 'UM7' => -7,
561 'UM6' => -6,
562 'UM5' => -5,
563 'UM4' => -4,
564 'UM25' => -2.5,
565 'UM3' => -3,
566 'UM2' => -2,
567 'UM1' => -1,
568 'UTC' => 0,
569 'UP1' => +1,
570 'UP2' => +2,
571 'UP3' => +3,
572 'UP25' => +2.5,
573 'UP4' => +4,
574 'UP35' => +3.5,
575 'UP5' => +5,
576 'UP45' => +4.5,
577 'UP6' => +6,
578 'UP7' => +7,
579 'UP8' => +8,
580 'UP9' => +9,
581 'UP85' => +8.5,
582 'UP10' => +10,
583 'UP11' => +11,
584 'UP12' => +12
585 );
586
587 if ($tz == '')
588 {
589 return $zones;
590 }
591
592 if ($tz == 'GMT')
593 $tz = 'UTC';
594
Derek Jones0b59f272008-05-13 04:22:33 +0000595 return ( ! isset($zones[$tz])) ? 0 : $zones[$tz];
Derek Allard83894872007-03-13 20:51:52 +0000596 }
Derek Allard83894872007-03-13 20:51:52 +0000597}
598
Derek Jones0b59f272008-05-13 04:22:33 +0000599
600/* End of file date_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000601/* Location: ./system/helpers/date_helper.php */