[공통] util → framework 유틸 #7

Open
forge-bot wants to merge 8 commits from forge/ACM-CM-002-attempt-3-run-d48451005e39 into main
Showing only changes of commit a37cdbbbab - Show all commits

View file

@ -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);
}
}