Skip to content
Open
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 @@ -169,7 +169,13 @@ public WriteCellData(Date dateValue) {
throw new IllegalArgumentException("DateValue can not be null");
}
setType(CellDataTypeEnum.DATE);
this.dateValue = LocalDateTime.ofInstant(dateValue.toInstant(), ZoneId.systemDefault());
if (dateValue instanceof java.sql.Date) {
this.dateValue = ((java.sql.Date) dateValue).toLocalDate().atStartOfDay();
} else if (dateValue instanceof java.sql.Time) {
this.dateValue = ((java.sql.Time) dateValue).toLocalTime().atDate(java.time.LocalDate.of(1970, 1, 1));
} else {
this.dateValue = LocalDateTime.ofInstant(dateValue.toInstant(), ZoneId.systemDefault());
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is any time zone issue here? seems depends on the execution machine

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alaahong Good point. I changed this path to use SQL Date/Time APIs directly instead of going through epoch millis.

java.sql.Date now uses toLocalDate(), and java.sql.Time uses toLocalTime(). The existing toInstant() path is still kept for java.util.Date and java.sql.Timestamp.

I also checked the other date conversions. Some existing generic Date/Calendar paths still use the system default timezone, but they are not introduced by this PR. I will look at those separately and follow up if we want to make them consistent.

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.fesod.sheet.metadata.data;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import org.apache.fesod.sheet.enums.CellDataTypeEnum;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class WriteCellDataTest {

@Test
void constructorShouldSupportSqlDate() {
WriteCellData<?> cellData = new WriteCellData<>(java.sql.Date.valueOf("2026-05-07"));

Assertions.assertEquals(CellDataTypeEnum.DATE, cellData.getType());
Assertions.assertEquals(
LocalDate.of(2026, 5, 7), cellData.getDateValue().toLocalDate());
}

@Test
void constructorShouldSupportSqlTime() {
WriteCellData<?> cellData = new WriteCellData<>(java.sql.Time.valueOf("12:34:56"));

Assertions.assertEquals(CellDataTypeEnum.DATE, cellData.getType());
Assertions.assertEquals(
LocalTime.of(12, 34, 56), cellData.getDateValue().toLocalTime());
}

@Test
void constructorShouldKeepSupportingSqlTimestampNanos() {
WriteCellData<?> cellData = new WriteCellData<>(java.sql.Timestamp.valueOf("2026-05-07 12:34:56.789123456"));

Assertions.assertEquals(CellDataTypeEnum.DATE, cellData.getType());
Assertions.assertEquals(LocalDateTime.of(2026, 5, 7, 12, 34, 56, 789_123_456), cellData.getDateValue());
}
}