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 dae72a7
Showing 1 changed file with 24 additions and 12 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 @@ -122,16 +134,16 @@ public void register(ConversionService<?> conversionService) {

// CharSequence -> Duration
conversionService.addConverter(
CharSequence.class,
Duration.class,
(object, targetType, context) -> durationConverter.apply(object, context)
CharSequence.class,
Duration.class,
(object, targetType, context) -> durationConverter.apply(object, context)
);

// 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 dae72a7

Please sign in to comment.