eee
This commit is contained in:
@@ -47,20 +47,21 @@ class Kiri
|
||||
|
||||
|
||||
/**
|
||||
* @param $className
|
||||
* @param string|array $className
|
||||
* @param array $construct
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createObject($className, array $construct = []): mixed
|
||||
public static function createObject(string|array $className, array $construct = []): mixed
|
||||
{
|
||||
$container = static::getContainer();
|
||||
if (is_string($className) && class_exists($className)) {
|
||||
$object = static::getContainer()->get($className);
|
||||
$object = $container->get($className);
|
||||
return self::configure($object, $construct);
|
||||
} else if (is_array($className) && isset($className['class'])) {
|
||||
$class = $className['class'];
|
||||
unset($className['class']);
|
||||
return static::getContainer()->make($class, $construct, $className);
|
||||
return $container->make($class, $construct, $className);
|
||||
} else if (is_callable($className, TRUE)) {
|
||||
return call_user_func($className, $construct);
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,6 @@ declare(strict_types=1);
|
||||
namespace Kiri\Core;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class DateFormat
|
||||
* @package Kiri\Core
|
||||
@@ -18,87 +17,99 @@ namespace Kiri\Core;
|
||||
class DateFormat
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $time
|
||||
* @return bool|false|int|string
|
||||
*/
|
||||
private static function check($time): bool|int|string
|
||||
{
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
} else if (is_numeric($time)) {
|
||||
$length = strlen((string)$time);
|
||||
if ($length != 10 && $length != 13) {
|
||||
return false;
|
||||
}
|
||||
} else if (is_string($time)) {
|
||||
$time = strtotime($time);
|
||||
}
|
||||
|
||||
if (date('Y-m-d', $time)) {
|
||||
return $time;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $time
|
||||
* @return bool|false|int
|
||||
*
|
||||
* 获取指定日期当周第一天的时间
|
||||
*/
|
||||
public static function getWeekCurrentDay($time = null): bool|int
|
||||
{
|
||||
if (!($time = static::check($time))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$time = strtotime('-' . (date('N') - 1) . 'days', $time);
|
||||
|
||||
return strtotime(date('Y-m-d'), $time);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $time
|
||||
* @return bool|false|int
|
||||
*
|
||||
* 获取指定日期当月第一天的时间
|
||||
*/
|
||||
public static function getMonthCurrentDay($time = null): bool|int
|
||||
{
|
||||
if (!($time = static::check($time))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strtotime(date('Y-m', $time) . '-01');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $time
|
||||
* @return bool|int|string 指定的月份有几天
|
||||
* 指定的月份有几天
|
||||
*/
|
||||
public static function getMonthTotalDay($time): bool|int|string
|
||||
{
|
||||
if (!($time = static::check($time))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return date('t', $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $startTime
|
||||
* @param null $endTime
|
||||
* @return string
|
||||
*/
|
||||
public static function mtime($startTime, $endTime = null): string
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public static function DaySecond(): int
|
||||
{
|
||||
if ($endTime === null) {
|
||||
$endTime = microtime(true);
|
||||
}
|
||||
return sprintf('%.7f', $endTime - $startTime);
|
||||
}
|
||||
$time = strtotime(date('Y-m-d', strtotime('+1days')));
|
||||
|
||||
return $time - time();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $time
|
||||
* @return bool|false|int|string
|
||||
*/
|
||||
private static function check($time): bool|int|string
|
||||
{
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
} else if (is_numeric($time)) {
|
||||
$length = strlen((string)$time);
|
||||
if ($length != 10 && $length != 13) {
|
||||
return false;
|
||||
}
|
||||
} else if (is_string($time)) {
|
||||
$time = strtotime($time);
|
||||
}
|
||||
|
||||
if (date('Y-m-d', $time)) {
|
||||
return $time;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $time
|
||||
* @return bool|false|int
|
||||
*
|
||||
* 获取指定日期当周第一天的时间
|
||||
*/
|
||||
public static function getWeekCurrentDay($time = null): bool|int
|
||||
{
|
||||
if (!($time = static::check($time))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$time = strtotime('-' . (date('N') - 1) . 'days', $time);
|
||||
|
||||
return strtotime(date('Y-m-d'), $time);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $time
|
||||
* @return bool|false|int
|
||||
*
|
||||
* 获取指定日期当月第一天的时间
|
||||
*/
|
||||
public static function getMonthCurrentDay($time = null): bool|int
|
||||
{
|
||||
if (!($time = static::check($time))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strtotime(date('Y-m', $time) . '-01');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $time
|
||||
* @return bool|int|string 指定的月份有几天
|
||||
* 指定的月份有几天
|
||||
*/
|
||||
public static function getMonthTotalDay($time): bool|int|string
|
||||
{
|
||||
if (!($time = static::check($time))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return date('t', $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $startTime
|
||||
* @param null $endTime
|
||||
* @return string
|
||||
*/
|
||||
public static function mtime($startTime, $endTime = null): string
|
||||
{
|
||||
if ($endTime === null) {
|
||||
$endTime = microtime(true);
|
||||
}
|
||||
return sprintf('%.7f', $endTime - $startTime);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user