From a37cdbbbabd8d7bc8dbb3a8498fdd7534e6ac696 Mon Sep 17 00:00:00 2001 From: forge-bot Date: Sat, 18 Jul 2026 11:16:29 +0000 Subject: [PATCH] =?UTF-8?q?[=EA=B3=B5=ED=86=B5]=20util=20=E2=86=92=20frame?= =?UTF-8?q?work=20=EC=9C=A0=ED=8B=B8=20(ACM-CM-002)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acquirecore/framework/util/DateUtil.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 boot/common-framework/src/main/java/com/klaro/acquirecore/framework/util/DateUtil.java diff --git a/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/util/DateUtil.java b/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/util/DateUtil.java new file mode 100644 index 0000000..72b8216 --- /dev/null +++ b/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/util/DateUtil.java @@ -0,0 +1,91 @@ +package com.klaro.acquirecore.framework.util; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; + +/** + * Static utility class for date operations migrated from legacy C util_date.c + */ +public final class DateUtil { + + private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE; + + private DateUtil() { + // Utility class - prevent instantiation + } + + public static LocalDate of(int year, int month, int day) { + return LocalDate.of(year, month, day); + } + + public static String toString(LocalDate date) { + return date == null ? null : date.format(DEFAULT_FORMATTER); + } + + public static String format(LocalDate date, String pattern) { + return date == null ? null : date.format(DateTimeFormatter.ofPattern(pattern)); + } + + public static LocalDate fromString(String str) { + if (str == null || str.isEmpty()) return null; + return LocalDate.parse(str, DEFAULT_FORMATTER); + } + + public static LocalDate parse(String str, String pattern) { + if (str == null || str.isEmpty()) return null; + return LocalDate.parse(str, DateTimeFormatter.ofPattern(pattern)); + } + + public static long diffDays(LocalDate a, LocalDate b) { + if (a == null || b == null) throw new IllegalArgumentException("Dates must not be null"); + return ChronoUnit.DAYS.between(b, a); + } + + public static int compare(LocalDate a, LocalDate b) { + if (a == null || b == null) throw new IllegalArgumentException("Dates must not be null"); + return a.compareTo(b); + } + + public static LocalDate addDays(LocalDate date, long days) { + if (date == null) throw new IllegalArgumentException("Date must not be null"); + return date.plusDays(days); + } + + public static LocalDate subtractDays(LocalDate date, long days) { + if (date == null) throw new IllegalArgumentException("Date must not be null"); + return date.minusDays(days); + } + + public static int getYear(LocalDate date) { + if (date == null) throw new IllegalArgumentException("Date must not be null"); + return date.getYear(); + } + + public static int getMonth(LocalDate date) { + if (date == null) throw new IllegalArgumentException("Date must not be null"); + return date.getMonthValue(); + } + + public static int getDay(LocalDate date) { + if (date == null) throw new IllegalArgumentException("Date must not be null"); + return date.getDayOfMonth(); + } + + public static LocalDate now() { + return LocalDate.now(); + } + + public static boolean isBefore(LocalDate a, LocalDate b) { + return a != null && b != null && a.isBefore(b); + } + + public static boolean isAfter(LocalDate a, LocalDate b) { + return a != null && b != null && a.isAfter(b); + } + + public static boolean isEqual(LocalDate a, LocalDate b) { + if (a == null && b == null) return true; + return a != null && b != null && a.isEqual(b); + } +}