Skip to content

Commit 9ba2c39

Browse files
committed
IHF: to_default_timezone tests added.
1 parent fb06803 commit 9ba2c39

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/date.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Carbon\Carbon;
4+
use Illuminate\Support\Facades\Config;
45

56
if (!function_exists('to_default_timezone')) {
67
function to_default_timezone($datetime)
@@ -9,6 +10,8 @@ function to_default_timezone($datetime)
910
return $datetime;
1011
}
1112

12-
return Carbon::parse($datetime)->timezone(config('app.timezone'))->toDateTimeString();
13+
$timezone = Config::get('app.timezone');
14+
15+
return Carbon::parse($datetime)->timezone($timezone)->toDateTimeString();
1316
}
1417
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Config;
4+
5+
class ToDefaultTimezoneTest extends TestCase
6+
{
7+
/** @test */
8+
public function it_returns_the_value_itself_for_the_empty_values()
9+
{
10+
$this->assertNull(to_default_timezone(null));
11+
$this->assertFalse(to_default_timezone(false));
12+
$this->assertEquals('', to_default_timezone(''));
13+
}
14+
15+
/** @test */
16+
public function it_converts_valid_datetime_strings_to_default_timezone()
17+
{
18+
Config::shouldReceive('get')->with('app.timezone')->once()->andReturn('Europe/Kiev');
19+
20+
$this->assertEquals('2017-02-28 16:05:01', to_default_timezone('2017-02-28T14:05:01Z'));
21+
}
22+
}

0 commit comments

Comments
 (0)