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

Core: Fix Java Time DateFormatter printers #32592

Merged

Conversation

spinscale
Copy link
Contributor

A bug in the test suite prevented to properly check that all date
formatters printed the date the same way like joda time does.

This fixes the test and thus also a fair share of formats, that
now use the strict parser for printing.

Also, now all date parsers are using UTC as their default time zone.

A bug in the test suite prevented to properly check that all date
formatters printed the date the same way like joda time does.

This fixes the test and thus also a fair share of formats, that
basically use the strict parser for printing.

Also, now all date parsers are using UTC as their default time zone.
@spinscale spinscale added review :Core/Infra/Core Core issues without another label v7.0.0 v6.5.0 labels Aug 2, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

return new CompoundDateTimeFormatterBuilder();
}

static final class CompoundDateTimeFormatterBuilder {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of creating another class, could the functionality here just be a couple private static methods on DateFormatters? If I understand these timezone formats correctly, the only reason we have any of this complexity is because of +HHmm, which is a non standard format. The other two would be handled by appendZoneOrOffsetId()? I think it would be good to keep this local to DateFormatters, so that adding more cases like this does not leak outside of that class.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

This looks ok, but it is extremely hard to read because of the tons of formatters/printers reused sometimes and not others. Could you please add a comment to the top of the class indicating what naming conventions are used? For example, with basic time, BASIC_TIME_PRINTER does not have time zone info, but BASIC_TIME_NO_MILLIS does. Additionally, as a general suggestion for things that would make changes here easier to review in the future, some comments within the file grouping the formatters would also be nice. For example, having all the "time" formatters grouped together with some large comment blocks. And even more helpful would be having a comment on each formatter with the string format equivalent.

.append(OPTIONAL_TIME_ZONE_FORMATTER)
.optionalStart().appendZoneId().optionalEnd()
.optionalStart().appendOffset("+HHmm", "Z").optionalEnd()
.optionalStart().appendOffset("+HH:mm", "Z").optionalEnd()
Copy link
Member

Choose a reason for hiding this comment

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

Can you use appendZoneOrOffsetId() above, which includes this?

@spinscale
Copy link
Contributor Author

I removed the methods from the CompoundDateFormatter, used appendZoneOrOffsetId() and also did not create more static methods, but created the date time formatters manually (the methods did not save that much).

I also removed making all the formatters UTC by default, as there seem to be differences between java8 and 10 (java10 works as expected, java8 fails the tests in CI and local).

@spinscale
Copy link
Contributor Author

I also added a small comment for each of the compound date time formatters now

@spinscale spinscale merged commit 823d40e into elastic:master Aug 9, 2018
spinscale added a commit that referenced this pull request Aug 9, 2018
A bug in the test suite prevented to properly check that all date
formatters printed the date the same way like joda time does.

This fixes the test and thus also a fair share of formats, that
now use the strict parser for printing.
rjernst pushed a commit that referenced this pull request Aug 14, 2018
A bug in the test suite prevented to properly check that all date
formatters printed the date the same way like joda time does.

This fixes the test and thus also a fair share of formats, that
now use the strict parser for printing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants