I've scenario where custom financial calendar is defined. Sometimes the month can be of 28 days or sometimes it can be of 35 days as well. The start of every month varies. (It can start from 10/15/20th)
For referring which calendar date refers to which financial date, I've defined a table which has following column structure:
In above table you can see that fiscalmonth
P1
refers to the date 20190125. (It can be the case that fiscalmonth-P1
is starting from 20190115
to 20190215
This table is in database. I'm working on java part to create functionality which will return Periodbetween
object based on two fiscal dates provided(which will refer to yyyymmdd
column of above table) to function.
public class PeriodBetween {
private int days;
private int weeks;
private int months;
private int quarters;
private int years;
//getters & setters
}
This periodBetween
object gives more information about number of days/weeks/months/quarters in between this two dates.
public PeriodBetween between(int startDate, int endDate)
I was looking into something to build like what's there in Java's java.time.Period.between
function. But not able to get what best approach I can use by referring to table that is defined above.
Let me know if something like this already exist or there can be other way apart from using Financial Calendar
table.
Updates:
The scenario of sometimes the calendar cab be of 28 days or 35 days is based on which calendar is followed by customer. So depending on client the Financial Calendar Table
will be populated.
Fiscal Calendar is not predictable. It will be pre populated in table based on requirement.
Yes the Fiscal Calendar Table
follow 52 as well as 52 week support. So to give you higher level of idea the table will be populated based on what type of custom calendar is used by customer.
How I am defining my calendar right now ?
Getting the requirement from customer on how they want the calendar to be defined. Using that I'm populating the table mentioned above & using that table everywhere.
So let's say on Financial Calendar I want to find out what is 3rd day of P3 month on Financial year 2018
.
Then my query to this table will be to extract more information on this day will be: select * from financial_calendar where fiscaldayofmonth=3 and fiscalmonth=P3 and fiscalyear=Financial Year 2018
My thoughts of calculating number of months between two dates is to extract information from table using between clause of two dates & divide the data size by 30. Which is incorrect.