forked from briannesbitt/Carbon
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement createFromTimeString briannesbitt#919
- Loading branch information
1 parent
d12da8c
commit 2c4b597
Showing
3 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Carbon package. | ||
* | ||
* (c) Brian Nesbitt <brian@nesbot.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\Carbon; | ||
|
||
use Carbon\Carbon; | ||
use DateTimeZone; | ||
use Tests\AbstractTestCase; | ||
|
||
class CreateFromTimeStringTest extends AbstractTestCase | ||
{ | ||
public function testCreateFromTimeString() | ||
{ | ||
$d = Carbon::createFromTimeString('22:45'); | ||
$this->assertSame(22, $d->hour); | ||
$this->assertSame(45, $d->minute); | ||
$this->assertSame(0, $d->second); | ||
$this->assertSame(0, $d->micro); | ||
} | ||
|
||
public function testCreateFromTimeStringWithSecond() | ||
{ | ||
$d = Carbon::createFromTimeString('22:45:12'); | ||
$this->assertSame(22, $d->hour); | ||
$this->assertSame(45, $d->minute); | ||
$this->assertSame(12, $d->second); | ||
$this->assertSame(0, $d->micro); | ||
} | ||
|
||
public function testCreateFromTimeStringWithMicroSecond() | ||
{ | ||
if (version_compare(PHP_VERSION, '7.1.0-dev', '<')) { | ||
$this->markTestSkipped(); | ||
} | ||
|
||
$d = Carbon::createFromTimeString('22:45:00.625341'); | ||
$this->assertSame(22, $d->hour); | ||
$this->assertSame(45, $d->minute); | ||
$this->assertSame(0, $d->second); | ||
$this->assertSame(625341, $d->micro); | ||
} | ||
|
||
public function testCreateFromTimeStringWithDateTimeZone() | ||
{ | ||
$d = Carbon::createFromTimeString('12:20:30', new DateTimeZone('Europe/London')); | ||
$this->assertCarbon($d, Carbon::now()->year, Carbon::now()->month, Carbon::now()->day, 12, 20, 30, 0); | ||
$this->assertSame('Europe/London', $d->tzName); | ||
} | ||
|
||
public function testCreateFromTimeStringWithTimeZoneString() | ||
{ | ||
$d = Carbon::createFromTimeString('12:20:30', 'Europe/London'); | ||
$this->assertCarbon($d, Carbon::now()->year, Carbon::now()->month, Carbon::now()->day, 12, 20, 30, 0); | ||
$this->assertSame('Europe/London', $d->tzName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters