File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 9
9
* the LICENSE file that was distributed with this source code.
10
10
*/
11
11
12
+ use CodeIgniter \I18n \Time ;
13
+
12
14
// CodeIgniter Date Helpers
13
15
14
16
if (! function_exists ('now ' )) {
@@ -25,12 +27,14 @@ function now(?string $timezone = null): int
25
27
$ timezone = empty ($ timezone ) ? app_timezone () : $ timezone ;
26
28
27
29
if ($ timezone === 'local ' || $ timezone === date_default_timezone_get ()) {
28
- return time ();
30
+ $ time = Time::now ();
31
+
32
+ return $ time ->getTimestamp ();
29
33
}
30
34
31
- $ datetime = new DateTime ( ' now ' , new DateTimeZone ($ timezone) );
35
+ $ time = Time:: now ($ timezone );
32
36
sscanf (
33
- $ datetime ->format ('j-n-Y G:i:s ' ),
37
+ $ time ->format ('j-n-Y G:i:s ' ),
34
38
'%d-%d-%d %d:%d:%d ' ,
35
39
$ day ,
36
40
$ month ,
Original file line number Diff line number Diff line change 11
11
12
12
namespace CodeIgniter \Helpers ;
13
13
14
+ use CodeIgniter \I18n \Time ;
14
15
use CodeIgniter \Test \CIUnitTestCase ;
15
16
use DateTimeZone ;
16
17
@@ -27,16 +28,24 @@ protected function setUp(): void
27
28
28
29
public function testNowDefault ()
29
30
{
30
- $ this ->assertCloseEnough (now (), time ()); // close enough
31
+ Time::setTestNow ('June 20, 2022 ' , 'America/Chicago ' );
32
+
33
+ $ this ->assertSame (now (), 1655701200 );
34
+
35
+ Time::setTestNow ();
31
36
}
32
37
33
38
public function testNowSpecific ()
34
39
{
40
+ Time::setTestNow ('June 20, 2022 ' , 'America/Chicago ' );
41
+
35
42
// Chicago should be two hours ahead of Vancouver
36
- $ this ->assertCloseEnough (
43
+ $ this ->assertSame (
37
44
7200 ,
38
45
now ('America/Chicago ' ) - now ('America/Vancouver ' )
39
46
);
47
+
48
+ Time::setTestNow ();
40
49
}
41
50
42
51
public function testTimezoneSelectDefault ()
You can’t perform that action at this time.
0 commit comments