Browse Source

✨ feat: 增加乐跑记录时间选择

Pchen. 4 months ago
parent
commit
a70580d903
1 changed files with 15 additions and 0 deletions
  1. 15 0
      src/utils/util.js

+ 15 - 0
src/utils/util.js

@@ -6,6 +6,21 @@ export function timeFix() {
   return hour < 9 ? '早上好' : hour <= 11 ? '上午好' : hour <= 13 ? '中午好' : hour < 20 ? '下午好' : '晚上好'
   return hour < 9 ? '早上好' : hour <= 11 ? '上午好' : hour <= 13 ? '中午好' : hour < 20 ? '下午好' : '晚上好'
 }
 }
 
 
+/**
+ * 学期判断
+ * 返回 [学期开始时间戳, 当前时间戳]
+ */
+export function getSemesterTimestamps() {
+  const now = new Date()
+  const year = now.getFullYear()
+  const feb1ThisYear = new Date(year, 1, 1, 0, 0, 0, 0)     // 当年 2-01
+  const aug31ThisYear = new Date(year, 7, 31, 0, 0, 0, 0)  // 当年 8-31
+  // 下学期:2 月 1 日 ~ 8 月 31 日
+  // 上学期:8 月 31 日 ~ 次年 2 月 1 日
+  // 1 月属于上一年的上学期
+  return [(now >= feb1ThisYear && now < aug31ThisYear) ? feb1ThisYear : new Date(now < feb1ThisYear ? year - 1 : year, 7, 31, 0, 0, 0, 0).getTime(), now.getTime()]
+}
+
 export async function getNotice(key) {
 export async function getNotice(key) {
   try {
   try {
     const res = await GetNotice({ key })
     const res = await GetNotice({ key })