Files
digital-psychology/apps/api/internal/service/home/shichen.go
T
jackyu66gitandCursor 89756f65b4 feat(ECR-012–016): 合规、题库、时辰刷新、头像、MBTI OEJTS 与埋点
落地输入合规、探索题库、报告日/时辰刷新、账号头像、OEJTS 量表,并补齐 H5 埋点与 Admin 漏斗;同步 ESS 工件、切至自建 Git、清理 GitHub Actions。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-13 01:27:58 +08:00

33 lines
788 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package home
import (
"time"
)
var shichenNames = [12]string{"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}
// ShichenWindow is the current Chinese double-hour window.
type ShichenWindow struct {
Index int
Name string
Start time.Time
End time.Time
}
// CurrentShichen returns the 十二时辰 window for now (子时 23:0001:00 …).
func CurrentShichen(now time.Time) ShichenWindow {
h := now.Hour()
idx := ((h + 1) % 24) / 2
startHour := (idx*2 + 23) % 24
start := time.Date(now.Year(), now.Month(), now.Day(), startHour, 0, 0, 0, now.Location())
if start.After(now) {
start = start.Add(-24 * time.Hour)
}
return ShichenWindow{
Index: idx,
Name: shichenNames[idx],
Start: start,
End: start.Add(2 * time.Hour),
}
}