From 127d4b02c2ef74cd8744490803fee935871c3329 Mon Sep 17 00:00:00 2001 From: Chaim Date: Sat, 25 Jul 2020 10:00:37 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E9=97=A8=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ src/common.php | 2 +- src/facade/Times.php | 5 +++-- src/helper/Times.php | 30 +++++++++++++++++++++--------- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6be95ae..23833e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v6.0.98 / 2020-07-25 +- 优化时间门面 + ## v6.0.97 / 2020-07-23 - 增加小数门面 diff --git a/src/common.php b/src/common.php index 14d3ecf..20174cf 100644 --- a/src/common.php +++ b/src/common.php @@ -26,7 +26,7 @@ use think\db\exception\DbException; /** * 定义当前版本 */ -const VERSION = '6.0.97'; +const VERSION = '6.0.98'; if (!function_exists('get_ip_info')) { /** diff --git a/src/facade/Times.php b/src/facade/Times.php index 2887d6e..19092ff 100644 --- a/src/facade/Times.php +++ b/src/facade/Times.php @@ -36,8 +36,9 @@ use think\Facade; * @method static string getUDate() 当前时间戳 * @method static string getTimeDifference(string $end_time, string $start_time) 计算两个时间差 * @method static string dateToTimestamp(string $date) 将指定日期转换为时间戳 - * @method static string dateRear(string $format = "Y-m-d H:i:s", int $mun = 10) f获取某个时间之后的时间 - * @method static string dateBefore(string $format = "Y-m-d H:i:s", int $mun = 10) 获取某个时间之前的时间 + * @method static string timestampToDate(int $time, string $format = "Y-m-d H:i:s") 将指定时间戳转换为日期 + * @method static string dateRear(string $format = "Y-m-d H:i:s", int $mun = 10) 在当前时间之后的时间 + * @method static string dateBefore(string $format = "Y-m-d H:i:s", int $mun = 10) 在当前时间之前的时间 * @method static bool checkIsBetweenTime(string $start, string $end) 判断当前的时分是否在指定的时间段内 */ class Times extends Facade diff --git a/src/helper/Times.php b/src/helper/Times.php index 5df1fc9..cb6462c 100644 --- a/src/helper/Times.php +++ b/src/helper/Times.php @@ -71,7 +71,7 @@ class Times { date_default_timezone_set('Asia/Shanghai'); $end_time = strtotime($end_time); - $start_time = $start_time == '' ? strtotime(self::getData('Y-m-d H:i:s')) : strtotime($start_time); + $start_time = $start_time == '' ? time() : strtotime($start_time); return $end_time - $start_time; } @@ -87,27 +87,39 @@ class Times } /** - * 获取某个时间之后的时间 + * 将指定时间戳转换为日期 + * @param string $format + * @param int $time + * @return false|string + */ + public function timestampToDate(int $time, string $format = "Y-m-d H:i:s") + { + date_default_timezone_set('Asia/Shanghai'); + return date($format, $time); + } + + /** + * 在当前时间之前的时间 * @param string $format 格式 - * @param int $mun 多少分钟 + * @param int $mun 多少秒 * @return false|string */ - public function dateRear(string $format = "Y-m-d H:i:s", int $mun = 10) + public function dateBefore(string $format = "Y-m-d H:i:s", int $mun = 60) { date_default_timezone_set('Asia/Shanghai'); - return date($format, strtotime(self::getData()) + $mun); + return date($format, time() - $mun); } /** - * 获取某个时间之前的时间 + * 在当前时间之后的时间 * @param string $format 格式 - * @param int $mun 多少分钟 + * @param int $mun 多少秒 * @return false|string */ - public function dateBefore(string $format = "Y-m-d H:i:s", int $mun = 10) + public function dateRear(string $format = "Y-m-d H:i:s", int $mun = 60) { date_default_timezone_set('Asia/Shanghai'); - return date($format, strtotime(self::getData()) - $mun); + return date($format, time() + $mun); }