Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
87.50% |
7 / 8 |
CRAP | |
88.24% |
15 / 17 |
Clock | |
0.00% |
0 / 1 |
|
87.50% |
7 / 8 |
8.10 | |
88.24% |
15 / 17 |
getTime | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getTimeAsInt | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getTimeAsDTI | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
getRequestTime | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
getRequestTimeAsInt | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getRequestTimeAsImmutable | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
getToday | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getTodayAsInt | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
<?php | |
namespace Puyo\Time; | |
/** | |
* 時計 | |
* | |
* システム内では、時刻はここから取得する。 | |
* DateTimeImmutable で返す機能もあるため php-5.5 以上が必要 | |
* @author y.kushida | |
* @version 1.1.1 | |
* @uses >= php-5.5 | |
*/ | |
class Clock | |
{ | |
/** | |
* 現在時刻を返す | |
* @return \DateTime | |
*/ | |
public function getTime() { | |
return new \DateTime(); | |
} | |
/** | |
* 現在時刻を返す | |
* @return int | |
*/ | |
public function getTimeAsInt() { | |
$d = $this->getTime(); | |
return $d->getTimestamp(); | |
} | |
/** | |
* 現在時刻を返す | |
* @return \DateTimeImmutable | |
* @throws \Exception | |
*/ | |
public function getTimeAsDTI() { | |
$d = $this->getTime(); | |
return new \DateTimeImmutable($d->format('c')); | |
} | |
/** | |
* scriptの開始時刻を返す | |
* @return \DateTime | |
*/ | |
public function getRequestTime() { | |
$intUnixTime = $this->getRequestTimeAsInt(); | |
$result = new \DateTime('@'.$intUnixTime); | |
$timeZone = new \DateTimeZone(date_default_timezone_get()); | |
$result = $result->setTimeZone($timeZone); | |
return $result; | |
} | |
/** | |
* scriptの開始時刻を返す | |
* @return int | |
*/ | |
public function getRequestTimeAsInt() { | |
return $_SERVER['REQUEST_TIME']; | |
} | |
/** | |
* scriptの開始時刻を返す | |
* @return \DateTimeImmutable | |
* @throws \Exception | |
*/ | |
public function getRequestTimeAsImmutable() { | |
$intUnixTime = $this->getRequestTimeAsInt(); | |
$timeZone = new \DateTimeZone(date_default_timezone_get()); | |
$result = new \DateTimeImmutable('@'.$intUnixTime, $timeZone); | |
return $result; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getToday() { | |
return new \DateTime($this->getRequestTime()->format('Y-m-d')); | |
} | |
/** | |
* @return int | |
*/ | |
public function getTodayAsInt() { | |
return strtotime($this->getToday()->format('Y-m-d')); | |
} | |
} |