Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Design problem - next occurence of date

Status
Not open for further replies.

LesleyW

Programmer
Mar 12, 2001
196
GB
Hi folks, have a design problem which some of you must have encountered before as I know this scenario crops up in lots of places. It's proving quite tricky to pin down the solution. I'm using OO techniques - it's not really an OO problem as such, but I can't find a general "system design" forum!

The problem in a nutshell is working out the next occurence of a particular day in a time frequency. E.g Weekly, Monday; 31st, Monthly; 1st, Quarterly, pay 2nd month in quarter. If the calculated date is not a working day ie. Saturday, Sunday or Bank Holiday, use the next earliest day.

I have a database table which keeps track of all working days so we can plug in the bank holidays when we know them. And a function we can put in the date and it tells us if it's a working day or not. No problem.

I have an object that stores the payment frequency and required day of week, day of month and/or month of quarter. There is also data to support half yearly payment and annual payment but I've ignored them here for simplicity(!)

There is a method on the object which calculates the next payment due date which I'm working on now. The object itself has the data to work out what the frequency and the desired day is. My difficulty is that the method can be called in 2 situations - if the object has just been updated e.g. on the 15th January, you update it to monthly payment on the 31st of the month, so you want to set the date to 31st January. The other situation is that the customer has just been paid and you need to work out the next date. e.g. you pay them on the 31st January and need to work out the next date when monthly payment on the 31st. In this situation we need to pay them on the 28th February. I had everything worked out but realised I had ignored the above situation... my immediate reaction was if the day required was greater than 28 to check the number of days in the following month ... but what month are you looking at? In scenario 1 it's Januray and in 2 it's February....

I've done tons of work on it and I'm sure I can figure out something. However it's a situation that some of us must have come across before so .... has anyone done this and can give me some pointers/patterns to work with?
 
Is not the period of the payment the key?

If you are processing a half-month payment (15th... 31th) you need to check into the same month; if you are processing a monthly payment (31th... 31th) you need to check into the next month.

Or am I getting your meaning wrong?

buho (A).
 
There's no half-month payment... there's a half-year payment, for which they specify which 2 months they want to be paid (have to be 6 months apart) e.g. HalfYearID 1 means pay in Jan and July. Similarly with quarters QuarterID 1 means pay in Jan/Apr/Jul/Oct.

Your response is similar to my initial one, in that it looks easy but it's not. Whether you look in the current month or the next month depends on the current date. For example, If your payment day is 31 and it's currently the be 15th, you look in current month, or if today's the 31st you look in next month. Which month do you check the number of days in? If today is the 28th Feb and the payment day is 30th, you clearly look in next month. However if today is the 15th of Feb and payment day is the 30th, we need to return the 28th Feb. Actually, that was a useful exercise... I'm now seeing that if you are past that day in the current month you look to the following month, ohterwise you look in the current month.

Hey ho, after I've checked that works I'll have to look at the problems involved in quarterly payment which are probably just as vexing!

Any input gratefully received.. this is an interesting problem!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top