111 lines
3.0 KiB
TypeScript
111 lines
3.0 KiB
TypeScript
"use client";
|
|
|
|
interface DigitalClockProps {
|
|
time: Date;
|
|
timezone: string;
|
|
showDate: boolean;
|
|
showSeconds: boolean;
|
|
format24h: boolean;
|
|
theme: "light" | "dark" | "blue" | "gradient";
|
|
}
|
|
|
|
/**
|
|
* 디지털 시계 컴포넌트
|
|
* - 실시간 시간 표시
|
|
* - 타임존 지원
|
|
* - 날짜/초 표시 옵션
|
|
* - 12/24시간 형식 지원
|
|
*/
|
|
export function DigitalClock({ time, timezone, showDate, showSeconds, format24h, theme }: DigitalClockProps) {
|
|
// 시간 포맷팅 (타임존 적용)
|
|
const timeString = new Intl.DateTimeFormat("ko-KR", {
|
|
timeZone: timezone,
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
second: showSeconds ? "2-digit" : undefined,
|
|
hour12: !format24h,
|
|
}).format(time);
|
|
|
|
// 날짜 포맷팅 (타임존 적용)
|
|
const dateString = showDate
|
|
? new Intl.DateTimeFormat("ko-KR", {
|
|
timeZone: timezone,
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
weekday: "long",
|
|
}).format(time)
|
|
: null;
|
|
|
|
// 타임존 라벨
|
|
const timezoneLabel = getTimezoneLabel(timezone);
|
|
|
|
// 테마별 스타일
|
|
const themeClasses = getThemeClasses(theme);
|
|
|
|
return (
|
|
<div className={`flex h-full flex-col items-center justify-center p-4 text-center ${themeClasses.container}`}>
|
|
{/* 날짜 표시 */}
|
|
{showDate && dateString && <div className={`mb-3 text-sm font-medium ${themeClasses.date}`}>{dateString}</div>}
|
|
|
|
{/* 시간 표시 */}
|
|
<div className={`text-5xl font-bold tabular-nums ${themeClasses.time}`}>{timeString}</div>
|
|
|
|
{/* 타임존 표시 */}
|
|
<div className={`mt-3 text-xs font-medium ${themeClasses.timezone}`}>{timezoneLabel}</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 타임존 라벨 반환
|
|
*/
|
|
function getTimezoneLabel(timezone: string): string {
|
|
const timezoneLabels: Record<string, string> = {
|
|
"Asia/Seoul": "서울 (KST)",
|
|
"Asia/Tokyo": "도쿄 (JST)",
|
|
"Asia/Shanghai": "베이징 (CST)",
|
|
"America/New_York": "뉴욕 (EST)",
|
|
"America/Los_Angeles": "LA (PST)",
|
|
"Europe/London": "런던 (GMT)",
|
|
"Europe/Paris": "파리 (CET)",
|
|
"Australia/Sydney": "시드니 (AEDT)",
|
|
};
|
|
|
|
return timezoneLabels[timezone] || timezone;
|
|
}
|
|
|
|
/**
|
|
* 테마별 클래스 반환
|
|
*/
|
|
function getThemeClasses(theme: string) {
|
|
const themes = {
|
|
light: {
|
|
container: "bg-white text-gray-900",
|
|
date: "text-gray-600",
|
|
time: "text-gray-900",
|
|
timezone: "text-gray-500",
|
|
},
|
|
dark: {
|
|
container: "bg-gray-900 text-white",
|
|
date: "text-gray-300",
|
|
time: "text-white",
|
|
timezone: "text-gray-400",
|
|
},
|
|
blue: {
|
|
container: "bg-gradient-to-br from-blue-400 to-blue-600 text-white",
|
|
date: "text-blue-100",
|
|
time: "text-white",
|
|
timezone: "text-blue-200",
|
|
},
|
|
gradient: {
|
|
container: "bg-gradient-to-br from-purple-400 via-pink-500 to-red-500 text-white",
|
|
date: "text-purple-100",
|
|
time: "text-white",
|
|
timezone: "text-pink-200",
|
|
},
|
|
};
|
|
|
|
return themes[theme as keyof typeof themes] || themes.light;
|
|
}
|