Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MARP-1386 Change date data type #72

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading