diff --git a/std-bits/table/src/main/java/org/enso/table/excel/ExcelRow.java b/std-bits/table/src/main/java/org/enso/table/excel/ExcelRow.java index cf3957c6096..17a6d75e556 100644 --- a/std-bits/table/src/main/java/org/enso/table/excel/ExcelRow.java +++ b/std-bits/table/src/main/java/org/enso/table/excel/ExcelRow.java @@ -46,7 +46,10 @@ public class ExcelRow { return dateTime.toLocalTime(); } if (dateTime.getHour() == 0 && dateTime.getMinute() == 0 && dateTime.getSecond() == 0) { - return dateTime.toLocalDate(); + var dateFormat = cell.getCellStyle().getDataFormatString(); + if (!dateFormat.contains("h") && !dateFormat.contains("H")) { + return dateTime.toLocalDate(); + } } return dateTime.atZone(ZoneId.systemDefault()); } else { diff --git a/std-bits/table/src/main/java/org/enso/table/write/ExcelWriter.java b/std-bits/table/src/main/java/org/enso/table/write/ExcelWriter.java index 0c42a52dfc8..29e7dea7faa 100644 --- a/std-bits/table/src/main/java/org/enso/table/write/ExcelWriter.java +++ b/std-bits/table/src/main/java/org/enso/table/write/ExcelWriter.java @@ -14,6 +14,7 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.enso.table.data.column.storage.BoolStorage; import org.enso.table.data.column.storage.Storage; +import org.enso.table.data.column.storage.datetime.DateTimeStorage; import org.enso.table.data.column.storage.numeric.AbstractLongStorage; import org.enso.table.data.column.storage.numeric.DoubleStorage; import org.enso.table.data.table.Column; @@ -498,6 +499,9 @@ public class ExcelWriter { cell.setCellValue(longStorage.getItem(j)); } else if (storage instanceof BoolStorage boolStorage) { cell.setCellValue(boolStorage.getItem(j)); + } else if (storage instanceof DateTimeStorage dateTimeStorage) { + cell.setCellValue(dateTimeStorage.getItem(j).toLocalDateTime()); + cell.setCellStyle(getDateTimeStyle(workbook, "yyyy-MM-dd HH:mm:ss")); } else { Object value = storage.getItemBoxed(j); switch (value) { diff --git a/test/Table_Tests/data/all_data_types.csv b/test/Table_Tests/data/all_data_types.csv new file mode 100644 index 00000000000..7e6eaa3a8a8 --- /dev/null +++ b/test/Table_Tests/data/all_data_types.csv @@ -0,0 +1,16 @@ +id_integer,name_char,age_integer,salary_integer,join_date_date,is_active_boolean,start_time_time,appointment_datetime_datetime_withtimezone,height_cm_float +1,John Doe,18,-2147483648,2000-01-01,true,00:00:00,2000-01-01 00:00:00,150.2 +2,Jane Smith,25,0,2010-05-20,false,06:30:00,2015-12-31 23:59:59,160.0 +3,Mike Johnson,40,10000,1966-02-10,true,,1995-06-15 15:30:00,170.0 +4,Sarah Parker,22,25000,2022-03-05,,18:45:00,2023-12-31 00:00:00,165.0 +5,David Brown,30,50000,1980-11-12,true,21:15:00,1970-01-01 08:00:00,180.0 +6,Lisa Wilson,28,35000,2005-09-30,false,09:30:00,2010-12-31 12:00:00,155.0 +7,Chris Lee,35,70000,2000-07-18,true,15:45:00,1999-12-31 23:59:59, +8,Emily Adams,20,999,2021-12-22,false,03:00:00,2024-04-27 15:00:00,140.0 +9,Michael Taylor,33,68000,2010-03-08,true,08:30:00,2015-06-30 17:30:00,172.2 +10,Amy Chen,23,63000,,false,12:15:00,2018-12-31 19:00:00,160.0 +11,André Müller,45,2147483647,1970-01-01,true,00:00:00,1999-12-31 14:00:00,185.8 +12,Елена Иванова,18,1000,2000-01-01,false,06:00:00,,120.0 +13,John,,,2010-10-05,true,15:30:00,2015-06-30 16:45:00,125.0 +14,田中 花子,20,-2147483648,1980-04-25,false,22:00:00,1966-01-01 08:45:00,140.0 +15,김 영희,22,50000,2015-01-08,true,08:00:00,2016-12-31 00:00:00,150.0 diff --git a/test/Table_Tests/src/IO/Excel_Spec.enso b/test/Table_Tests/src/IO/Excel_Spec.enso index 7d752c21d58..1083d49c60f 100644 --- a/test/Table_Tests/src/IO/Excel_Spec.enso +++ b/test/Table_Tests/src/IO/Excel_Spec.enso @@ -157,6 +157,15 @@ spec_write suite_builder suffix test_sheet_name = written.read 'EnsoSheet' . should_equal data.table written.close + group_builder.specify 'should be able to round trip all the data types' <| + alltypes = enso_project.data / "transient" / "alltypes."+suffix + alltypes.delete_if_exists . should_succeed + t1 = enso_project.data/'all_data_types.csv' . read + t1.write alltypes (Excel_Format.Sheet "AllTypes") . should_succeed + t2 = alltypes.read (Excel_Format.Sheet "AllTypes") + t2.should_equal t1 + + group_builder.specify 'should write a table to non-existent file in append mode as a new sheet with headers' <| out = data.create_out data.table.write out on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed