Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
CRAP | |
94.44% |
17 / 18 |
Date | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
5.00 | |
94.44% |
17 / 18 |
fromUnixTime | |
0.00% |
0 / 1 |
2.01 | |
88.89% |
8 / 9 |
|||
toUnixTime | |
100.00% |
1 / 1 |
3 | |
100.00% |
9 / 9 |
<?php | |
namespace Popy\Calendar\Converter\UnixTimeConverter; | |
use Popy\Calendar\Converter\Conversion; | |
use Popy\Calendar\Converter\UnixTimeConverterInterface; | |
use Popy\Calendar\ValueObject\DateRepresentation\Standard; | |
/** | |
* Day in the year representation | |
* | |
* Fragment units are, usually, named as, and used as : | |
* 0 => months (format symbols m, etc ...) | |
* | |
* Transversal units are, usually, named as and used as : | |
* 0 => ISO 8601 year (format symbol o). | |
* 1 => ISO 8601 week number (format symbol W) | |
* 2 => ISO 8601 day index (format symbol N) | |
*/ | |
class Date implements UnixTimeConverterInterface | |
{ | |
/** | |
* @inheritDoc | |
*/ | |
public function fromUnixTime(Conversion $conversion) | |
{ | |
if (null === $res = $conversion->getTo()) { | |
return; | |
} | |
$from = $conversion->getFrom(); | |
$res = $res | |
->withUnixTime($from->getUnixTime()) | |
->withUnixMicroTime($from->getUnixMicroTime()) | |
->withTimezone($from->getTimezone()) | |
; | |
$conversion->setTo($res); | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public function toUnixTime(Conversion $conversion) | |
{ | |
$input = $conversion->getTo(); | |
if (null === $input->getUnixTime()) { | |
$input = $input->withUnixTime($conversion->getUnixTime()); | |
} | |
if (null === $input->getUnixMicroTime()) { | |
$input = $input->withUnixMicroTime($conversion->getUnixMicroTime()); | |
} | |
$conversion->setTo($input); | |
} | |
} |