rmannibucau commented on PR #117:
URL: https://github.com/apache/johnzon/pull/117#issuecomment-1909955347

   In the spirit (date parsing can be enhanced) - this is what we do for JSON-B 
already for ex:
   
   ```java
   public class DateConverter implements Converter<Date> {
       private static final ZoneId UTC = ZoneId.of("UTC");
   
       private final DateTimeFormatter formatter;
   
       public DateConverter(final String pattern) {
           this.formatter = ofPattern(pattern, ROOT);
       }
   
       @Override
       public String toString(final Date instance) {
           return 
formatter.format(ZonedDateTime.ofInstant(instance.toInstant(), UTC));
       }
   
       @Override
       public Date fromString(final String text) {
           try {
               return Date.from(parseZonedDateTime(text, 
formatter).toInstant());
           } catch (final DateTimeParseException dpe) {
               return 
Date.from(LocalDateTime.parse(text).toInstant(ZoneOffset.UTC));
           }
       }
   
       private static ZonedDateTime parseZonedDateTime(final String text, final 
DateTimeFormatter formatter) {
           final TemporalAccessor parse = formatter.parse(text);
           ZoneId zone = parse.query(TemporalQueries.zone());
           if (Objects.isNull(zone)) {
               zone = UTC;
           }
           final int year = parse.isSupported(YEAR) ? parse.get(YEAR) : 0;
           final int month = parse.isSupported(MONTH_OF_YEAR) ? 
parse.get(MONTH_OF_YEAR) : 0;
           final int day = parse.isSupported(DAY_OF_MONTH) ? 
parse.get(DAY_OF_MONTH) : 0;
           final int hour = parse.isSupported(HOUR_OF_DAY) ? 
parse.get(HOUR_OF_DAY) : 0;
           final int minute = parse.isSupported(MINUTE_OF_HOUR) ? 
parse.get(MINUTE_OF_HOUR) : 0;
           final int second = parse.isSupported(SECOND_OF_MINUTE) ? 
parse.get(SECOND_OF_MINUTE) : 0;
           final int millisecond = parse.isSupported(MILLI_OF_SECOND) ? 
parse.get(MILLI_OF_SECOND) : 0;
           return ZonedDateTime.of(year, month, day, hour, minute, second, 
millisecond, zone);
       }
   }
   ```
   
   Checked the pattern table and formatter seems to be a superset of simple 
dateformat so we shouldn't be too bad.
   Once applied there are a few failures but mainly around the error messages 
so test can be "fixed".
   
   Do you want to try that path?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to