[공통] util → framework 유틸 #5

Open
forge-bot wants to merge 8 commits from forge/ACM-CM-002-attempt-2-run-87bf2707792a into main
Showing only changes of commit 56c791f0af - Show all commits

View file

@ -0,0 +1,85 @@
package com.klaro.acquirecore.framework.util;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
/**
* Static utility class for date operations migrated from legacy C code.
* Provides parsing, formatting, and calculation for LocalDate instances.
*/
public final class DateUtil {
private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
private DateUtil() {
// Utility class - prevent instantiation
}
public static LocalDate parse(String dateStr) {
if (dateStr == null || dateStr.isBlank()) {
return null;
}
try {
return LocalDate.parse(dateStr.trim(), DEFAULT_FORMATTER);
} catch (DateTimeParseException e) {
return null;
}
}
public static String format(LocalDate date) {
if (date == null) {
return "";
}
return date.format(DEFAULT_FORMATTER);
}
public static String format(LocalDate date, String pattern) {
if (date == null || pattern == null || pattern.isBlank()) {
return "";
}
try {
return date.format(DateTimeFormatter.ofPattern(pattern));
} catch (IllegalArgumentException e) {
return "";
}
}
public static long diffDays(LocalDate from, LocalDate to) {
if (from == null || to == null) {
return 0;
}
return ChronoUnit.DAYS.between(from, to);
}
public static LocalDate addDays(LocalDate date, long days) {
if (date == null) {
return null;
}
return date.plusDays(days);
}
public static LocalDate today() {
return LocalDate.now();
}
public static boolean isValid(String dateStr) {
return parse(dateStr) != null;
}
public static boolean isBefore(LocalDate date, LocalDate before) {
if (date == null || before == null) {
return false;
}
return date.isBefore(before);
}
public static boolean isAfter(LocalDate date, LocalDate after) {
if (date == null || after == null) {
return false;
}
return date.isAfter(after);
}
}