micronaut-core icon indicating copy to clipboard operation
micronaut-core copied to clipboard

Java time default formatters

Open timyates opened this issue 3 years ago • 8 comments

Originally https://github.com/micronaut-projects/micronaut-core/pull/6576

The Java Time classes have default formatters built in which use the ISO formats. So if in micronaut somewhere a string is to be converted to one of those classes we expect the default format to be the default format of the classes.

Up to now micronaut used RFC_1123_DATE_TIME as the default format for converting but this is a rather human readable format and does not use the defaults that are already there.

Another advantage of the built in defaults is, that they the classes do use the same format in .toString(). So i.e. OffsetDateTime.toString() is compatible with OffsetDateTime.parse() without thinking about the format.

timyates avatar Feb 14 '22 20:02 timyates

We also need tests for declarative clients that send date headers

jameskleeh avatar Feb 17 '22 18:02 jameskleeh

Added some tests to a declarative client with a header (once I eventually worked out how to make one) ☺️

timyates avatar Feb 18 '22 13:02 timyates

@timyates This needs documentation, otherwise good to go imo

Edit: I think you misunderstood the declarative client tests. The tests should be sending headers via arguments to the client methods. For example @Header OffsetDateTime date. None of the declarative client methods take arguments

jameskleeh avatar Feb 21 '22 19:02 jameskleeh

@jameskleeh Ahhh, so I moved the header into the client:

        @Get('/header-localdatetime')
        String headerLocalDateTime(@Header('X-Test') LocalDateTime date)

And you're right... It seems to be sending it through in the wrong format 🤔 Good catch, I'm looking in to it

timyates avatar Feb 28 '22 13:02 timyates

Right, I think that handles the declarative client conversions... Need to make sure it works on a non-GMT machine though... The perils of living on GMT

timyates avatar Feb 28 '22 17:02 timyates

@jameskleeh Probably worth you running DateTimeConversionSpec locally to check the conversion to GMT works for you

timyates avatar Feb 28 '22 17:02 timyates

That's awesome 😍

timyates avatar Mar 04 '22 10:03 timyates

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

:white_check_mark: timyates
:x: ckosmowski
:x: jameskleeh
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Feb 07 '24 21:02 CLAassistant