Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * CodeIgniter Date Helpers |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Helpers |
| 35 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/helpers/date_helper.html |
| 38 | */ |
| 39 | |
| 40 | // ------------------------------------------------------------------------ |
| 41 | |
| 42 | /** |
| 43 | * Get "now" time |
| 44 | * |
| 45 | * Returns time() or its GMT equivalent based on the config file preference |
| 46 | * |
| 47 | * @access public |
| 48 | * @return integer |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 49 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | if ( ! function_exists('now')) |
| 51 | { |
| 52 | function now() |
| 53 | { |
| 54 | $CI =& get_instance(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 55 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 56 | if (strtolower($CI->config->item('time_reference')) == 'gmt') |
| 57 | { |
| 58 | $now = time(); |
| 59 | $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 60 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 61 | if (strlen($system_time) < 10) |
| 62 | { |
| 63 | $system_time = time(); |
| 64 | log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); |
| 65 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 66 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 67 | return $system_time; |
| 68 | } |
Greg Aker | c964e72 | 2011-08-29 19:31:29 -0500 | [diff] [blame] | 69 | |
| 70 | return time(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | } |
| 72 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 73 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 74 | // ------------------------------------------------------------------------ |
| 75 | |
| 76 | /** |
| 77 | * Convert MySQL Style Datecodes |
| 78 | * |
| 79 | * This function is identical to PHPs date() function, |
| 80 | * except that it allows date codes to be formatted using |
| 81 | * the MySQL style, where each code letter is preceded |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 82 | * with a percent sign: %Y %m %d etc... |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | * |
| 84 | * The benefit of doing dates this way is that you don't |
| 85 | * have to worry about escaping your text letters that |
| 86 | * match the date codes. |
| 87 | * |
| 88 | * @access public |
| 89 | * @param string |
| 90 | * @param integer |
| 91 | * @return integer |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 92 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | if ( ! function_exists('mdate')) |
| 94 | { |
| 95 | function mdate($datestr = '', $time = '') |
| 96 | { |
| 97 | if ($datestr == '') |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 98 | { |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 99 | return ''; |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 100 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 101 | |
Greg Aker | c964e72 | 2011-08-29 19:31:29 -0500 | [diff] [blame] | 102 | $time = ($time == '') ? now() : $time; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 103 | |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 104 | $datestr = str_replace( |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 105 | '%\\', |
| 106 | '', |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 107 | preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr) |
| 108 | ); |
Greg Aker | c964e72 | 2011-08-29 19:31:29 -0500 | [diff] [blame] | 109 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 110 | return date($datestr, $time); |
| 111 | } |
| 112 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 113 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | // ------------------------------------------------------------------------ |
| 115 | |
| 116 | /** |
| 117 | * Standard Date |
| 118 | * |
| 119 | * Returns a date formatted according to the submitted standard. |
| 120 | * |
| 121 | * @access public |
| 122 | * @param string the chosen format |
| 123 | * @param integer Unix timestamp |
| 124 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 125 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 126 | if ( ! function_exists('standard_date')) |
| 127 | { |
| 128 | function standard_date($fmt = 'DATE_RFC822', $time = '') |
| 129 | { |
| 130 | $formats = array( |
| 131 | 'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%Q', |
| 132 | 'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC', |
Greg Aker | 3b889a9 | 2011-01-10 12:35:57 -0600 | [diff] [blame] | 133 | 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%Q', |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 134 | 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', |
Syahril Zulkefli | 90658ad | 2011-11-13 23:43:37 +0800 | [diff] [blame] | 135 | 'DATE_RFC850' => '%l, %d-%M-%y %H:%i:%s UTC', |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | 'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O', |
| 137 | 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O', |
| 138 | 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O', |
| 139 | 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q' |
| 140 | ); |
| 141 | |
| 142 | if ( ! isset($formats[$fmt])) |
| 143 | { |
| 144 | return FALSE; |
| 145 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 146 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 147 | return mdate($formats[$fmt], $time); |
| 148 | } |
| 149 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 150 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 151 | // ------------------------------------------------------------------------ |
| 152 | |
| 153 | /** |
| 154 | * Timespan |
| 155 | * |
| 156 | * Returns a span of seconds in this format: |
| 157 | * 10 days 14 hours 36 minutes 47 seconds |
| 158 | * |
| 159 | * @access public |
| 160 | * @param integer a number of seconds |
| 161 | * @param integer Unix timestamp |
Roger Herbert | b81f909 | 2012-03-12 12:46:02 +0000 | [diff] [blame] | 162 | * @param integer a number of display units |
| 163 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 164 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | if ( ! function_exists('timespan')) |
| 166 | { |
Roger Herbert | 8d69aa1 | 2012-03-14 08:44:55 +0000 | [diff] [blame^] | 167 | function timespan($seconds = 1, $time = '', $units = 7) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | { |
| 169 | $CI =& get_instance(); |
| 170 | $CI->lang->load('date'); |
| 171 | |
| 172 | if ( ! is_numeric($seconds)) |
| 173 | { |
| 174 | $seconds = 1; |
| 175 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 176 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 177 | if ( ! is_numeric($time)) |
| 178 | { |
| 179 | $time = time(); |
| 180 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 181 | |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 182 | if ( ! is_numeric($units)) |
| 183 | { |
Roger Herbert | 8d69aa1 | 2012-03-14 08:44:55 +0000 | [diff] [blame^] | 184 | $units = 7; |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 187 | $seconds = ($time <= $seconds) ? 1 : $time - $seconds; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 188 | |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 189 | $str = array(); |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 190 | $years = floor($seconds / 31557600); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 191 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 192 | if ($years > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 193 | { |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 194 | $str[] = $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 195 | } |
| 196 | |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 197 | $seconds -= $years * 31557600; |
| 198 | $months = floor($seconds / 2629743); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 199 | |
Roger Herbert | b8fb66b | 2012-03-11 16:15:15 +0000 | [diff] [blame] | 200 | if (count($str) < $units && ($years > 0 OR $months > 0)) |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 201 | { |
| 202 | if ($months > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 203 | { |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 204 | $str[] = $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')); |
Roger Herbert | 03dbcf0 | 2012-03-11 11:48:50 +0000 | [diff] [blame] | 205 | } |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 206 | |
| 207 | $seconds -= $months * 2629743; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 210 | $weeks = floor($seconds / 604800); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 211 | |
Roger Herbert | b8fb66b | 2012-03-11 16:15:15 +0000 | [diff] [blame] | 212 | if (count($str) < $units && ($years > 0 OR $months > 0 OR $weeks > 0)) |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 213 | { |
| 214 | if ($weeks > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 215 | { |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 216 | $str[] = $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')); |
Roger Herbert | 03dbcf0 | 2012-03-11 11:48:50 +0000 | [diff] [blame] | 217 | } |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 218 | |
| 219 | $seconds -= $weeks * 604800; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 220 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 221 | |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 222 | $days = floor($seconds / 86400); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 223 | |
Roger Herbert | b8fb66b | 2012-03-11 16:15:15 +0000 | [diff] [blame] | 224 | if (count($str) < $units && ($months > 0 OR $weeks > 0 OR $days > 0)) |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 225 | { |
| 226 | if ($days > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 227 | { |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 228 | $str[] = $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')); |
Roger Herbert | 03dbcf0 | 2012-03-11 11:48:50 +0000 | [diff] [blame] | 229 | } |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 230 | |
| 231 | $seconds -= $days * 86400; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 232 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 233 | |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 234 | $hours = floor($seconds / 3600); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 235 | |
Roger Herbert | b8fb66b | 2012-03-11 16:15:15 +0000 | [diff] [blame] | 236 | if (count($str) < $units && ($days > 0 OR $hours > 0)) |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 237 | { |
| 238 | if ($hours > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 239 | { |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 240 | $str[] = $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')); |
Roger Herbert | 03dbcf0 | 2012-03-11 11:48:50 +0000 | [diff] [blame] | 241 | } |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 242 | |
| 243 | $seconds -= $hours * 3600; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 244 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 245 | |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 246 | $minutes = floor($seconds / 60); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 247 | |
Roger Herbert | b8fb66b | 2012-03-11 16:15:15 +0000 | [diff] [blame] | 248 | if (count($str) < $units && ($days > 0 OR $hours > 0 OR $minutes > 0)) |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 249 | { |
| 250 | if ($minutes > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 251 | { |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 252 | $str[] = $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | } |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 254 | |
| 255 | $seconds -= $minutes * 60; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 256 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 257 | |
Roger Herbert | 11f46f7 | 2012-03-11 15:11:44 +0000 | [diff] [blame] | 258 | if ($str == '') |
| 259 | { |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 260 | $str[] = $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 261 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 262 | |
Roger Herbert | 04c146d | 2012-03-11 15:31:01 +0000 | [diff] [blame] | 263 | return implode(', ', $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 264 | } |
| 265 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 266 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 267 | // ------------------------------------------------------------------------ |
| 268 | |
| 269 | /** |
| 270 | * Number of days in a month |
| 271 | * |
| 272 | * Takes a month/year as input and returns the number of days |
| 273 | * for the given month/year. Takes leap years into consideration. |
| 274 | * |
| 275 | * @access public |
| 276 | * @param integer a numeric month |
| 277 | * @param integer a numeric year |
| 278 | * @return integer |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 279 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | if ( ! function_exists('days_in_month')) |
| 281 | { |
| 282 | function days_in_month($month = 0, $year = '') |
| 283 | { |
| 284 | if ($month < 1 OR $month > 12) |
| 285 | { |
| 286 | return 0; |
| 287 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 288 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 289 | if ( ! is_numeric($year) OR strlen($year) != 4) |
| 290 | { |
| 291 | $year = date('Y'); |
| 292 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 293 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 294 | if ($month == 2) |
| 295 | { |
| 296 | if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) |
| 297 | { |
| 298 | return 29; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
| 303 | return $days_in_month[$month - 1]; |
| 304 | } |
| 305 | } |
Derek Jones | 3659109 | 2010-03-05 10:05:51 -0600 | [diff] [blame] | 306 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | // ------------------------------------------------------------------------ |
| 308 | |
| 309 | /** |
| 310 | * Converts a local Unix timestamp to GMT |
| 311 | * |
| 312 | * @access public |
| 313 | * @param integer Unix timestamp |
| 314 | * @return integer |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 315 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 316 | if ( ! function_exists('local_to_gmt')) |
| 317 | { |
| 318 | function local_to_gmt($time = '') |
| 319 | { |
| 320 | if ($time == '') |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 321 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | $time = time(); |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 323 | } |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 324 | |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 325 | return mktime( |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 326 | gmdate("H", $time), |
| 327 | gmdate("i", $time), |
| 328 | gmdate("s", $time), |
| 329 | gmdate("m", $time), |
| 330 | gmdate("d", $time), |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 331 | gmdate("Y", $time) |
| 332 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | } |
| 334 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 335 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 336 | // ------------------------------------------------------------------------ |
| 337 | |
| 338 | /** |
| 339 | * Converts GMT time to a localized value |
| 340 | * |
| 341 | * Takes a Unix timestamp (in GMT) as input, and returns |
| 342 | * at the local value based on the timezone and DST setting |
| 343 | * submitted |
| 344 | * |
| 345 | * @access public |
| 346 | * @param integer Unix timestamp |
| 347 | * @param string timezone |
| 348 | * @param bool whether DST is active |
| 349 | * @return integer |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 350 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 351 | if ( ! function_exists('gmt_to_local')) |
| 352 | { |
| 353 | function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 354 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 355 | if ($time == '') |
| 356 | { |
| 357 | return now(); |
| 358 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 359 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 360 | $time += timezones($timezone) * 3600; |
| 361 | |
| 362 | if ($dst == TRUE) |
| 363 | { |
| 364 | $time += 3600; |
| 365 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 366 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | return $time; |
| 368 | } |
| 369 | } |
Derek Jones | 3659109 | 2010-03-05 10:05:51 -0600 | [diff] [blame] | 370 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 371 | // ------------------------------------------------------------------------ |
| 372 | |
| 373 | /** |
| 374 | * Converts a MySQL Timestamp to Unix |
| 375 | * |
| 376 | * @access public |
| 377 | * @param integer Unix timestamp |
| 378 | * @return integer |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 379 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 380 | if ( ! function_exists('mysql_to_unix')) |
| 381 | { |
| 382 | function mysql_to_unix($time = '') |
| 383 | { |
| 384 | // We'll remove certain characters for backward compatibility |
| 385 | // since the formatting changed with MySQL 4.1 |
| 386 | // YYYY-MM-DD HH:MM:SS |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 387 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 388 | $time = str_replace('-', '', $time); |
| 389 | $time = str_replace(':', '', $time); |
| 390 | $time = str_replace(' ', '', $time); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 391 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 392 | // YYYYMMDDHHMMSS |
Greg Aker | c964e72 | 2011-08-29 19:31:29 -0500 | [diff] [blame] | 393 | return mktime( |
| 394 | substr($time, 8, 2), |
| 395 | substr($time, 10, 2), |
| 396 | substr($time, 12, 2), |
| 397 | substr($time, 4, 2), |
| 398 | substr($time, 6, 2), |
| 399 | substr($time, 0, 4) |
| 400 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 403 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 404 | // ------------------------------------------------------------------------ |
| 405 | |
| 406 | /** |
| 407 | * Unix to "Human" |
| 408 | * |
| 409 | * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM |
| 410 | * |
| 411 | * @access public |
| 412 | * @param integer Unix timestamp |
| 413 | * @param bool whether to show seconds |
| 414 | * @param string format: us or euro |
| 415 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 416 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 417 | if ( ! function_exists('unix_to_human')) |
| 418 | { |
| 419 | function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') |
| 420 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 421 | $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 422 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 423 | if ($fmt == 'us') |
| 424 | { |
| 425 | $r .= date('h', $time).':'.date('i', $time); |
| 426 | } |
| 427 | else |
| 428 | { |
| 429 | $r .= date('H', $time).':'.date('i', $time); |
| 430 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 431 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 432 | if ($seconds) |
| 433 | { |
| 434 | $r .= ':'.date('s', $time); |
| 435 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 436 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 437 | if ($fmt == 'us') |
| 438 | { |
| 439 | $r .= ' '.date('A', $time); |
| 440 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 441 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | return $r; |
| 443 | } |
| 444 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 445 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 446 | // ------------------------------------------------------------------------ |
| 447 | |
| 448 | /** |
| 449 | * Convert "human" date to GMT |
| 450 | * |
| 451 | * Reverses the above process |
| 452 | * |
| 453 | * @access public |
| 454 | * @param string format: us or euro |
| 455 | * @return integer |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 456 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 457 | if ( ! function_exists('human_to_unix')) |
| 458 | { |
| 459 | function human_to_unix($datestr = '') |
| 460 | { |
| 461 | if ($datestr == '') |
| 462 | { |
| 463 | return FALSE; |
| 464 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 465 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 466 | $datestr = trim($datestr); |
Derek Jones | 3659109 | 2010-03-05 10:05:51 -0600 | [diff] [blame] | 467 | $datestr = preg_replace("/\040+/", ' ', $datestr); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 468 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 469 | if ( ! preg_match('/^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr)) |
| 470 | { |
| 471 | return FALSE; |
| 472 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 473 | |
Derek Jones | 3659109 | 2010-03-05 10:05:51 -0600 | [diff] [blame] | 474 | $split = explode(' ', $datestr); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 475 | |
| 476 | $ex = explode("-", $split['0']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 477 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 478 | $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; |
| 479 | $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; |
| 480 | $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 481 | |
| 482 | $ex = explode(":", $split['1']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 483 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 484 | $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 485 | $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 486 | |
Derek Jones | 1322ec5 | 2009-03-11 17:01:14 +0000 | [diff] [blame] | 487 | if (isset($ex['2']) && preg_match('/[0-9]{1,2}/', $ex['2'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 489 | $sec = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 490 | } |
| 491 | else |
| 492 | { |
| 493 | // Unless specified, seconds get set to zero. |
| 494 | $sec = '00'; |
| 495 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 496 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 497 | if (isset($split['2'])) |
| 498 | { |
| 499 | $ampm = strtolower($split['2']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 500 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 501 | if (substr($ampm, 0, 1) == 'p' AND $hour < 12) |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 502 | { |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 503 | $hour = $hour + 12; |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 504 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 505 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 506 | if (substr($ampm, 0, 1) == 'a' AND $hour == 12) |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 507 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 508 | $hour = '00'; |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 509 | } |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 510 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 511 | if (strlen($hour) == 1) |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 512 | { |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 513 | $hour = '0'.$hour; |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 514 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 516 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 517 | return mktime($hour, $min, $sec, $month, $day, $year); |
| 518 | } |
| 519 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 520 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 521 | // ------------------------------------------------------------------------ |
| 522 | |
| 523 | /** |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 524 | * Turns many "reasonably-date-like" strings into something |
| 525 | * that is actually useful. This only works for dates after unix epoch. |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 526 | * |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 527 | * @access public |
| 528 | * @param string The terribly formatted date-like string |
| 529 | * @param string Date format to return (same as php date function) |
| 530 | * @return string |
| 531 | */ |
| 532 | if ( ! function_exists('nice_date')) |
| 533 | { |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 534 | function nice_date($bad_date = '', $format = FALSE) |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 535 | { |
| 536 | if (empty($bad_date)) |
| 537 | { |
| 538 | return 'Unknown'; |
| 539 | } |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 540 | |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 541 | // Date like: YYYYMM |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 542 | if (preg_match('/^\d{6}$/', $bad_date)) |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 543 | { |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 544 | if (in_array(substr($bad_date, 0, 2),array('19', '20'))) |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 545 | { |
| 546 | $year = substr($bad_date, 0, 4); |
| 547 | $month = substr($bad_date, 4, 2); |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 548 | } |
| 549 | else |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 550 | { |
| 551 | $month = substr($bad_date, 0, 2); |
| 552 | $year = substr($bad_date, 2, 4); |
| 553 | } |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 554 | |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 555 | return date($format, strtotime($year . '-' . $month . '-01')); |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 556 | } |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 557 | |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 558 | // Date Like: YYYYMMDD |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 559 | if (preg_match('/^\d{8}$/',$bad_date)) |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 560 | { |
| 561 | $month = substr($bad_date, 0, 2); |
| 562 | $day = substr($bad_date, 2, 2); |
| 563 | $year = substr($bad_date, 4, 4); |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 564 | |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 565 | return date($format, strtotime($month . '/01/' . $year)); |
| 566 | } |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 567 | |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 568 | // Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between) |
| 569 | if (preg_match('/^\d{1,2}-\d{1,2}-\d{4}$/',$bad_date)) |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 570 | { |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 571 | list($m, $d, $y) = explode('-', $bad_date); |
| 572 | return date($format, strtotime("{$y}-{$m}-{$d}")); |
| 573 | } |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 574 | |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 575 | // Any other kind of string, when converted into UNIX time, |
| 576 | // produces "0 seconds after epoc..." is probably bad... |
| 577 | // return "Invalid Date". |
| 578 | if (date('U', strtotime($bad_date)) == '0') |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 579 | { |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 580 | return "Invalid Date"; |
| 581 | } |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 582 | |
Kyle Farris | 896d95a | 2011-08-21 23:03:54 -0300 | [diff] [blame] | 583 | // It's probably a valid-ish date format already |
| 584 | return date($format, strtotime($bad_date)); |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | // ------------------------------------------------------------------------ |
| 589 | |
| 590 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 591 | * Timezone Menu |
| 592 | * |
| 593 | * Generates a drop-down menu of timezones. |
| 594 | * |
| 595 | * @access public |
| 596 | * @param string timezone |
| 597 | * @param string classname |
| 598 | * @param string menu name |
| 599 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 600 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 601 | if ( ! function_exists('timezone_menu')) |
| 602 | { |
| 603 | function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') |
| 604 | { |
| 605 | $CI =& get_instance(); |
| 606 | $CI->lang->load('date'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 607 | |
Greg Aker | c964e72 | 2011-08-29 19:31:29 -0500 | [diff] [blame] | 608 | $default = ($default == 'GMT') ? 'UTC' : $default; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 609 | |
| 610 | $menu = '<select name="'.$name.'"'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 611 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 612 | if ($class != '') |
| 613 | { |
| 614 | $menu .= ' class="'.$class.'"'; |
| 615 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 616 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 617 | $menu .= ">\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 618 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 619 | foreach (timezones() as $key => $val) |
| 620 | { |
| 621 | $selected = ($default == $key) ? " selected='selected'" : ''; |
| 622 | $menu .= "<option value='{$key}'{$selected}>".$CI->lang->line($key)."</option>\n"; |
| 623 | } |
| 624 | |
| 625 | $menu .= "</select>"; |
| 626 | |
| 627 | return $menu; |
| 628 | } |
| 629 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 630 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 631 | // ------------------------------------------------------------------------ |
| 632 | |
| 633 | /** |
| 634 | * Timezones |
| 635 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 636 | * Returns an array of timezones. This is a helper function |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 637 | * for various other ones in this library |
| 638 | * |
| 639 | * @access public |
| 640 | * @param string timezone |
| 641 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 642 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 643 | if ( ! function_exists('timezones')) |
| 644 | { |
| 645 | function timezones($tz = '') |
| 646 | { |
| 647 | // Note: Don't change the order of these even though |
| 648 | // some items appear to be in the wrong order |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 649 | |
| 650 | $zones = array( |
Greg Aker | c964e72 | 2011-08-29 19:31:29 -0500 | [diff] [blame] | 651 | 'UM12' => -12, |
| 652 | 'UM11' => -11, |
| 653 | 'UM10' => -10, |
| 654 | 'UM95' => -9.5, |
| 655 | 'UM9' => -9, |
| 656 | 'UM8' => -8, |
| 657 | 'UM7' => -7, |
| 658 | 'UM6' => -6, |
| 659 | 'UM5' => -5, |
| 660 | 'UM45' => -4.5, |
| 661 | 'UM4' => -4, |
| 662 | 'UM35' => -3.5, |
| 663 | 'UM3' => -3, |
| 664 | 'UM2' => -2, |
| 665 | 'UM1' => -1, |
| 666 | 'UTC' => 0, |
| 667 | 'UP1' => +1, |
| 668 | 'UP2' => +2, |
| 669 | 'UP3' => +3, |
| 670 | 'UP35' => +3.5, |
| 671 | 'UP4' => +4, |
| 672 | 'UP45' => +4.5, |
| 673 | 'UP5' => +5, |
| 674 | 'UP55' => +5.5, |
| 675 | 'UP575' => +5.75, |
| 676 | 'UP6' => +6, |
| 677 | 'UP65' => +6.5, |
| 678 | 'UP7' => +7, |
| 679 | 'UP8' => +8, |
| 680 | 'UP875' => +8.75, |
| 681 | 'UP9' => +9, |
| 682 | 'UP95' => +9.5, |
| 683 | 'UP10' => +10, |
| 684 | 'UP105' => +10.5, |
| 685 | 'UP11' => +11, |
| 686 | 'UP115' => +11.5, |
| 687 | 'UP12' => +12, |
| 688 | 'UP1275' => +12.75, |
| 689 | 'UP13' => +13, |
| 690 | 'UP14' => +14 |
| 691 | ); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 692 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 693 | if ($tz == '') |
| 694 | { |
| 695 | return $zones; |
| 696 | } |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 697 | |
Greg Aker | f916839 | 2011-08-29 19:29:05 -0500 | [diff] [blame] | 698 | $tz = ($tz == 'GMT') ? 'UTC' : $tz; |
Eric Barnes | dc3e4be | 2011-12-19 13:48:29 -0500 | [diff] [blame] | 699 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 700 | return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; |
| 701 | } |
| 702 | } |
| 703 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 704 | /* End of file date_helper.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 705 | /* Location: ./system/helpers/date_helper.php */ |