|
41 | 41 | * @package CodeIgniter |
42 | 42 | */ |
43 | 43 |
|
| 44 | +if (! function_exists('now')) |
| 45 | +{ |
| 46 | + /** |
| 47 | + * Get "now" time |
| 48 | + * |
| 49 | + * Returns time() based on the timezone parameter or on the |
| 50 | + * app_timezone() setting |
| 51 | + * |
| 52 | + * @param string $timezone |
| 53 | + * |
| 54 | + * @return integer |
| 55 | + * @throws \Exception |
| 56 | + */ |
| 57 | + function now(string $timezone = null): int |
| 58 | + { |
| 59 | + $timezone = empty($timezone) ? app_timezone() : $timezone; |
| 60 | + |
| 61 | + if ($timezone === 'local' || $timezone === date_default_timezone_get()) |
| 62 | + { |
| 63 | + return time(); |
| 64 | + } |
| 65 | + |
| 66 | + $datetime = new DateTime('now', new DateTimeZone($timezone)); |
| 67 | + sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second); |
| 68 | + |
| 69 | + return mktime($hour, $minute, $second, $month, $day, $year); |
| 70 | + } |
| 71 | +}<?php |
| 72 | +/** |
| 73 | + * CodeIgniter |
| 74 | + * |
| 75 | + * An open source application development framework for PHP |
| 76 | + * |
| 77 | + * This content is released under the MIT License (MIT) |
| 78 | + * |
| 79 | + * Copyright (c) 2014-2019 British Columbia Institute of Technology |
| 80 | + * |
| 81 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 82 | + * of this software and associated documentation files (the "Software"), to deal |
| 83 | + * in the Software without restriction, including without limitation the rights |
| 84 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 85 | + * copies of the Software, and to permit persons to whom the Software is |
| 86 | + * furnished to do so, subject to the following conditions: |
| 87 | + * |
| 88 | + * The above copyright notice and this permission notice shall be included in |
| 89 | + * all copies or substantial portions of the Software. |
| 90 | + * |
| 91 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 92 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 93 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 94 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 95 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 96 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 97 | + * THE SOFTWARE. |
| 98 | + * |
| 99 | + * @package CodeIgniter |
| 100 | + * @author CodeIgniter Dev Team |
| 101 | + * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) |
| 102 | + * @license https://opensource.org/licenses/MIT MIT License |
| 103 | + * @link https://codeigniter.com |
| 104 | + * @since Version 4.0.0 |
| 105 | + * @filesource |
| 106 | + */ |
| 107 | + |
| 108 | +/** |
| 109 | + * CodeIgniter Date Helpers |
| 110 | + * |
| 111 | + * @package CodeIgniter |
| 112 | + */ |
| 113 | + |
44 | 114 | if (! function_exists('now')) |
45 | 115 | { |
46 | 116 | /** |
|
0 commit comments