From 171a5597caa5887da782db59ca4ab643b163b84d Mon Sep 17 00:00:00 2001
From: husq <931347610@qq.com>
Date: Sat, 28 Oct 2023 20:52:52 +0800
Subject: [PATCH] 实施航线逻辑修改、页面修改
---
src/utils/time.ts | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/src/utils/time.ts b/src/utils/time.ts
index 2d450de..c7b9d9a 100644
--- a/src/utils/time.ts
+++ b/src/utils/time.ts
@@ -66,3 +66,41 @@
const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())
return Y + M + D
}
+
+// 获取时间戳对应的日期
+export const getDateFromTimestamp = (timestamp:number) => {
+ const date = new Date(timestamp)
+ const year = date.getFullYear()
+ const month = date.getMonth() + 1
+ const day = date.getDate()
+ const hours = date.getHours()
+ const minutes = date.getMinutes()
+ const seconds = date.getSeconds()
+ return { year, month, day, hours, minutes, seconds }
+}
+
+// 将日期设置为今天的日期,返回时间戳
+export const setTodayTime = (dateObj:any) => {
+ const today = new Date()
+ const year = today.getFullYear()
+ const month = today.getMonth()
+ const day = today.getDate()
+ const { hours, minutes, seconds } = dateObj
+ return new Date(year, month, day, hours, minutes, seconds).getTime()
+}
+
+// 判断任务状态是否是当天进行对比
+export const isToday = (timestamp:number) => {
+ const { hours, minutes, seconds } = getDateFromTimestamp(timestamp)
+ const todayTaskTimestamp = setTodayTime({ hours, minutes, seconds })
+ // 判断传过来的时间戳是否是今天任务时间时间戳
+ if (timestamp === todayTaskTimestamp) {
+ return true
+ } else if (todayTaskTimestamp < timestamp) {
+ return false
+ } else {
+ const oneDayTimestamp = 24 * 60 * 60 * 1000
+ timestamp += oneDayTimestamp
+ isToday(timestamp)
+ }
+}
--
Gitblit v1.9.3