Skip to content

Commit

Permalink
Reduce changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rlconst committed Oct 12, 2023
1 parent 775c4eb commit dc9c4ad
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@
import io.micronaut.core.convert.format.Format;
import io.micronaut.core.util.StringUtils;

import java.time.*;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.MonthDay;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.Year;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.TemporalAccessor;
Expand Down Expand Up @@ -129,9 +141,9 @@ public void register(ConversionService<?> conversionService) {

// CharSequence -> TemporalAmount
conversionService.addConverter(
CharSequence.class,
TemporalAmount.class,
(object, targetType, context) -> durationConverter.apply(object, context).map(TemporalAmount.class::cast)
CharSequence.class,
TemporalAmount.class,
(object, targetType, context) -> durationConverter.apply(object, context).map(TemporalAmount.class::cast)
);

// TemporalAccessor -> CharSequence
Expand Down Expand Up @@ -166,9 +178,9 @@ public void register(ConversionService<?> conversionService) {
}
};
conversionService.addConverter(
LocalDateTime.class,
CharSequence.class,
localDateTimeConverter
LocalDateTime.class,
CharSequence.class,
localDateTimeConverter
);

addTemporalStringConverter(conversionService, Instant.class, DateTimeFormatter.ISO_INSTANT, Instant::from);
Expand Down Expand Up @@ -229,7 +241,7 @@ private <T extends TemporalAccessor> void addTemporalToDateConverter(ConversionS
private DateTimeFormatter resolveFormatter(ConversionContext context) {
Optional<String> format = context.getAnnotationMetadata().stringValue(Format.class);
return format
.map(pattern -> DateTimeFormatter.ofPattern(pattern, context.getLocale()))
.orElse(DateTimeFormatter.RFC_1123_DATE_TIME);
.map(pattern -> DateTimeFormatter.ofPattern(pattern, context.getLocale()))
.orElse(DateTimeFormatter.RFC_1123_DATE_TIME);
}
}

0 comments on commit dc9c4ad

Please sign in to comment.