add admin timetable
This commit is contained in:
@@ -8,6 +8,12 @@
|
||||
|
||||
namespace common\components;
|
||||
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\i18n\Formatter;
|
||||
|
||||
class DateUtil
|
||||
@@ -16,12 +22,13 @@ class DateUtil
|
||||
* Get UTC today @00:00:00 .
|
||||
* Helper method to generate date for mysql
|
||||
*
|
||||
* @return \DateTime
|
||||
* @return DateTime
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function todayStart( ){
|
||||
$d2 = new \DateTime();
|
||||
$d2->setTimezone( new \DateTimeZone( "UTC" ) );
|
||||
$d2->setTime(0, 0, 0);
|
||||
$d2 = new DateTime();
|
||||
$d2->setTimezone( new DateTimeZone('UTC') );
|
||||
$d2->setTime(0, 0);
|
||||
return $d2;
|
||||
}
|
||||
|
||||
@@ -29,13 +36,14 @@ class DateUtil
|
||||
* Get UTC t @00:00:00 .
|
||||
* Helper method to generate date for mysql
|
||||
*
|
||||
* @return \DateTime
|
||||
* @return DateTime
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function tomorrowStart( ){
|
||||
$d2 = new \DateTime();
|
||||
$d2->add(new \DateInterval('P1D'));
|
||||
$d2->setTimezone( new \DateTimeZone( "UTC" ) );
|
||||
$d2->setTime(0, 0, 0);
|
||||
$d2 = new DateTime();
|
||||
$d2->add(new DateInterval('P1D'));
|
||||
$d2->setTimezone( new DateTimeZone('UTC') );
|
||||
$d2->setTime(0, 0);
|
||||
return $d2;
|
||||
}
|
||||
|
||||
@@ -44,11 +52,11 @@ class DateUtil
|
||||
public static function addMonth($timestamp, $monthCount = 1)
|
||||
{
|
||||
|
||||
if ($timestamp instanceof \DateTime) {
|
||||
if ($timestamp instanceof DateTime) {
|
||||
$d1 = $timestamp;
|
||||
} else {
|
||||
|
||||
$d1 = new \DateTime();
|
||||
$d1 = new DateTime();
|
||||
|
||||
if (isset($timestamp)) {
|
||||
$d1->setTimestamp($timestamp);
|
||||
@@ -63,28 +71,34 @@ class DateUtil
|
||||
$day = $d1->format('d');
|
||||
|
||||
$year += floor($monthToAdd / 12);
|
||||
$monthToAdd = $monthToAdd % 12;
|
||||
$monthToAdd %= 12;
|
||||
$month += $monthToAdd;
|
||||
if ($month > 12) {
|
||||
$year++;
|
||||
$month = $month % 12;
|
||||
if ($month === 0)
|
||||
$month %= 12;
|
||||
if ($month === 0) {
|
||||
$month = 12;
|
||||
}
|
||||
}
|
||||
|
||||
if (!checkdate($month, $day, $year)) {
|
||||
$d2 = \DateTime::createFromFormat('Y-n-j', $year . '-' . $month . '-1');
|
||||
$d2 = DateTime::createFromFormat('Y-n-j', $year . '-' . $month . '-1');
|
||||
$d2->modify('last day of');
|
||||
} else {
|
||||
$d2 = \DateTime::createFromFormat('Y-n-d', $year . '-' . $month . '-' . $day);
|
||||
$d2 = DateTime::createFromFormat('Y-n-d', $year . '-' . $month . '-' . $day);
|
||||
}
|
||||
$d2->setTime(0, 0, 0);
|
||||
$d2->setTime(0, 0);
|
||||
|
||||
|
||||
return $d2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dateTimeObject
|
||||
* @return string
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public static function formatUtc($dateTimeObject)
|
||||
{
|
||||
$formatter = new Formatter;
|
||||
@@ -93,6 +107,11 @@ class DateUtil
|
||||
return $formatter->asDatetime($dateTimeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dateTimeObject
|
||||
* @return string
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public static function formatDateUtc($dateTimeObject)
|
||||
{
|
||||
$formatter = new Formatter;
|
||||
@@ -103,9 +122,27 @@ class DateUtil
|
||||
|
||||
public static function parseDate($dateString){
|
||||
|
||||
$date = \DateTime::createFromFormat("Y.m.d", $dateString, new \DateTimeZone( 'UTC'));
|
||||
$date->setTime(0, 0, 0);
|
||||
$date = DateTime::createFromFormat('Y.m.d', $dateString, new DateTimeZone( 'UTC'));
|
||||
$date->setTime(0, 0);
|
||||
return $date;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @param integer $weekDay Numeric representation of the day of the week. @See https://www.php.net/manual/en/function.date.php
|
||||
* @return string
|
||||
*/
|
||||
public static function getLocalDayName($weekDay){
|
||||
$translations = [
|
||||
0 => Yii::t('common', 'Sunday'),
|
||||
1 => Yii::t('common', 'Monday'),
|
||||
2 => Yii::t('common', 'Tuesday'),
|
||||
3 => Yii::t('common', 'Wednesday'),
|
||||
4 => Yii::t('common', 'Thursday'),
|
||||
5 => Yii::t('common', 'Friday'),
|
||||
6 => Yii::t('common', 'Saturday'),
|
||||
7 => Yii::t('common', 'Sunday'),
|
||||
];
|
||||
return $translations[$weekDay];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user