Spotless.

This commit is contained in:
Luke deGruchy 2024-09-26 15:31:04 -04:00
parent b5a18002c3
commit d9fc74ee9d
3 changed files with 20 additions and 28 deletions

View File

@ -110,7 +110,8 @@ public final class DateUtils {
* @param theTemporalAccessor The TemporalAccessor containing date/time information
* @return A LocalDateTime or empty
*/
public static Optional<LocalDateTime> extractLocalDateTimeForRangeStartOrEmpty(TemporalAccessor theTemporalAccessor) {
public static Optional<LocalDateTime> extractLocalDateTimeForRangeStartOrEmpty(
TemporalAccessor theTemporalAccessor) {
if (theTemporalAccessor.isSupported(ChronoField.YEAR)) {
final int year = theTemporalAccessor.get(ChronoField.YEAR);
final Month month = Month.of(getTimeUnitIfSupported(theTemporalAccessor, ChronoField.MONTH_OF_YEAR, 1));
@ -137,10 +138,9 @@ public final class DateUtils {
final int year = theTemporalAccessor.get(ChronoField.YEAR);
final Month month = Month.of(getTimeUnitIfSupported(theTemporalAccessor, ChronoField.MONTH_OF_YEAR, 12));
final int day = getTimeUnitIfSupported(
theTemporalAccessor,
ChronoField.DAY_OF_MONTH,
YearMonth.of(year, month).atEndOfMonth().getDayOfMonth()
);
theTemporalAccessor,
ChronoField.DAY_OF_MONTH,
YearMonth.of(year, month).atEndOfMonth().getDayOfMonth());
final int hour = getTimeUnitIfSupported(theTemporalAccessor, ChronoField.HOUR_OF_DAY, 23);
final int minute = getTimeUnitIfSupported(theTemporalAccessor, ChronoField.MINUTE_OF_HOUR, 59);
final int seconds = getTimeUnitIfSupported(theTemporalAccessor, ChronoField.SECOND_OF_MINUTE, 59);
@ -151,7 +151,6 @@ public final class DateUtils {
return Optional.empty();
}
/**
* With the provided DateTimeFormatter, parse a date time String or return empty if the String doesn't correspond
* to the formatter.
@ -175,11 +174,11 @@ public final class DateUtils {
private static int getTimeUnitIfSupported(
TemporalAccessor theTemporalAccessor, TemporalField theTemporalField, int theDefaultValue) {
return getTimeUnitIfSupportedOrEmpty(theTemporalAccessor, theTemporalField)
.orElse(theDefaultValue);
.orElse(theDefaultValue);
}
private static Optional<Integer> getTimeUnitIfSupportedOrEmpty(
TemporalAccessor theTemporalAccessor, TemporalField theTemporalField) {
TemporalAccessor theTemporalAccessor, TemporalField theTemporalField) {
if (theTemporalAccessor.isSupported(theTemporalField)) {
return Optional.of(theTemporalAccessor.get(theTemporalField));
}

View File

@ -29,6 +29,7 @@ import java.util.StringJoiner;
public class MeasurePeriodForEvaluation {
@Nullable
private final String myPeriodStart;
@Nullable
private final String myPeriodEnd;

View File

@ -35,24 +35,22 @@ import java.util.Optional;
// LUKETODO: changelog
// LUKETODO: javadoc
// LUKETODO: unit test
public class MeasureReportPeriodRequestProcessingService {
private static final Logger ourLog = LoggerFactory.getLogger(MeasureReportPeriodRequestProcessingService.class);
private static final DateTimeFormatter DATE_TIME_FORMATTER_YYYY_INPUT = DateTimeFormatter.ofPattern("yyyy");
private static final DateTimeFormatter DATE_TIME_FORMATTER_YYYY_MM_INPUT = DateTimeFormatter.ofPattern("yyyy-MM");
private static final DateTimeFormatter DATE_TIME_FORMATTER_YYYY_MM_DD_INPUT = DateTimeFormatter.ISO_DATE;
private static final DateTimeFormatter DATE_TIME_FORMATTER_YYYY_MM_DD_HH_MM_SS_INPUT = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
private static final DateTimeFormatter DATE_TIME_FORMATTER_YYYY_MM_DD_HH_MM_SS_INPUT =
DateTimeFormatter.ISO_LOCAL_DATE_TIME;
private static final DateTimeFormatter DATE_TIME_FORMATTER_YYYY_MM_DD_HH_MM_SS_Z_OUTPUT =
DateTimeFormatter.ISO_OFFSET_DATE_TIME;
private static final Map<Integer, DateTimeFormatter> VALID_DATE_TIME_FORMATTERS_BY_FORMAT_LENGTH =
Map.of(
private static final Map<Integer, DateTimeFormatter> VALID_DATE_TIME_FORMATTERS_BY_FORMAT_LENGTH = Map.of(
4, DATE_TIME_FORMATTER_YYYY_INPUT,
7, DATE_TIME_FORMATTER_YYYY_MM_INPUT,
10, DATE_TIME_FORMATTER_YYYY_MM_DD_INPUT,
19, DATE_TIME_FORMATTER_YYYY_MM_DD_HH_MM_SS_INPUT
);
19, DATE_TIME_FORMATTER_YYYY_MM_DD_HH_MM_SS_INPUT);
private final ZoneId myFallbackTimezone;
@ -84,17 +82,15 @@ public class MeasureReportPeriodRequestProcessingService {
if (dateTimeFormatterStart == null) {
throw new InvalidRequestException(String.format(
"Unsupported Date/Time format for period start: %s or end: %s",
thePeriodStart, thePeriodEnd)
);
"Unsupported Date/Time format for period start: %s or end: %s", thePeriodStart, thePeriodEnd));
}
final Optional<LocalDateTime> optLocalDateTimeStart =
DateUtils.parseDateTimeStringIfValid(thePeriodStart, dateTimeFormatterStart)
final Optional<LocalDateTime> optLocalDateTimeStart = DateUtils.parseDateTimeStringIfValid(
thePeriodStart, dateTimeFormatterStart)
.flatMap(DateUtils::extractLocalDateTimeForRangeStartOrEmpty);
final Optional<LocalDateTime> optLocalDateTimeEnd =
DateUtils.parseDateTimeStringIfValid(thePeriodEnd, dateTimeFormatterStart)
final Optional<LocalDateTime> optLocalDateTimeEnd = DateUtils.parseDateTimeStringIfValid(
thePeriodEnd, dateTimeFormatterStart)
.flatMap(DateUtils::extractLocalDateTimeForRangeEndOrEmpty);
if (optLocalDateTimeStart.isEmpty() || optLocalDateTimeEnd.isEmpty()) {
@ -115,15 +111,11 @@ public class MeasureReportPeriodRequestProcessingService {
}
return new MeasurePeriodForEvaluation(
formatWithTimezone(localDateTimeStart, theZoneId),
formatWithTimezone(localDateTimeEnd, theZoneId)
);
formatWithTimezone(localDateTimeStart, theZoneId), formatWithTimezone(localDateTimeEnd, theZoneId));
}
private String formatWithTimezone(
LocalDateTime theLocalDateTime, ZoneId theZoneId) {
return theLocalDateTime.atZone(theZoneId)
.format(DATE_TIME_FORMATTER_YYYY_MM_DD_HH_MM_SS_Z_OUTPUT);
private String formatWithTimezone(LocalDateTime theLocalDateTime, ZoneId theZoneId) {
return theLocalDateTime.atZone(theZoneId).format(DATE_TIME_FORMATTER_YYYY_MM_DD_HH_MM_SS_Z_OUTPUT);
}
private ZoneId getClientTimezoneOrInvalidRequest(RequestDetails theRequestDetails) {