Hi,
I have a requirement to update a date based on a condition that if the given date is of last 2 dates of that particular month, then I want my rule to return first date of the next month and it should be applicable for all the dates whether the month has 30 or 31 days or if it is February or leap year.
For eg: 27/02/2023 should be converted to 01/03/2023.
I have written following code for this, but my senior asks me to optimize the code and reduce the use of if conditions. Please tell me what else I can do
edit:
a!localVariables( local!currentMonth: month(ri!requestDate), local!currentDay: day(ri!requestDate), local!currentYear: year(ri!requestDate), local!isLeapYear: isleapyear(local!currentYear), todate( if( and( tointeger(local!currentMonth) = 2, or(local!isLeapYear), contains( tointeger({ 28, 29 }), tointeger(local!currentDay) ) ), concat( tointeger(local!currentMonth) + 1, "/", 1, "/", local!currentYear ), if( and( tointeger(local!currentMonth) = 2, not(or(local!isLeapYear)), contains( tointeger({ 27, 28 }), tointeger(local!currentDay) ) ), concat( tointeger(local!currentMonth) + 1, "/", 1, "/", local!currentYear ), if( and( tointeger(local!currentMonth) <> 2, contains( tointeger({ 30, 31 }), tointeger(local!currentDay) ) ), concat( if( tointeger(local!currentMonth) = 12, 1, local!currentMonth + 1 ), "/", 1, "/", if( tointeger(local!currentMonth) = 12, local!currentYear + 1, local!currentYear ) ), ri!requestDate ) ) ) ) )
Thanks you for help
Discussion posts and replies are publicly visible
First of all, edit this question and re paste your code in a code box.
Sorry for that I have edited it
Thank you so much for the response.