blob: 1856628c44bc62bb921359ac61d073b1bd14422c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/**
* SWP 관련 유틸리티 함수
*/
/**
* SWP API 날짜 포맷팅 (간단 버전)
* 오전/오후 → AM/PM 변환 및 (KST) 추가
*
* @param dateStr "2017-02-20 오전 8:52:00" 형식
* @returns "2017-02-20 AM 8:52:00 (KST)"
*/
export function formatSwpDate(dateStr: string): string {
if (!dateStr || dateStr === "1900-01-01 오전 12:00:00") return "-";
return dateStr.replace("오후", "PM").replace("오전", "AM") + " (KST)";
}
/**
* SWP API 날짜 포맷팅 (간결 버전)
* 오전/오후를 24시간 형식으로 변환하고 초 제거
*
* @param dateStr "2017-02-20 오전 8:52:00" 형식
* @returns "2017-02-20 08:52"
*/
export function formatSwpDateShort(dateStr: string): string {
if (!dateStr || dateStr === "1900-01-01 오전 12:00:00") return "-";
try {
// 날짜와 시간 분리
const parts = dateStr.split(" ");
if (parts.length < 3) return formatSwpDate(dateStr);
const datePart = parts[0]; // "2017-02-20"
const ampm = parts[1]; // "오전" or "오후"
const timePart = parts[2]; // "8:52:00"
// 시간 파싱
const [hours, minutes] = timePart.split(":");
let hour = parseInt(hours, 10);
// 오후인 경우 12시간 더하기 (12시는 제외)
if (ampm === "오후" && hour !== 12) {
hour += 12;
} else if (ampm === "오전" && hour === 12) {
hour = 0;
}
return `${datePart} ${hour.toString().padStart(2, "0")}:${minutes}`;
} catch {
return formatSwpDate(dateStr);
}
}
/**
* 파일 크기 포맷팅
*
* @param sizeStr 바이트 단위 파일 크기 문자열
* @returns "1.23 MB" 또는 "456.78 KB" 형식
*/
export function formatFileSize(sizeStr: string): string {
const bytes = parseInt(sizeStr, 10);
if (isNaN(bytes)) return sizeStr;
const kb = bytes / 1024;
const mb = kb / 1024;
return mb >= 1 ? `${mb.toFixed(2)} MB` : `${kb.toFixed(2)} KB`;
}
|