Skip to content

Commit

Permalink
Starting to replace Carbon with Time
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Apr 21, 2014
1 parent 499a26e commit 012ca14
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Database/Type/DateTimeType.php
Expand Up @@ -28,7 +28,7 @@ class DateTimeType extends \Cake\Database\Type {
*
* @var string
*/
public static $dateTimeClass = 'Carbon\Carbon';
public static $dateTimeClass = 'Cake\Utility\Time';

/**
* String format to use for DateTime parsing
Expand Down
30 changes: 15 additions & 15 deletions tests/TestCase/Database/Type/DateTimeTypeTest.php
Expand Up @@ -17,7 +17,7 @@
use Cake\Database\Type;
use Cake\Database\Type\DateTimeType;
use Cake\TestSuite\TestCase;
use Carbon\Carbon;
use Cake\Utility\Time;

/**
* Test for the DateTime type.
Expand All @@ -44,7 +44,7 @@ public function testToPHP() {
$this->assertNull($this->type->toPHP(null, $this->driver));

$result = $this->type->toPHP('2001-01-04 12:13:14', $this->driver);
$this->assertInstanceOf('Carbon\Carbon', $result);
$this->assertInstanceOf('Cake\Utility\Time', $result);
$this->assertEquals('2001', $result->format('Y'));
$this->assertEquals('01', $result->format('m'));
$this->assertEquals('04', $result->format('d'));
Expand All @@ -64,7 +64,7 @@ public function testToPHP() {
public function testToPHPIncludingMilliseconds() {
$in = '2014-03-24 20:44:36.315113';
$result = $this->type->toPHP($in, $this->driver);
$this->assertInstanceOf('Carbon\Carbon', $result);
$this->assertInstanceOf('Cake\Utility\Time', $result);
}

/**
Expand All @@ -77,7 +77,7 @@ public function testToDatabase() {
$result = $this->type->toDatabase($value, $this->driver);
$this->assertEquals($value, $result);

$date = new Carbon('2013-08-12 15:16:17');
$date = new Time('2013-08-12 15:16:17');
$result = $this->type->toDatabase($date, $this->driver);
$this->assertEquals('2013-08-12 15:16:17', $result);
}
Expand All @@ -98,54 +98,54 @@ public function marshalProvider() {
['2013-nope!', '2013-nope!'],

// valid string types
['1392387900', new Carbon('@1392387900')],
[1392387900, new Carbon('@1392387900')],
['2014-02-14', new Carbon('2014-02-14')],
['2014-02-14 13:14:15', new Carbon('2014-02-14 13:14:15')],
['1392387900', new Time('@1392387900')],
[1392387900, new Time('@1392387900')],
['2014-02-14', new Time('2014-02-14')],
['2014-02-14 13:14:15', new Time('2014-02-14 13:14:15')],

// valid array types
[
['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15],
new Carbon('2014-02-14 13:14:15')
new Time('2014-02-14 13:14:15')
],
[
[
'year' => 2014, 'month' => 2, 'day' => 14,
'hour' => 1, 'minute' => 14, 'second' => 15,
'meridian' => 'am'
],
new Carbon('2014-02-14 01:14:15')
new Time('2014-02-14 01:14:15')
],
[
[
'year' => 2014, 'month' => 2, 'day' => 14,
'hour' => 1, 'minute' => 14, 'second' => 15,
'meridian' => 'pm'
],
new Carbon('2014-02-14 13:14:15')
new Time('2014-02-14 13:14:15')
],
[
[
'year' => 2014, 'month' => 2, 'day' => 14,
],
new Carbon('2014-02-14 00:00:00')
new Time('2014-02-14 00:00:00')
],

// Invalid array types
[
['year' => 'farts', 'month' => 'derp'],
new Carbon(date('Y-m-d 00:00:00'))
new Time(date('Y-m-d 00:00:00'))
],
[
['year' => 'farts', 'month' => 'derp', 'day' => 'farts'],
new Carbon(date('Y-m-d 00:00:00'))
new Time(date('Y-m-d 00:00:00'))
],
[
[
'year' => '2014', 'month' => '02', 'day' => '14',
'hour' => 'farts', 'minute' => 'farts'
],
new Carbon('2014-02-14 00:00:00')
new Time('2014-02-14 00:00:00')
],
];
}
Expand Down
26 changes: 13 additions & 13 deletions tests/TestCase/Database/Type/DateTypeTest.php
Expand Up @@ -17,7 +17,7 @@
use Cake\Database\Type;
use Cake\Database\Type\DateType;
use Cake\TestSuite\TestCase;
use Carbon\Carbon;
use Cake\Utility\Time;

/**
* Test for the Date type.
Expand Down Expand Up @@ -70,11 +70,11 @@ public function testToDatabase() {
$result = $this->type->toDatabase($value, $this->driver);
$this->assertEquals($value, $result);

$date = new Carbon('2013-08-12');
$date = new Time('2013-08-12');
$result = $this->type->toDatabase($date, $this->driver);
$this->assertEquals('2013-08-12', $result);

$date = new Carbon('2013-08-12 15:16:18');
$date = new Time('2013-08-12 15:16:18');
$result = $this->type->toDatabase($date, $this->driver);
$this->assertEquals('2013-08-12', $result);
}
Expand All @@ -85,7 +85,7 @@ public function testToDatabase() {
* @return array
*/
public function marshalProvider() {
$date = new Carbon('@1392387900');
$date = new Time('@1392387900');
$date->setTime(0, 0, 0);

return [
Expand All @@ -100,52 +100,52 @@ public function marshalProvider() {
// valid string types
['1392387900', $date],
[1392387900, $date],
['2014-02-14', new Carbon('2014-02-14')],
['2014-02-14 13:14:15', new Carbon('2014-02-14 00:00:00')],
['2014-02-14', new Time('2014-02-14')],
['2014-02-14 13:14:15', new Time('2014-02-14 00:00:00')],

// valid array types
[
['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15],
new Carbon('2014-02-14 00:00:00')
new Time('2014-02-14 00:00:00')
],
[
[
'year' => 2014, 'month' => 2, 'day' => 14,
'hour' => 1, 'minute' => 14, 'second' => 15,
'meridian' => 'am'
],
new Carbon('2014-02-14 00:00:00')
new Time('2014-02-14 00:00:00')
],
[
[
'year' => 2014, 'month' => 2, 'day' => 14,
'hour' => 1, 'minute' => 14, 'second' => 15,
'meridian' => 'pm'
],
new Carbon('2014-02-14 00:00:00')
new Time('2014-02-14 00:00:00')
],
[
[
'year' => 2014, 'month' => 2, 'day' => 14,
],
new Carbon('2014-02-14 00:00:00')
new Time('2014-02-14 00:00:00')
],

// Invalid array types
[
['year' => 'farts', 'month' => 'derp'],
new Carbon(date('Y-m-d 00:00:00'))
new Time(date('Y-m-d 00:00:00'))
],
[
['year' => 'farts', 'month' => 'derp', 'day' => 'farts'],
new Carbon(date('Y-m-d 00:00:00'))
new Time(date('Y-m-d 00:00:00'))
],
[
[
'year' => '2014', 'month' => '02', 'day' => '14',
'hour' => 'farts', 'minute' => 'farts'
],
new Carbon('2014-02-14 00:00:00')
new Time('2014-02-14 00:00:00')
],
];
}
Expand Down
24 changes: 12 additions & 12 deletions tests/TestCase/Database/Type/TimeTypeTest.php
Expand Up @@ -17,7 +17,7 @@
use Cake\Database\Type;
use Cake\Database\Type\TimeType;
use Cake\TestSuite\TestCase;
use Carbon\Carbon;
use Cake\Utility\Time;

/**
* Test for the Time type.
Expand Down Expand Up @@ -70,11 +70,11 @@ public function testToDatabase() {
$result = $this->type->toDatabase($value, $this->driver);
$this->assertEquals($value, $result);

$date = new Carbon('16:30:15');
$date = new Time('16:30:15');
$result = $this->type->toDatabase($date, $this->driver);
$this->assertEquals('16:30:15', $result);

$date = new Carbon('2013-08-12 15:16:18');
$date = new Time('2013-08-12 15:16:18');
$result = $this->type->toDatabase($date, $this->driver);
$this->assertEquals('15:16:18', $result);
}
Expand All @@ -85,7 +85,7 @@ public function testToDatabase() {
* @return array
*/
public function marshalProvider() {
$date = new Carbon('@1392387900');
$date = new Time('@1392387900');

return [
// invalid types.
Expand All @@ -99,48 +99,48 @@ public function marshalProvider() {
// valid string types
['1392387900', $date],
[1392387900, $date],
['13:10:10', new Carbon('13:10:10')],
['2014-02-14 13:14:15', new Carbon('2014-02-14 13:14:15')],
['13:10:10', new Time('13:10:10')],
['2014-02-14 13:14:15', new Time('2014-02-14 13:14:15')],

// valid array types
[
['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15],
new Carbon('2014-02-14 13:14:15')
new Time('2014-02-14 13:14:15')
],
[
[
'year' => 2014, 'month' => 2, 'day' => 14,
'hour' => 1, 'minute' => 14, 'second' => 15,
'meridian' => 'am'
],
new Carbon('2014-02-14 01:14:15')
new Time('2014-02-14 01:14:15')
],
[
[
'year' => 2014, 'month' => 2, 'day' => 14,
'hour' => 1, 'minute' => 14, 'second' => 15,
'meridian' => 'pm'
],
new Carbon('2014-02-14 13:14:15')
new Time('2014-02-14 13:14:15')
],
[
[
'hour' => 1, 'minute' => 14, 'second' => 15,
],
new Carbon('01:14:15')
new Time('01:14:15')
],

// Invalid array types
[
['hour' => 'nope', 'minute' => 14, 'second' => 15],
new Carbon(date('Y-m-d 00:14:15'))
new Time(date('Y-m-d 00:14:15'))
],
[
[
'year' => '2014', 'month' => '02', 'day' => '14',
'hour' => 'nope', 'minute' => 'nope'
],
new Carbon('2014-02-14 00:00:00')
new Time('2014-02-14 00:00:00')
],
];
}
Expand Down

0 comments on commit 012ca14

Please sign in to comment.