Exclude Leap day while finding difference between two dates
<p>Hello,</p>
<p> </p>
<p>I'm designing a report for Lease Management requirement where we are calculating the rent for the duration given. I have written a logic to find the number of days for year X given the start date and end date. For example, if you have start date as 1-DEC-2015 and end date as 31-MAR-2016 and want to find the number of days for year 2016, it will be 91 days (it's a leap year). But the result should be 90 days, as you don't want to pay the rent for an extra day. Ideally we pay the same monthly/yearly rent in leap year as well and don't pay for an extra one day.</p>
<p> </p>
<p>I have written the below logic which calculates the number of days but needs to be changed to exclude the extra leap day. Here, row["year0"] is calculated as per the parameter passed. If the parameter is passed as Current Year, year0 will be 2016. We have similar calculation for year1 (2017), year2 (2018), year3 (2019), year4 (2020) also.</p>
<p> </p>
<div>if (BirtComp.greaterOrEqual(row["StartDate"],new Date(row["year0"],00,01))</div>
<div>&& (BirtComp.lessOrEqual(row["StartDate"],new Date(row["year0"],11,31)))</div>
<div>&& (BirtComp.lessThan(row["StartDate"],row["EndDate"])))</div>
<div>{<span> </span></div>
<div>if (BirtComp.greaterOrEqual(row["EndDate"] ,new Date(row["year0"],11,31)))</div>
<div> <span> </span>{BirtDateTime.diffDay(row["StartDate"] ,new Date(row["year0"],11,31))+1}</div>
<div>else</div>
<div>{BirtDateTime.diffDay(row["StartDate"] ,(row["EndDate"]))+1}</div>
<div>}</div>
<div>else if(BirtComp.greaterOrEqual(row["EndDate"],new Date(row["year0"],00,01))</div>
<div>&& (BirtComp.lessOrEqual(row["EndDate"],new Date(row["year0"],11,31)))</div>
<div>&& (BirtComp.lessThan(row["StartDate"],row["EndDate"])))</div>
<div> </div>
<div>{BirtDateTime.diffDay(new Date(row["year0"],00,01),row["EndDate"])+1}</div>
<div> </div>
<div>else if (BirtComp.lessThan(row["StartDate"],new Date(row["year0"],00,01)) </div>
<div>&& (BirtComp.greaterThan(row["EndDate"] ,new Date(row["year0"],11,31)))</div>
<div>&& (BirtComp.lessThan(row["StartDate"],row["EndDate"])))</div>
<div> </div>
<div>{365}</div>
<div> </div>
<div>else</div>
<p>{0} </p>
<p> </p>
<p>Can anyone please help me to include the logic for leap day exclusion? It might require to consider multiple scenarios.</p>