260914_01_ENH: 1차 완성
This commit is contained in:
13
src/lib/kmusical/date.ts
Normal file
13
src/lib/kmusical/date.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const toLocalDateString = (date = new Date()) => {
|
||||
const pad = (value: number) => String(value).padStart(2, "0");
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
||||
};
|
||||
|
||||
export const parseLocalDateString = (value: string | undefined | null): Date | null => {
|
||||
const match = value ? /^(\d{4})-(\d{2})-(\d{2})/.exec(value) : null;
|
||||
if (!match) return null;
|
||||
|
||||
const [, year, month, day] = match;
|
||||
const date = new Date(Number(year), Number(month) - 1, Number(day));
|
||||
return Number.isNaN(date.getTime()) ? null : date;
|
||||
};
|
||||
Reference in New Issue
Block a user