게시판 등록시간 수정

This commit is contained in:
Macbook
2026-05-29 15:34:59 +09:00
parent 03441337f2
commit c95732c09b
13 changed files with 129 additions and 66 deletions
+50
View File
@@ -155,3 +155,53 @@ export function formatNowClock(tz?: string, withSeconds = true): string {
const zone = normalizeTimezone(tz ?? _tz);
return formatUnixClock(Math.floor(Date.now() / 1000), zone, withSeconds);
}
/** 백엔드 LocalDateTime(JSON, 타임존 없음) 저장 기준 — Asia/Seoul 벽시계 */
export const BACKEND_NAIVE_TIMEZONE = 'Asia/Seoul';
/**
* 백엔드가 내려준 ISO 문자열(타임존 없음)을 Instant로 변환.
* Docker(UTC JVM)에서 저장된 과거 UTC 벽시계 값은 +00:00, 신규는 +09:00으로 해석.
*/
export function parseBackendNaiveDateTime(iso: string): Date | null {
const raw = (iso ?? '').trim();
if (!raw) return null;
if (/[Zz]$/.test(raw) || /[+-]\d{2}:?\d{2}$/.test(raw)) {
const d = new Date(raw);
return Number.isNaN(d.getTime()) ? null : d;
}
const normalized = raw.includes('T') ? raw : raw.replace(' ', 'T');
const withSec = /:\d{2}/.test(normalized.slice(11)) ? normalized : `${normalized}:00`;
const d = new Date(`${withSec}+09:00`);
if (!Number.isNaN(d.getTime())) return d;
const fallback = new Date(raw);
return Number.isNaN(fallback.getTime()) ? null : fallback;
}
/** 검증게시판·API LocalDateTime → 표시 시간대(기본 앱 설정) */
export function formatIsoDateTime(
iso?: string | null,
tz?: string,
style: 'full' | 'short' = 'full',
): string {
if (!iso) return style === 'full' ? '—' : '';
const d = parseBackendNaiveDateTime(iso);
if (!d) return iso;
const zone = normalizeTimezone(tz ?? _tz);
const opts: Intl.DateTimeFormatOptions = {
timeZone: zone,
hour12: false,
hour: '2-digit',
minute: '2-digit',
};
if (style === 'full') {
opts.year = 'numeric';
opts.month = '2-digit';
opts.day = '2-digit';
opts.second = '2-digit';
} else {
opts.month = '2-digit';
opts.day = '2-digit';
}
return new Intl.DateTimeFormat('ko-KR', opts).format(d);
}