Skip to content

fix: support SQL date types in WriteCellData#912

Open
skytin1004 wants to merge 2 commits into
apache:mainfrom
skytin1004:fix/714-support-sql-date-types-write-cell-data
Open

fix: support SQL date types in WriteCellData#912
skytin1004 wants to merge 2 commits into
apache:mainfrom
skytin1004:fix/714-support-sql-date-types-write-cell-data

Conversation

@skytin1004
Copy link
Copy Markdown
Contributor

@skytin1004 skytin1004 commented May 7, 2026

Purpose of the pull request

Closed: #714

I've fixed WriteCellData(Date) when the actual value is java.sql.Date or java.sql.Time.

I reproduced the failure locally and confirmed that both SQL date/time types can throw UnsupportedOperationException when toInstant() is called directly.

What's changed?

The existing toInstant() path is kept for java.util.Date and java.sql.Timestamp. This keeps the behavior unchanged for regular date values and preserves java.sql.Timestamp nano precision.

I added regression tests for:

  • java.sql.Date
  • java.sql.Time
  • java.sql.Timestamp

To verify the fix, I first confirmed that the new WriteCellDataTest failed before the change with UnsupportedOperationException from java.sql.Date.toInstant() and java.sql.Time.toInstant(). After applying the fix, I confirmed that the new test passed, the existing related CellDataDataTest passed together with it, and the full fesod-sheet test suite also passed.

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

@skytin1004 skytin1004 force-pushed the fix/714-support-sql-date-types-write-cell-data branch from 7ec9fe2 to 6d774c2 Compare May 8, 2026 21:45
@alaahong alaahong requested a review from Copilot May 18, 2026 16:34
this.dateValue = LocalDateTime.ofInstant(Instant.ofEpochMilli(dateValue.getTime()), ZoneId.systemDefault());
} 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] WriteCellData 方法如果传入 java.sql.Date 会报错

3 participants