feat: 날씨 사주 — 원국(만세력)·일진 해석·조후 날씨 궁합으로 오늘 점수와 할 일, 레벨로 이번 주·금전·연애·궁합·이달·올해
- 엔진(services/saju): 절입 시각을 천문 계산(KASI 대비 최대 41초), 지방평균시·서머타임 보정, 네 기둥, 십성·합충형파해원진·도화·홍염, 조후(한난조습)와 시간별 날씨 맞춤 - API: POST /v1/saju/reading, POST /v1/saju/match (레벨 5). 생년월일은 저장하지 않음, 레벨은 서버에서 잠금 - 화면(/saju): 오늘의 점수(사주+날씨 궁합)와 결정 카드(언제·할 것·조심할 것·좋은 흐름·입을 것·갈 곳), 내 기운(계절·날씨 장면 16종), 잠긴 것은 다음 하나와 남은 각 - 오늘 탭 아이콘 줄에 날씨 사주, 사주 보면 +10각 - GA4 saju_input·saju_view
This commit is contained in:
1 parent
03ad57bcaa
commit
0399942fb1
40 files changed
+3143
-7
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import { useSyncExternalStore } from 'react'
|
||||
|
||||
/** 날씨 사주에 쓰는 태어난 정보. 이 기기에만 저장하고, 계산할 때만 서버에 보낸다(서버는 남기지 않는다) */
|
||||
export type Birth = { y: number; m: number; d: number; hour: number | null; minute: number | null; place: string; gender: 'M' | 'F' | null }
|
||||
|
||||
const KEY = 'nalssigak.b.birth'
|
||||
|
||||
/** 태어난 곳: 시각을 그곳 경도로 맞춘다 (시·도청 경도) */
|
||||
export const BIRTH_PLACES: [string, string, number][] = [
|
||||
['seoul', '서울', 126.98],
|
||||
['busan', '부산', 129.08],
|
||||
['daegu', '대구', 128.6],
|
||||
['incheon', '인천', 126.71],
|
||||
['gwangju', '광주', 126.85],
|
||||
['daejeon', '대전', 127.38],
|
||||
['ulsan', '울산', 129.31],
|
||||
['sejong', '세종', 127.29],
|
||||
['gyeonggi', '경기', 127.01],
|
||||
['gangwon', '강원', 127.73],
|
||||
['chungbuk', '충북', 127.49],
|
||||
['chungnam', '충남', 126.67],
|
||||
['jeonbuk', '전북', 127.11],
|
||||
['jeonnam', '전남', 126.46],
|
||||
['gyeongbuk', '경북', 128.51],
|
||||
['gyeongnam', '경남', 128.69],
|
||||
['jeju', '제주', 126.5],
|
||||
]
|
||||
|
||||
export const placeLon = (key: string) => BIRTH_PLACES.find(([k]) => k === key)?.[2] ?? 127
|
||||
|
||||
function read(): Birth | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(KEY)
|
||||
return raw ? (JSON.parse(raw) as Birth) : null
|
||||
} catch {
|
||||
// 사파리 프라이빗 모드 등에서는 저장소를 못 쓴다 → 이번 방문엔 없는 것으로
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
let birth = read()
|
||||
const listeners = new Set<() => void>()
|
||||
const subscribe = (cb: () => void) => {
|
||||
listeners.add(cb)
|
||||
return () => listeners.delete(cb)
|
||||
}
|
||||
|
||||
export function setBirth(b: Birth | null) {
|
||||
birth = b
|
||||
listeners.forEach((cb) => cb())
|
||||
try {
|
||||
if (b) localStorage.setItem(KEY, JSON.stringify(b))
|
||||
else localStorage.removeItem(KEY)
|
||||
} catch (e) {
|
||||
console.warn('[saju] 기기에 저장하지 못함', e)
|
||||
}
|
||||
}
|
||||
|
||||
export const useBirth = () => useSyncExternalStore(subscribe, () => birth)
|
||||
|
||||
/** 있는 날짜이고 1900-01-01 ~ 오늘 사이인지 */
|
||||
export function validBirth(y: number, m: number, d: number) {
|
||||
const at = new Date(Date.UTC(y, m - 1, d))
|
||||
const ok = at.getUTCFullYear() === y && at.getUTCMonth() === m - 1 && at.getUTCDate() === d
|
||||
return ok && y >= 1900 && at.getTime() <= Date.now()
|
||||
}
|
||||
Reference in new issue
Block a user