door manager

This commit is contained in:
Schneider Roland
2022-05-04 19:41:18 +02:00
parent fb39d6599e
commit 946799a598
20 changed files with 8872 additions and 220 deletions

View File

@@ -18,6 +18,12 @@ use yii\i18n\Formatter;
class DateUtil
{
public static function fromUnixTimeStamp($timestamp){
$dt = DateUtil::utcDate();
$dt->setTimestamp($timestamp);
return $dt;
}
/**
* Get UTC today @00:00:00 .
* Helper method to generate date for mysql
@@ -25,13 +31,49 @@ class DateUtil
* @return DateTime
* @throws Exception
*/
public static function todayStart( ){
$d2 = new DateTime();
public static function todayStart(){
$d2 = new DateTime();
return DateUtil::utcDate($d2);
}
/**
* @param $date \DateTime optional. The date to set as utc date. If not set, new DateTime() will be used
* @return DateTime the datetime object with time reset and utc timezone
*/
public static function utcDate($date = null){
$d2 = isset($date ) ? $date : new DateTime();
$d2 = DateUtil::withTimeZoneUTC($d2);
return DateUtil::resetTime($d2);
}
/**
* @param $date \DateTime optional. If not set,defaults to : new DateTime() .
* @return DateTime
*/
public static function utcDateTime($date = null){
$d2 = isset($date ) ? $date : new DateTime();
return DateUtil::withTimeZoneUTC($d2);
}
/**
* @param $date \DateTime
* @return DateTime
*/
public static function withTimeZoneUTC( $date = null){
$d2 = isset($date ) ? $date : new DateTime();
$d2->setTimezone( new DateTimeZone('UTC') );
$d2->setTime(0, 0);
return $d2;
}
/**
* @param $dateTime \DateTime
* @return \DateTime
*/
public static function resetTime($dateTime){
$dateTime->setTime(0, 0);
return $dateTime;
}
/**
* Get UTC t @00:00:00 .
* Helper method to generate date for mysql
@@ -39,16 +81,12 @@ class DateUtil
* @return DateTime
* @throws Exception
*/
public static function tomorrowStart( ){
$d2 = new DateTime();
public static function tomorrowStart( $date = null){
$d2 = isset($date) ? $date : new DateTime();
$d2->add(new DateInterval('P1D'));
$d2->setTimezone( new DateTimeZone('UTC') );
$d2->setTime(0, 0);
return $d2;
return DateUtil::utcDate($d2);
}
public static function addMonth($timestamp, $monthCount = 1)
{
@@ -99,7 +137,7 @@ class DateUtil
* @return string
* @throws InvalidConfigException
*/
public static function formatUtc($dateTimeObject)
public static function formatDateTimeUtc($dateTimeObject)
{
$formatter = new Formatter;
$formatter->datetimeFormat = 'php:Y-m-d H:i:s';
@@ -127,6 +165,10 @@ class DateUtil
return $date;
}
public static function parseDateTime($dateTimeString){
return DateTime::createFromFormat('Y-m-d H:i:s', $dateTimeString, new DateTimeZone( 'UTC'));
}
/**
* @param integer $weekDay Numeric representation of the day of the week. @See https://www.php.net/manual/en/function.date.php
* @return string