galovics commented on code in PR #3352: URL: https://github.com/apache/fineract/pull/3352#discussion_r1286652898
########## fineract-core/src/main/java/org/apache/fineract/infrastructure/core/data/DateFormat.java: ########## @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.core.data; + +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.format.ResolverStyle; +import java.time.temporal.ChronoField; +import java.util.List; +import lombok.Getter; +import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; + +public class DateFormat { + + @Getter + private final String dateFormat; + + public DateFormat(String rawDateFormat) { + String compatibleDateFormat = rawDateFormat.replace("yyyy", "uuuu"); Review Comment: Let's add a nullcheck before here as well. ########## fineract-core/src/main/java/org/apache/fineract/infrastructure/core/serialization/JsonParserHelper.java: ########## @@ -518,17 +524,25 @@ public static LocalDate convertFrom(final String dateAsString, final String para return convertDateTimeFrom(dateAsString, parameterName, dateFormat, clientApplicationLocale).toLocalDate(); } - public static LocalDateTime convertDateTimeFrom(final String dateTimeAsString, final String parameterName, final String dateTimeFormat, + public static LocalDate convertFrom(final String dateAsString, final String parameterName, final DateFormat dateFormat, + final Locale clientApplicationLocale) { + + return convertDateTimeFrom(dateAsString, parameterName, dateFormat.getDateFormat(), clientApplicationLocale).toLocalDate(); + } + + private static LocalDateTime convertDateTimeFrom(final String dateTimeAsString, final String parameterName, String dateTimeFormat, final Locale clientApplicationLocale) { validateDateFormatAndLocale(parameterName, dateTimeFormat, clientApplicationLocale); LocalDateTime eventLocalDateTime = null; if (StringUtils.isNotBlank(dateTimeAsString)) { try { + dateTimeFormat = dateTimeFormat.replace("y", "u"); Review Comment: Same as above. ########## fineract-core/src/main/java/org/apache/fineract/infrastructure/core/serialization/JsonParserHelper.java: ########## @@ -459,28 +462,31 @@ public LocalTime extractLocalTimeNamed(final String parameterName, final JsonEle return value; } - public LocalDateTime extractLocalDateTimeNamed(final String parameterName, final JsonElement element, final String timeFormat, + public LocalDateTime extractLocalDateTimeNamed(final String parameterName, final JsonElement element, String timeFormat, final Locale clientApplicationLocale, final Set<String> parametersPassedInCommand) { LocalDateTime value = null; - String timeValueAsString = null; + String timeValueAsString; if (element.isJsonObject()) { final JsonObject object = element.getAsJsonObject(); if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) { parametersPassedInCommand.add(parameterName); try { - DateTimeFormatter timeFormtter = DateTimeFormatter.ofPattern(timeFormat); + timeFormat = timeFormat.replace("y", "u"); Review Comment: I don't think we need this anymore, do we? -- 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]
