Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added $utc, checks if timezone is UTC #49

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Carbon/Carbon.php
Expand Up @@ -34,6 +34,7 @@
* @property-read integer $offset the timezone offset in seconds from UTC
* @property-read integer $offsetHours the timezone offset in hours from UTC
* @property-read integer $dst daylight savings time indicator, 1 if DST, 0 otherwise
* @property-read boolean $utc checks if the timezone is UTC, true if UTC, false otherwise
* @property-read string $timezoneName
* @property-read string $tzName
*
Expand Down Expand Up @@ -429,6 +430,9 @@ public function __get($name)

case 'dst':
return $this->format('I') == '1';

case 'utc':
return $this->format('Z') == 0;

case 'timezone':
return $this->getTimezone();
Expand Down
17 changes: 17 additions & 0 deletions tests/GettersTest.php
Expand Up @@ -123,6 +123,23 @@ public function testGetDstTrue()
$this->assertTrue(Carbon::createFromDate(2012, 7, 1, 'America/Toronto')->dst);
}

public function testGetUtcFalse()
{
$this->assertFalse(Carbon::createFromDate(2013, 1, 1, 'America/Toronto')->utc);
$this->assertFalse(Carbon::createFromDate(2013, 1, 1, 'Europe/Paris')->utc);
}
public function testGetUtcTrue()
{
$this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Atlantic/Reykjavik')->utc);
$this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Europe/Lisbon')->utc);
$this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Africa/Casablanca')->utc);
$this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Africa/Dakar')->utc);
$this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Europe/Dublin')->utc);
$this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Europe/London')->utc);
$this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'UTC')->utc);
$this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'GMT')->utc);
}

public function testOffsetForTorontoWithDST()
{
$this->assertSame(-18000, Carbon::createFromDate(2012, 1, 1, 'America/Toronto')->offset);
Expand Down