summaryrefslogtreecommitdiff
path: root/lib/soap/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/soap/utils.ts')
-rw-r--r--lib/soap/utils.ts49
1 files changed, 48 insertions, 1 deletions
diff --git a/lib/soap/utils.ts b/lib/soap/utils.ts
index 6c09edbe..57e3b280 100644
--- a/lib/soap/utils.ts
+++ b/lib/soap/utils.ts
@@ -6,6 +6,7 @@ import { eq } from "drizzle-orm";
import db from "@/db/db";
import { soapLogs, type LogDirection, type SoapLogInsert } from "@/db/schema/SOAP/soap";
import { XMLBuilder } from 'fast-xml-parser'; // for object→XML 변환
+import { debugError } from "../debug-utils";
// XML 파싱용 타입 유틸리티: 스키마에서 XML 타입 생성
export type ToXMLFields<T> = {
@@ -605,4 +606,50 @@ export function dateToSAPFormat(date: Date): { date: string; time: string } {
date: formatDateForSAP(date.toISOString().slice(0, 10)),
time: formatTimeForSAP(date.toTimeString().slice(0, 8))
};
-} \ No newline at end of file
+}
+
+/**
+ * SAP 날짜 문자열을 Date로 변환 (YYYYMMDD -> Date)
+ */
+export function parseSAPDate(dateStr: string | null | undefined): Date | null {
+ if (!dateStr || !dateStr.trim()) return null;
+
+ const trimmed = dateStr.trim();
+ if (trimmed.length !== 8) return null;
+
+ try {
+ const year = parseInt(trimmed.substring(0, 4), 10);
+ const month = parseInt(trimmed.substring(4, 6), 10) - 1; // 월은 0부터 시작
+ const day = parseInt(trimmed.substring(6, 8), 10);
+
+ const date = new Date(year, month, day);
+
+ // 유효한 날짜인지 확인
+ if (isNaN(date.getTime())) return null;
+
+ return date;
+ } catch (error) {
+ debugError('SAP 날짜 파싱 오류', { dateStr, error });
+ return null;
+ }
+}
+
+
+/**
+ * 숫자 문자열을 string으로 변환 (numeric 타입용)
+ * drizzle-orm의 numeric 타입은 string으로 저장됨
+ */
+export function parseNumericString(value: string | null | undefined): string | null {
+ if (!value || !value.trim()) return null;
+
+ try {
+ const trimmed = value.trim();
+ const parsed = parseFloat(trimmed);
+ // 유효한 숫자인지 확인
+ if (isNaN(parsed)) return null;
+ // 원본 문자열 반환 (또는 정제된 숫자 문자열)
+ return trimmed;
+ } catch {
+ return null;
+ }
+}