Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Giovanni Lovato
committed
Sep 28, 2013
1 parent
7f2cc0c
commit a71fef2
Showing
2 changed files
with
65 additions
and
35 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 |
---|---|---|
@@ -1 +1,31 @@ | ||
<?php | ||
namespace Bread\Types; | ||
|
||
use DateTimeZone; | ||
|
||
class DateTime extends \DateTime | ||
{ | ||
|
||
public function diff($datetime, $absolute = null) | ||
{ | ||
$interval = parent::diff($datetime, $absolute); | ||
return DateInterval::createFromDateInterval($interval); | ||
} | ||
|
||
public static function __set_state(array $array) | ||
{ | ||
$datetime = parent::__set_state($array); | ||
return static::createFromDateTime($datetime); | ||
} | ||
|
||
public static function createFromFormat($format, $time, $timezone = null) | ||
{ | ||
$datetime = call_user_func_array(array('parent', 'createFromFormat'), func_get_args()); | ||
return static::createFromDateTime($datetime); | ||
} | ||
|
||
public static function createFromDateTime($datetime) | ||
{ | ||
return new static($datetime->format('Y-m-d H:i:s'), $datetime->getTimezone()); | ||
} | ||
} |