battles/engine/datetime.php

27 lines
651 B
PHP
Raw Normal View History

2018-01-28 16:40:49 +00:00
<?php
namespace Oldcombats;
class DateTime extends \DateTime {
public function __construct($time = "now", $timezone = null) {
if(is_null($timezone)) {
$timezone = new \DateTimeZone("Europe/Moscow");
}
parent::__construct($time, $timezone);
}
public function isDay() {
$now = $this->getTimestamp();
$sunrise = date_sunrise($now, SUNFUNCS_RET_TIMESTAMP);
$sunset = date_sunset($now, SUNFUNCS_RET_TIMESTAMP);
return ($now > $sunrise && $now <= $sunset);
}
public function isNight() {
return (!$this->isDay());
}
public function getTimeOfDay() {
return ($this->isDay() ? 'day' : 'night');
}
}