기존 src/main/util/kstDate.ts (2 함수) 를 shared 로 이동 + kstTodayAsDate 추가. main + renderer 양쪽 import 가능. 6 callsite 통합: - NoteRepository.findExpiredCandidates (todayInKstString → kstTodayIso) - TelemetryService.todayKstIso (inline 제거) - telemetryStats.kstDate (inline 제거) - AiWorker.todayKstAsDate / todayKstAsIso (inline 제거) - store.snoozeExpired + snoozeRecall (inline 제거 → nextKstMidnightMs) API: kstTodayIso(now) / nextKstMidnightMs(now) / kstTodayAsDate(now) + KST_OFFSET_MS, DAY_MS 상수 export. 단위 +4 cases (boundary, format, midnight, asDate). 418 → 422. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
/**
|
|
* KST timezone helpers — main + renderer 양쪽에서 import 가능.
|
|
* v0.2.6 C1: backlog #3+#19+#34 통합 (기존 src/main/util/kstDate.ts 이동).
|
|
*/
|
|
|
|
export const KST_OFFSET_MS = 9 * 60 * 60 * 1000;
|
|
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
|
|
/**
|
|
* KST 자정 기준 today YYYY-MM-DD.
|
|
*
|
|
* 기존 todayInKstString (NoteRepository.findExpiredCandidates),
|
|
* TelemetryService.todayKstIso, telemetryStats.kstDate, AiWorker.todayKstAsIso
|
|
* 4 callsite 통합.
|
|
*/
|
|
export function kstTodayIso(now: Date = new Date()): string {
|
|
const k = new Date(now.getTime() + KST_OFFSET_MS);
|
|
return new Date(Date.UTC(k.getUTCFullYear(), k.getUTCMonth(), k.getUTCDate()))
|
|
.toISOString().slice(0, 10);
|
|
}
|
|
|
|
/**
|
|
* 다음 KST 자정의 epoch ms (UTC).
|
|
*
|
|
* 기존 nextKstMidnightMs (store.snoozeExpired) + store.snoozeRecall inline 통합.
|
|
*/
|
|
export function nextKstMidnightMs(now: number = Date.now()): number {
|
|
const kstNow = now + KST_OFFSET_MS;
|
|
const kstMidnightFloor = Math.floor(kstNow / DAY_MS) * DAY_MS;
|
|
const nextKstMidnight = kstMidnightFloor + DAY_MS;
|
|
return nextKstMidnight - KST_OFFSET_MS;
|
|
}
|
|
|
|
/**
|
|
* KST today (00:00 KST 의 UTC Date 객체). AiWorker 의 dueDateParser 가 candidate 비교용.
|
|
*
|
|
* 기존 AiWorker.todayKstAsDate 통합.
|
|
*/
|
|
export function kstTodayAsDate(now: Date = new Date()): Date {
|
|
const k = new Date(now.getTime() + KST_OFFSET_MS);
|
|
return new Date(Date.UTC(k.getUTCFullYear(), k.getUTCMonth(), k.getUTCDate()));
|
|
}
|