Skip to content

Commit

Permalink
Change Timestamp to Date
Browse files Browse the repository at this point in the history
  • Loading branch information
nntthuy-axonivy committed Dec 12, 2024
1 parent d2d3a65 commit 42d86f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.io.IOException;
import java.nio.file.Path;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.jupiter.api.Test;
Expand All @@ -25,7 +25,7 @@ void parseColumns_xlsx(@TempDir Path dir) throws IOException {
.contains("Firstname", "Lastname");
assertThat(columns).contains(
new Column("Firstname", String.class, 255), new Column("ZIP", Integer.class),
new Column("Amount", Double.class), new Column("Birthdate", Timestamp.class), // should be a date
new Column("Amount", Double.class), new Column("Birthdate", Date.class), // should be a date
new Column("Note", String.class, 811),
new Column("Column contains texts in incorrect number format", String.class, 255),
new Column("Column contains both text and numeric", String.class, 255)
Expand All @@ -44,4 +44,15 @@ void parseColumnsOver255Characters_xlsx(@TempDir Path dir) throws IOException {
new Column("Summary", String.class, 823));
}

@Test
void parseColumnsSeveralDateFormats_xlsx(@TempDir Path dir) throws IOException {
Path path = dir.resolve("customers.xlsx");
TstRes.loadTo(path, "sample_date_format.xlsx");
Workbook wb = ExcelLoader.load(path);
List<Column> columns = ExcelReader.parseColumns(wb.getSheetAt(0));
assertThat(columns).extracting(Column::getName).contains("Start date", "End date", "Date without year");
assertThat(columns).contains(new Column("Start date", Date.class),
new Column("End date", Date.class), new Column("Date without year", Date.class));
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.axonivy.util.excel.importer;

import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -65,7 +65,7 @@ private static Column toColumn(String fieldName, Cell cell) {
switch (cell.getCellType()) {
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
return new Column(fieldName, Timestamp.class);
return new Column(fieldName, Date.class);
}
if (CellUtils.isInteger(cell)) {
return new Column(fieldName, Integer.class);
Expand Down

0 comments on commit 42d86f6

Please sign in to comment.