4279: honour session timezone in FROM_UNIXTIME by bheading · Pull Request #4280 · h2database/h2database · GitHub
Skip to content

4279: honour session timezone in FROM_UNIXTIME#4280

Draft
bheading wants to merge 1 commit into
h2database:masterfrom
bheading:4279-fix-unix_timestamp
Draft

4279: honour session timezone in FROM_UNIXTIME#4280
bheading wants to merge 1 commit into
h2database:masterfrom
bheading:4279-fix-unix_timestamp

Conversation

@bheading

@bheading bheading commented Sep 7, 2025

Copy link
Copy Markdown

Fixes #4279

A quick hack that demonstrates the problem - let me know if you want me to change the approach or add test cases etc.

@katzyn katzyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your contribution!

Please, address the review comments and send a license statement as described here
https://h2database.com/html/build.html#providing_patches
to the mailing list (Google group):
https://groups.google.com/g/h2-database

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method can be removed.

public static String fromUnixTime(int seconds, String format) {
public static String fromUnixTime(SessionLocal session, int seconds, String format) {
format = convertToSimpleDateFormat(format);
SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ENGLISH);

@katzyn katzyn Sep 7, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SimpleDateFormat and Date are legacy defective by design classes, please, replace them with classes from JSR-310.
Something like

DateTimeFormatter.ofPattern(format).withLocale(Locale.ENGLISH).withZone(ZoneId.of(session.currentTimeZone().getId()))
        .format(Instant.ofEpochSecond(seconds));

You also need to adjust tests it TestCompatibility, they must set some specific time zone of the session.

@bheading

bheading commented Sep 8, 2025

Copy link
Copy Markdown
Author

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.

MySQL mode : FROM_UNIXTIME does not honour session timestamp when it should

2 participants