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

Handle Timezone Differences in Liquibase for Cloud Spanner #385

Merged

Conversation

vladimirevd
Copy link
Contributor

To ensure predictable behavior, adjustments were made to handle timezone differences appropriately and align Liquibase's behavior with Cloud Spanner's expectations.

@@ -49,12 +57,26 @@ public boolean dataTypeIsNotModifiable(final String typeName) {

@Override
public String getDateLiteral(final String isoDate) {
String literal = super.getDateLiteral(isoDate);
String literal;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: just remove this variable. It is not really needed in the way that the implementation works now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

String formattedTime = utcDateTime.format(ISO_LOCAL_TIME);
literal = "TIMESTAMP '" + formattedDate + "T" + formattedTime + "Z'";
} catch (ParseException e) {
throw new RuntimeException("Error parsing ISO date: " + isoDate, e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to do the same as the super class does in a case like this, which is to return "BAD_DATE_FORMAT:" + isoDate;. I don't know exactly why Liquibase does that here, but as the super class does not throw an exception for an invalid value, we should probably also not do in this override.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did like super class

OffsetDateTime utcDateTime = instant.atOffset(ZoneOffset.UTC);
String formattedDate = utcDateTime.format(ISO_LOCAL_DATE);
String formattedTime = utcDateTime.format(ISO_LOCAL_TIME);
literal = "TIMESTAMP '" + formattedDate + "T" + formattedTime + "Z'";
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: just return directly here instead of assigning to literal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if (isDateTime(isoDate)) {
literal = "TIMESTAMP " + literal.replace(' ', 'T');
Date date;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: move this inside the try block to what is now line 66

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is correct, the super class already has similar behavior, and the try catch block was needed for the ISODateFormat().parse(isoDate) method.

Comment on lines 76 to 77
literal = super.getDateLiteral(isoDate);
literal = "DATE " + literal;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: just do return "DATE " + super.getDateLiteral(isoDate);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

@vladimirevd vladimirevd left a comment

Choose a reason for hiding this comment

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

Comments resolved

@olavloite olavloite merged commit 747980e into cloudspannerecosystem:master Dec 20, 2024
8 checks passed
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.

2 participants