Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.serialization.JsonParserHelper;
import org.apache.logging.log4j.util.Strings;
import org.springframework.lang.NonNull;

public final class DateUtils {
Expand Down Expand Up @@ -464,6 +465,36 @@ public static LocalDateTime convertDateTimeStringToLocalDateTime(String dateTime
}
}

public static OffsetDateTime convertDateTimeStringToOffsetDateTime(String dateTimeStr, String dateFormat, String localeStr,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we follow the naming convention in this utility parseOffsetDateTime would be consequent.
There are other parseOffsetDateTime methods, could you please move this next to them?

LocalTime fallbackTime) {
if (Strings.isEmpty(dateTimeStr)) {
return null;
}
final Locale locale = localeStr == null ? null : JsonParserHelper.localeFromString(localeStr);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locale locale should be passed as parameter

DateTimeFormatter formatter = getDateFormatter(dateFormat, locale);
TemporalAccessor parsed = formatter.parse(dateTimeStr);

boolean hasTime = parsed.isSupported(ChronoField.HOUR_OF_DAY) && parsed.isSupported(ChronoField.MINUTE_OF_HOUR);
boolean hasOffset = parsed.isSupported(ChronoField.OFFSET_SECONDS);

try {
if (hasTime && hasOffset) {
return OffsetDateTime.from(parsed);
} else if (hasTime) {
LocalDateTime localDateTime = LocalDateTime.from(parsed);
return localDateTime.atOffset(ZoneOffset.UTC);
} else {
LocalDate date = LocalDate.from(parsed);
LocalDateTime localDateTime = LocalDateTime.of(date, fallbackTime);
return localDateTime.atOffset(ZoneOffset.UTC);
}
} catch (final DateTimeParseException e) {
final List<ApiParameterError> errors = List.of(ApiParameterError.parameterError("validation.msg.invalid.date.pattern",
"The parameter date (" + dateTimeStr + ") format is invalid", "date", dateTimeStr));
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", errors, e);
}
}

/**
* Returns the earlier date. If date1 is before date2 it return date1 otherwise date2.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import jakarta.ws.rs.QueryParam;
import java.io.Serial;
import java.io.Serializable;
import java.time.ZonedDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.fineract.infrastructure.core.service.DateUtils;

@Setter
@Getter
Expand All @@ -43,9 +45,9 @@ public class MakerCheckerRequest implements Serializable {
@QueryParam("makerId")
private Long makerId;
@QueryParam("makerDateTimeFrom")
private ZonedDateTime makerDateTimeFrom;
private String makerDateTimeFrom;
@QueryParam("makerDateTimeTo")
private ZonedDateTime makerDateTimeTo;
private String makerDateTimeTo;
@QueryParam("clientId")
private Long clientId;
@QueryParam("loanid")
Expand All @@ -56,4 +58,16 @@ public class MakerCheckerRequest implements Serializable {
private Long groupId;
@QueryParam("savingsAccountId")
private Long savingsAccountId;
@QueryParam("dateFormat")
private String dateFormat;
@QueryParam("locale")
private String locale;

public OffsetDateTime getMakerDateTimeFrom() {
return DateUtils.convertDateTimeStringToOffsetDateTime(makerDateTimeFrom, dateFormat, locale, LocalTime.MIN);
}

public OffsetDateTime getMakerDateTimeTo() {
return DateUtils.convertDateTimeStringToOffsetDateTime(makerDateTimeTo, dateFormat, locale, LocalTime.MAX);
}
}
Loading