adamsaghy commented on code in PR #5559:
URL: https://github.com/apache/fineract/pull/5559#discussion_r2871220373


##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java:
##########
@@ -474,4 +476,26 @@ public static LocalDateTime 
convertDateTimeStringToLocalDateTime(String dateTime
     public static LocalDate min(@NonNull LocalDate date1, @NonNull LocalDate 
date2) {
         return date1.isBefore(date2) ? date1 : date2;
     }
+
+    /**
+     * Builds a {@link MonthDay} from month and day, clamping the day to the 
last valid day of the month if necessary.
+     * Use when reading (month, day) from storage (e.g. fee_on_month, 
fee_on_day) where the combination may be invalid
+     * (e.g. day 30 for February).
+     * <p>
+     * Uses a fixed leap year (2024) so that February has 29 days. We want the 
<em>maximum</em> valid day per month, not
+     * "valid in the current year". If the year were dynamic, in a non-leap 
year we would clamp Feb 29 to Feb 28 and
+     * lose valid stored values; callers that use the resulting MonthDay in a 
specific year handle non-leap February
+     * (e.g. use Feb 28) themselves.
+     *
+     * @param month
+     *            month 1–12
+     * @param day
+     *            day of month (may exceed month length; will be clamped)
+     * @return valid MonthDay (day clamped to month length; February allows 29)
+     */
+    public static MonthDay safeMonthDay(int month, int day) {
+        int maxDay = YearMonth.of(2024, month).lengthOfMonth();
+        int safeDay = Math.min(day, maxDay);
+        return MonthDay.of(month, safeDay);

Review Comment:
   Having Feb 29 is just as bad as having feb 30 or feb 31... leap years has 
only feb 29 only...  so from 4 years 3 has feb 28 only, i dont see any 
improvement here... 
   
   Am I missing something here?



-- 
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]

Reply via email to