Skip to content

Commit

Permalink
Tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Aug 21, 2016
1 parent b5b0ebb commit 0169b19
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 68 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
build
composer.lock
docs
vendor
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The ICanBoogie/DateTime package is free software.
It is released under the terms of the following BSD License.

Copyright (c) 2013-2015 by Olivier Laviale
Copyright (c) 2013-2016 by Olivier Laviale
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# customization

PACKAGE_NAME = ICanBoogie/DateTime
PACKAGE_VERSION = v1.1.0
PACKAGE_VERSION = v1.2

# do not edit the following lines

Expand Down
49 changes: 26 additions & 23 deletions lib/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,7 @@ static public function now()

if (!$now)
{
$now = empty($_SERVER['REQUEST_TIME'])
? new static
: (new static('@' . $_SERVER['REQUEST_TIME']))->local;
$now = empty($_SERVER['REQUEST_TIME']) ? new static : (new static('@' . $_SERVER['REQUEST_TIME']))->local;
}

return clone $now;
Expand Down Expand Up @@ -300,7 +298,7 @@ static public function right_now()
*
* @return DateTime
*/
static public function none($timezone='utc')
static public function none($timezone = 'utc')
{
return new static('0000-00-00', $timezone);
}
Expand All @@ -322,7 +320,7 @@ static public function none($timezone='utc')
* @param string $time Defaults to "now".
* @param \DateTimeZone|string|null $timezone
*/
public function __construct($time='now', $timezone=null)
public function __construct($time = 'now', $timezone = null)
{
if (is_string($timezone))
{
Expand All @@ -337,11 +335,14 @@ public function __construct($time='now', $timezone=null)
$timezone === null ? parent::__construct($time) : parent::__construct($time, $timezone);
}

/**
* @inheritdoc
*/
public function __get($property)
{
if (strpos($property, 'as_') === 0)
{
return call_user_func([ $this, 'format_' . $property ]);
return $this->{ 'format_' . $property }();
}

switch ($property)
Expand Down Expand Up @@ -604,25 +605,27 @@ public function __set($property, $value)
*/
public function __call($method, $arguments)
{
if (strpos($method, 'format_as_') === 0)
if (strpos($method, 'format_as_') !== 0)
{
$as = strtoupper(substr($method, strlen('format_as_')));
$format = constant(__CLASS__ . '::' . $as);
$value = $this->format($format);
throw new \BadMethodCallException("Unsupported method: $method.");
}

if ($as == 'RFC822' || $as == 'RFC1123')
{
$value = str_replace('+0000', 'GMT', $value);
}
else if ($as == 'ISO8601')
{
$value = str_replace('+0000', 'Z', $value);
}
$as = strtoupper(substr($method, strlen('format_as_')));
$format = constant(__CLASS__ . '::' . $as);
$value = $this->format($format);

return $value;
}
switch ($as)
{
case 'RFC822':
case 'RFC1123':
return str_replace('+0000', 'GMT', $value);

case 'ISO8601':
return str_replace('+0000', 'Z', $value);

throw new \BadMethodCallException("Unsupported method: $method.");
default:
return $value;
}
}

/**
Expand Down Expand Up @@ -661,7 +664,7 @@ public function setTimezone($timezone)
$timezone = date_default_timezone_get();
}

if (!($timezone instanceof \DateTimeZone))
if (!$timezone instanceof \DateTimeZone)
{
$timezone = new \DateTimeZone($timezone);
}
Expand Down Expand Up @@ -761,7 +764,7 @@ public function change(array $options, $cascade=false)
*
* @return DateTime
*/
public function with(array $options, $cascade=false)
public function with(array $options, $cascade = false)
{
$dt = clone $this;

Expand Down
2 changes: 2 additions & 0 deletions lib/TimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public function __construct($timezone)
* Returns the {@link $location}, {@link $name} and {@link $offset} properties.
*
* @throws PropertyNotDefined in attempt to get an unsupported property.
*
* @inheritdoc
*/
public function __get($property)
{
Expand Down
16 changes: 8 additions & 8 deletions tests/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1280,15 +1280,15 @@ public function test_localize()
$reference->localize('fr');
}

/**
* @expectedException \RuntimeException
*/
/**
* @expectedException \RuntimeException
*/
public function test_getting_undefined_property_should_throw_exception()
{
$date = DateTime::now();
$property = uniqid();
$date->$property;
}
{
$date = DateTime::now();
$property = uniqid();
$date->$property;
}
}

namespace ICanBoogie\DateTimeTest;
Expand Down
66 changes: 33 additions & 33 deletions tests/TimeZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ public function test_utc_case()
{
$this->assertEquals('UTC', TimeZone::from('utc')->name);
$this->assertEquals('UTC', TimeZone::from('UTC')->name);
$this->assertEquals('UTC', (new TimeZone('utc'))->name);
$this->assertEquals('UTC', (new TimeZone('UTC'))->name);
$this->assertEquals('UTC', (new TimeZone('utc'))->name);
$this->assertEquals('UTC', (new TimeZone('UTC'))->name);
}

public function test_should_create_from_php_datetimezone()
{
$name = 'Europe/Paris';
$z1 = new \DateTimeZone($name);
$z2 = TimeZone::from($z1);
{
$name = 'Europe/Paris';
$z1 = new \DateTimeZone($name);
$z2 = TimeZone::from($z1);

$this->assertSame($name, $z2->name);
}
$this->assertSame($name, $z2->name);
}

public function test_should_reuse_instance()
{
Expand All @@ -60,29 +60,29 @@ public function test_should_reuse_instance()
$this->assertSame($z1, $z2);
}

public function test_should_reuse_timezone()
{
$z1 = TimeZone::from('Europe/Paris');
$z2 = TimeZone::from($z1);

$this->assertSame($z1, $z2);
}

/**
* @expectedException \RuntimeException
*/
public function test_getting_undefined_property_should_throw_exception()
{
$property = uniqid();
$z1 = TimeZone::from('utc');
$z1->$property;
}

public function test_to_string()
{
$name = 'Europe/Paris';
$z1 = TimeZone::from($name);

$this->assertSame($name, (string) $z1);
}
public function test_should_reuse_timezone()
{
$z1 = TimeZone::from('Europe/Paris');
$z2 = TimeZone::from($z1);

$this->assertSame($z1, $z2);
}

/**
* @expectedException \RuntimeException
*/
public function test_getting_undefined_property_should_throw_exception()
{
$property = uniqid();
$z1 = TimeZone::from('utc');
$z1->$property;
}

public function test_to_string()
{
$name = 'Europe/Paris';
$z1 = TimeZone::from($name);

$this->assertSame($name, (string) $z1);
}
}

0 comments on commit 0169b19

Please sign in to comment.