Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ########### |
| 2 | Date Helper |
| 3 | ########### |
| 4 | |
| 5 | The Date Helper file contains functions that help you work with dates. |
| 6 | |
| 7 | .. contents:: Page Contents |
| 8 | |
| 9 | Loading this Helper |
| 10 | =================== |
| 11 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 12 | This helper is loaded using the following code:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 13 | |
| 14 | $this->load->helper('date'); |
| 15 | |
| 16 | The following functions are available: |
| 17 | |
| 18 | now() |
| 19 | ===== |
| 20 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 21 | .. php:function:: now($timezone = NULL) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 22 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 23 | :param string $timezone: Timezone |
| 24 | :returns: int |
Iban Eguia | 7bf0a4f | 2012-03-27 18:36:15 +0200 | [diff] [blame] | 25 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 26 | Returns the current time as a UNIX timestamp, referenced either to your server's |
| 27 | local time or any PHP suported timezone, based on the "time reference" setting |
| 28 | in your config file. If you do not intend to set your master time reference to |
| 29 | any other PHP supported timezone (which you'll typically do if you run a site |
| 30 | that lets each user set their own timezone settings) there is no benefit to using |
| 31 | this function over PHP's ``time()`` function. |
Iban Eguia | 7bf0a4f | 2012-03-27 18:36:15 +0200 | [diff] [blame] | 32 | |
| 33 | :: |
| 34 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 35 | echo now('Australia/Victoria'); |
| 36 | |
| 37 | If a timezone is not provided, it will return ``time()`` based on the |
| 38 | **time_reference** setting. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 39 | |
| 40 | mdate() |
| 41 | ======= |
| 42 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 43 | .. php:function:: mdate($datestr = '', $time = '') |
| 44 | |
| 45 | :param string $datestr: Date string |
| 46 | :param int $time: UNIX timestamp |
| 47 | :returns: int |
| 48 | |
Andrey Andreev | ac57033 | 2012-07-04 13:04:10 +0300 | [diff] [blame] | 49 | This function is identical to PHP's `date() <http://www.php.net/date>`_ |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 50 | function, except that it lets you use MySQL style date codes, where each |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 51 | code letter is preceded with a percent sign, e.g. `%Y %m %d` |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 52 | |
| 53 | The benefit of doing dates this way is that you don't have to worry |
| 54 | about escaping any characters that are not date codes, as you would |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 55 | normally have to do with the ``date()`` function. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 56 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 57 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 58 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 59 | $datestring = 'Year: %Y Month: %m Day: %d - %h:%i %a'; |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 60 | $time = time(); |
| 61 | echo mdate($datestring, $time); |
| 62 | |
| 63 | If a timestamp is not included in the second parameter the current time |
| 64 | will be used. |
| 65 | |
| 66 | standard_date() |
| 67 | =============== |
| 68 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 69 | .. php:function:: standard_date($fmt = 'DATE_RFC822', $time = NULL) |
| 70 | |
| 71 | :param string $fmt: Date format |
| 72 | :param int $time: UNIX timestamp |
| 73 | :returns: string |
| 74 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 75 | Lets you generate a date string in one of several standardized formats. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 76 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 77 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 78 | |
| 79 | $format = 'DATE_RFC822'; |
| 80 | $time = time(); |
| 81 | echo standard_date($format, $time); |
| 82 | |
Andrey Andreev | f964b16 | 2013-11-12 17:04:55 +0200 | [diff] [blame] | 83 | .. note:: This function is DEPRECATED. Use the native ``date()`` combined with |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 84 | `DateTime's format constants |
| 85 | <http://www.php.net/manual/en/class.datetime.php#datetime.constants.types>`_ |
Andrey Andreev | ac57033 | 2012-07-04 13:04:10 +0300 | [diff] [blame] | 86 | instead: |
| 87 | |
| 88 | | |
| 89 | | echo date(DATE_RFC822, time()); |
| 90 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 91 | Supported formats |
| 92 | ----------------- |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 93 | |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 94 | =============== ======================= ====================================== |
| 95 | Constant Description Example |
| 96 | =============== ======================= ====================================== |
Andrey Andreev | ac57033 | 2012-07-04 13:04:10 +0300 | [diff] [blame] | 97 | DATE_ATOM Atom 2005-08-15T16:13:03+0000 |
| 98 | DATE_COOKIE HTTP Cookies Sun, 14 Aug 2005 16:13:03 UTC |
| 99 | DATE_ISO8601 ISO-8601 2005-08-14T16:13:03+00:00 |
| 100 | DATE_RFC822 RFC 822 Sun, 14 Aug 05 16:13:03 UTC |
| 101 | DATE_RFC850 RFC 850 Sunday, 14-Aug-05 16:13:03 UTC |
| 102 | DATE_RFC1036 RFC 1036 Sunday, 14-Aug-05 16:13:03 UTC |
| 103 | DATE_RFC1123 RFC 1123 Sun, 14 Aug 2005 16:13:03 UTC |
| 104 | DATE_RFC2822 RFC 2822 Sun, 14 Aug 2005 16:13:03 +0000 |
| 105 | DATE_RSS RSS Sun, 14 Aug 2005 16:13:03 UTC |
| 106 | DATE_W3C W3C 2005-08-14T16:13:03+0000 |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 107 | =============== ======================= ====================================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 108 | |
| 109 | local_to_gmt() |
| 110 | ============== |
| 111 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 112 | .. php:function:: local_to_gmt($time = '') |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 113 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 114 | :param int $time: UNIX timestamp |
| 115 | :returns: string |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 116 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 117 | Takes a UNIX timestamp as input and returns it as GMT. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 118 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 119 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 120 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 121 | $gmt = local_to_gmt(time()); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 122 | |
| 123 | gmt_to_local() |
| 124 | ============== |
| 125 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 126 | .. php:function:: gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) |
| 127 | |
| 128 | :param int $time: UNIX timestamp |
| 129 | :param string $timezone: Timezone |
| 130 | :param bool $dst: Whether DST is active |
| 131 | :returns: int |
| 132 | |
| 133 | Takes a UNIX timestamp (referenced to GMT) as input, and converts it to |
| 134 | a localized timestamp based on the timezone and Daylight Saving Time |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 135 | submitted. |
| 136 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 137 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 138 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 139 | $timestamp = 1140153693; |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 140 | $timezone = 'UM8'; |
| 141 | $daylight_saving = TRUE; |
| 142 | echo gmt_to_local($timestamp, $timezone, $daylight_saving); |
| 143 | |
| 144 | |
| 145 | .. note:: For a list of timezones see the reference at the bottom of this page. |
| 146 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 147 | mysql_to_unix() |
| 148 | =============== |
| 149 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 150 | .. php:function:: mysql_to_unix($time = '') |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 151 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 152 | :param int $time: UNIX timestamp |
| 153 | :returns: int |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 154 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 155 | Takes a MySQL Timestamp as input and returns it as a UNIX timestamp. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 156 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 157 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 158 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 159 | $unix = mysql_to_unix('20061124092345'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 160 | |
| 161 | unix_to_human() |
| 162 | =============== |
| 163 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 164 | .. php:function:: unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 165 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 166 | :param int $time: UNIX timestamp |
| 167 | :param bool $seconds: Whether to show seconds |
| 168 | :param string $fmt: format (us or euro) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 169 | :returns: integer |
| 170 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 171 | Takes a UNIX timestamp as input and returns it in a human readable |
| 172 | format with this prototype:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 173 | |
| 174 | YYYY-MM-DD HH:MM:SS AM/PM |
| 175 | |
| 176 | This can be useful if you need to display a date in a form field for |
| 177 | submission. |
| 178 | |
| 179 | The time can be formatted with or without seconds, and it can be set to |
| 180 | European or US format. If only the timestamp is submitted it will return |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 181 | the time without seconds formatted for the U.S. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 182 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 183 | Examples:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 184 | |
| 185 | $now = time(); |
| 186 | echo unix_to_human($now); // U.S. time, no seconds |
| 187 | echo unix_to_human($now, TRUE, 'us'); // U.S. time with seconds |
| 188 | echo unix_to_human($now, TRUE, 'eu'); // Euro time with seconds |
| 189 | |
| 190 | human_to_unix() |
| 191 | =============== |
| 192 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 193 | .. php:function:: human_to_unix($datestr = '') |
| 194 | |
| 195 | :param int $datestr: Date string |
| 196 | :returns: int UNIX timestamp or FALSE on failure |
| 197 | |
| 198 | The opposite of the :php:func:`unix_to_time()` function. Takes a "human" |
| 199 | time as input and returns it as a UNIX timestamp. This is useful if you |
| 200 | accept "human" formatted dates submitted via a form. Returns boolean FALSE |
Mat Whitney | 7540ded | 2012-06-22 12:02:10 -0700 | [diff] [blame] | 201 | date string passed to it is not formatted as indicated above. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 202 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 203 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 204 | |
| 205 | $now = time(); |
| 206 | $human = unix_to_human($now); |
| 207 | $unix = human_to_unix($human); |
| 208 | |
| 209 | nice_date() |
| 210 | =========== |
| 211 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 212 | .. php:function:: nice_date($bad_date = '', $format = FALSE) |
| 213 | |
| 214 | :param int $bad_date: The terribly formatted date-like string |
| 215 | :param string $format: Date format to return (same as PHP's ``date()`` function) |
| 216 | :returns: string |
| 217 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 218 | This function can take a number poorly-formed date formats and convert |
| 219 | them into something useful. It also accepts well-formed dates. |
| 220 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 221 | The function will return a UNIX timestamp by default. You can, optionally, |
| 222 | pass a format string (the same type as the PHP ``date()`` function accepts) |
| 223 | as the second parameter. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 224 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 225 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 226 | |
Andrey Andreev | c275b23 | 2012-06-15 16:13:17 +0300 | [diff] [blame] | 227 | $bad_date = '199605'; |
| 228 | // Should Produce: 1996-05-01 |
| 229 | $better_date = nice_date($bad_date, 'Y-m-d'); |
| 230 | |
| 231 | $bad_date = '9-11-2001'; |
| 232 | // Should Produce: 2001-09-11 |
| 233 | $better_date = nice_date($bad_date, 'Y-m-d'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 234 | |
| 235 | timespan() |
| 236 | ========== |
| 237 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 238 | .. php:function:: timespan($seconds = 1, $time = '', $units = '') |
| 239 | |
| 240 | :param int $seconds: Number of seconds |
| 241 | :param string $time: UNIX timestamp |
| 242 | :param int $units: Number of time units to display |
| 243 | :returns: string |
| 244 | |
| 245 | Formats a UNIX timestamp so that is appears similar to this:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 246 | |
| 247 | 1 Year, 10 Months, 2 Weeks, 5 Days, 10 Hours, 16 Minutes |
| 248 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 249 | The first parameter must contain a UNIX timestamp. |
| 250 | The second parameter must contain a timestamp that is greater that the |
| 251 | first timestamp. |
| 252 | The thirdparameter is optional and limits the number of time units to display. |
| 253 | |
| 254 | If the second parameter empty, the current time will be used. |
| 255 | |
Mat Whitney | 7540ded | 2012-06-22 12:02:10 -0700 | [diff] [blame] | 256 | The most common purpose for this function is to show how much time has |
| 257 | elapsed from some point in time in the past to now. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 258 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 259 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 260 | |
| 261 | $post_date = '1079621429'; |
| 262 | $now = time(); |
Roger Herbert | b81f909 | 2012-03-12 12:46:02 +0000 | [diff] [blame] | 263 | $units = 2; |
| 264 | echo timespan($post_date, $now, $units); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 265 | |
| 266 | .. note:: The text generated by this function is found in the following language |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 267 | file: `language/<your_lang>/date_lang.php` |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 268 | |
| 269 | days_in_month() |
| 270 | =============== |
| 271 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 272 | .. php:function:: days_in_month($month = 0, $year = '') |
| 273 | |
| 274 | :param int $month: a numeric month |
| 275 | :param int $year: a numeric year |
| 276 | :returns: int |
| 277 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 278 | Returns the number of days in a given month/year. Takes leap years into |
Mat Whitney | 7540ded | 2012-06-22 12:02:10 -0700 | [diff] [blame] | 279 | account. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 280 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 281 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 282 | |
| 283 | echo days_in_month(06, 2005); |
| 284 | |
| 285 | If the second parameter is empty, the current year will be used. |
| 286 | |
Andrey Andreev | 2139ecd | 2012-01-11 23:58:50 +0200 | [diff] [blame] | 287 | date_range() |
| 288 | ============ |
| 289 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 290 | .. php:function:: date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d') |
| 291 | |
| 292 | :param int $unix_start: UNIX timestamp of the range start date |
| 293 | :param int $mixed: UNIX timestamp of the range end date or interval in days |
| 294 | :param bool $is_unix: set to FALSE if $mixed is not a timestamp |
| 295 | :param string $format: Output date format, same as in ``date()`` |
| 296 | :returns: array |
| 297 | |
Andrey Andreev | 2139ecd | 2012-01-11 23:58:50 +0200 | [diff] [blame] | 298 | Returns a list of dates within a specified period. |
| 299 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 300 | Example:: |
Andrey Andreev | 2139ecd | 2012-01-11 23:58:50 +0200 | [diff] [blame] | 301 | |
| 302 | $range = date_range('2012-01-01', '2012-01-15'); |
| 303 | echo "First 15 days of 2012:"; |
| 304 | foreach ($range as $date) |
| 305 | { |
| 306 | echo $date."\n"; |
| 307 | } |
| 308 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 309 | timezones() |
| 310 | =========== |
| 311 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 312 | .. php:function:: timezones($tz = '') |
| 313 | |
| 314 | :param string $tz: a numeric timezone |
| 315 | :returns: string |
| 316 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 317 | Takes a timezone reference (for a list of valid timezones, see the |
| 318 | "Timezone Reference" below) and returns the number of hours offset from |
| 319 | UTC. |
| 320 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 321 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 322 | |
| 323 | echo timezones('UM5'); |
| 324 | |
| 325 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 326 | This function is useful when used with :php:func:`timezone_menu()`. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 327 | |
| 328 | timezone_menu() |
| 329 | =============== |
| 330 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 331 | .. php:function:: timezone_menu($default = 'UTC', $class = '', $name = 'timezones', $attributes = '') |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 332 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 333 | :param string $default: Timezone |
| 334 | :param string $class: Class name |
| 335 | :param string $name: Menu name |
| 336 | :param mixed $attributes: HTML attributes |
| 337 | :returns: string |
| 338 | |
| 339 | Generates a pull-down menu of timezones, like this one: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 340 | |
| 341 | .. raw:: html |
| 342 | |
| 343 | <form action="#"> |
| 344 | <select name="timezones"> |
Kwaan Online | e90b684 | 2012-01-31 10:15:30 +0000 | [diff] [blame] | 345 | <option value='UM12'>(UTC -12:00) Baker/Howland Island</option> |
| 346 | <option value='UM11'>(UTC -11:00) Samoa Time Zone, Niue</option> |
| 347 | <option value='UM10'>(UTC -10:00) Hawaii-Aleutian Standard Time, Cook Islands, Tahiti</option> |
| 348 | <option value='UM95'>(UTC -9:30) Marquesas Islands</option> |
| 349 | <option value='UM9'>(UTC -9:00) Alaska Standard Time, Gambier Islands</option> |
| 350 | <option value='UM8'>(UTC -8:00) Pacific Standard Time, Clipperton Island</option> |
| 351 | <option value='UM7'>(UTC -7:00) Mountain Standard Time</option> |
| 352 | <option value='UM6'>(UTC -6:00) Central Standard Time</option> |
| 353 | <option value='UM5'>(UTC -5:00) Eastern Standard Time, Western Caribbean Standard Time</option> |
| 354 | <option value='UM45'>(UTC -4:30) Venezuelan Standard Time</option> |
| 355 | <option value='UM4'>(UTC -4:00) Atlantic Standard Time, Eastern Caribbean Standard Time</option> |
| 356 | <option value='UM35'>(UTC -3:30) Newfoundland Standard Time</option> |
| 357 | <option value='UM3'>(UTC -3:00) Argentina, Brazil, French Guiana, Uruguay</option> |
| 358 | <option value='UM2'>(UTC -2:00) South Georgia/South Sandwich Islands</option> |
| 359 | <option value='UM1'>(UTC -1:00) Azores, Cape Verde Islands</option> |
| 360 | <option value='UTC' selected='selected'>(UTC) Greenwich Mean Time, Western European Time</option> |
| 361 | <option value='UP1'>(UTC +1:00) Central European Time, West Africa Time</option> |
| 362 | <option value='UP2'>(UTC +2:00) Central Africa Time, Eastern European Time, Kaliningrad Time</option> |
| 363 | <option value='UP3'>(UTC +3:00) Moscow Time, East Africa Time</option> |
| 364 | <option value='UP35'>(UTC +3:30) Iran Standard Time</option> |
| 365 | <option value='UP4'>(UTC +4:00) Azerbaijan Standard Time, Samara Time</option> |
| 366 | <option value='UP45'>(UTC +4:30) Afghanistan</option> |
| 367 | <option value='UP5'>(UTC +5:00) Pakistan Standard Time, Yekaterinburg Time</option> |
| 368 | <option value='UP55'>(UTC +5:30) Indian Standard Time, Sri Lanka Time</option> |
| 369 | <option value='UP575'>(UTC +5:45) Nepal Time</option> |
| 370 | <option value='UP6'>(UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time</option> |
| 371 | <option value='UP65'>(UTC +6:30) Cocos Islands, Myanmar</option> |
| 372 | <option value='UP7'>(UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam</option> |
| 373 | <option value='UP8'>(UTC +8:00) Australian Western Standard Time, Beijing Time, Irkutsk Time</option> |
| 374 | <option value='UP875'>(UTC +8:45) Australian Central Western Standard Time</option> |
| 375 | <option value='UP9'>(UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk Time</option> |
| 376 | <option value='UP95'>(UTC +9:30) Australian Central Standard Time</option> |
| 377 | <option value='UP10'>(UTC +10:00) Australian Eastern Standard Time, Vladivostok Time</option> |
| 378 | <option value='UP105'>(UTC +10:30) Lord Howe Island</option> |
| 379 | <option value='UP11'>(UTC +11:00) Magadan Time, Solomon Islands, Vanuatu</option> |
| 380 | <option value='UP115'>(UTC +11:30) Norfolk Island</option> |
| 381 | <option value='UP12'>(UTC +12:00) Fiji, Gilbert Islands, Kamchatka Time, New Zealand Standard Time</option> |
| 382 | <option value='UP1275'>(UTC +12:45) Chatham Islands Standard Time</option> |
| 383 | <option value='UP13'>(UTC +13:00) Phoenix Islands Time, Tonga</option> |
| 384 | <option value='UP14'>(UTC +14:00) Line Islands</option> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 385 | </select> |
| 386 | </form> |
| 387 | |
| 388 | |
| 389 | This menu is useful if you run a membership site in which your users are |
| 390 | allowed to set their local timezone value. |
| 391 | |
| 392 | The first parameter lets you set the "selected" state of the menu. For |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 393 | example, to set Pacific time as the default you will do this:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 394 | |
| 395 | echo timezone_menu('UM8'); |
| 396 | |
| 397 | Please see the timezone reference below to see the values of this menu. |
| 398 | |
| 399 | The second parameter lets you set a CSS class name for the menu. |
| 400 | |
Mat Whitney | 7540ded | 2012-06-22 12:02:10 -0700 | [diff] [blame] | 401 | The fourth parameter lets you set one or more attributes on the generated select tag. |
| 402 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 403 | .. note:: The text contained in the menu is found in the following |
| 404 | language file: `language/<your_lang>/date_lang.php` |
| 405 | |
| 406 | |
| 407 | Timezone Reference |
| 408 | ================== |
| 409 | |
| 410 | The following table indicates each timezone and its location. |
| 411 | |
Kwaan Online | e90b684 | 2012-01-31 10:15:30 +0000 | [diff] [blame] | 412 | Note some of the location lists have been abridged for clarity and formatting. |
| 413 | |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 414 | =========== ===================================================================== |
| 415 | Time Zone Location |
| 416 | =========== ===================================================================== |
AdwinTrave | 7a09152 | 2013-07-15 13:36:51 -0400 | [diff] [blame] | 417 | UM12 (UTC - 12:00) Baker/Howland Island |
| 418 | UM11 (UTC - 11:00) Samoa Time Zone, Niue |
| 419 | UM10 (UTC - 10:00) Hawaii-Aleutian Standard Time, Cook Islands |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 420 | UM95 (UTC - 09:30) Marquesas Islands |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 421 | UM9 (UTC - 09:00) Alaska Standard Time, Gambier Islands |
| 422 | UM8 (UTC - 08:00) Pacific Standard Time, Clipperton Island |
| 423 | UM7 (UTC - 11:00) Mountain Standard Time |
| 424 | UM6 (UTC - 06:00) Central Standard Time |
| 425 | UM5 (UTC - 05:00) Eastern Standard Time, Western Caribbean |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 426 | UM45 (UTC - 04:30) Venezuelan Standard Time |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 427 | UM4 (UTC - 04:00) Atlantic Standard Time, Eastern Caribbean |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 428 | UM35 (UTC - 03:30) Newfoundland Standard Time |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 429 | UM3 (UTC - 03:00) Argentina, Brazil, French Guiana, Uruguay |
| 430 | UM2 (UTC - 02:00) South Georgia/South Sandwich Islands |
AdwinTrave | 7a09152 | 2013-07-15 13:36:51 -0400 | [diff] [blame] | 431 | UM1 (UTC -1:00) Azores, Cape Verde Islands |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 432 | UTC (UTC) Greenwich Mean Time, Western European Time |
| 433 | UP1 (UTC +1:00) Central European Time, West Africa Time |
| 434 | UP2 (UTC +2:00) Central Africa Time, Eastern European Time |
| 435 | UP3 (UTC +3:00) Moscow Time, East Africa Time |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 436 | UP35 (UTC +3:30) Iran Standard Time |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 437 | UP4 (UTC +4:00) Azerbaijan Standard Time, Samara Time |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 438 | UP45 (UTC +4:30) Afghanistan |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 439 | UP5 (UTC +5:00) Pakistan Standard Time, Yekaterinburg Time |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 440 | UP55 (UTC +5:30) Indian Standard Time, Sri Lanka Time |
| 441 | UP575 (UTC +5:45) Nepal Time |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 442 | UP6 (UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 443 | UP65 (UTC +6:30) Cocos Islands, Myanmar |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 444 | UP7 (UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam |
| 445 | UP8 (UTC +8:00) Australian Western Standard Time, Beijing Time |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 446 | UP875 (UTC +8:45) Australian Central Western Standard Time |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 447 | UP9 (UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 448 | UP95 (UTC +9:30) Australian Central Standard Time |
| 449 | UP10 (UTC +10:00) Australian Eastern Standard Time, Vladivostok Time |
| 450 | UP105 (UTC +10:30) Lord Howe Island |
| 451 | UP11 (UTC +11:00) Magadan Time, Solomon Islands, Vanuatu |
| 452 | UP115 (UTC +11:30) Norfolk Island |
| 453 | UP12 (UTC +12:00) Fiji, Gilbert Islands, Kamchatka, New Zealand |
| 454 | UP1275 (UTC +12:45) Chatham Islands Standard Time |
AdwinTrave | 7a09152 | 2013-07-15 13:36:51 -0400 | [diff] [blame] | 455 | UP13 (UTC +13:00) Phoenix Islands Time, Tonga |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 456 | UP14 (UTC +14:00) Line Islands |
Andrey Andreev | 58f677f | 2013-07-16 11:01:37 +0300 | [diff] [blame] | 457 | =========== ===================================================================== |