diff --git a/build.gradle b/build.gradle index bb959b1..556fa3f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } // 버전 변경은 여기서 -def commonVer = "beta.1.1.28" +def commonVer = "beta.1.1.29" group = 'com.kri.common' version = commonVer diff --git a/src/main/java/com/kri/common/feature/excel/ExcelUtil.java b/src/main/java/com/kri/common/feature/excel/ExcelUtil.java index a7f47ff..3ac3c9a 100644 --- a/src/main/java/com/kri/common/feature/excel/ExcelUtil.java +++ b/src/main/java/com/kri/common/feature/excel/ExcelUtil.java @@ -1,5 +1,6 @@ package com.kri.common.feature.excel; +import java.text.SimpleDateFormat; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; @@ -10,6 +11,10 @@ import org.apache.poi.ss.util.NumberToTextConverter; public final class ExcelUtil { + private static final double TIME_FRACTION_EPSILON = 0.0000001; + private static final String DATE_FORMAT = "yyyy-MM-dd"; + private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + private ExcelUtil() { } @@ -76,13 +81,15 @@ public final class ExcelUtil { private static String formatNumericCell(Cell cell, double value, DataFormatter formatter) { if (DateUtil.isCellDateFormatted(cell)) { - return formatter.formatRawCellContents( - value, - cell.getCellStyle().getDataFormat(), - cell.getCellStyle().getDataFormatString() - ); + String pattern = hasTimeFraction(value) ? DATE_TIME_FORMAT : DATE_FORMAT; + return new SimpleDateFormat(pattern).format(DateUtil.getJavaDate(value)); } return NumberToTextConverter.toText(value); } + + private static boolean hasTimeFraction(double value) { + double fraction = value - Math.floor(value); + return fraction > TIME_FRACTION_EPSILON && (1 - fraction) > TIME_FRACTION_EPSILON; + } }