views:

232

answers:

4

I am writing a program that shows the current years sales from the beginning of the fiscal year to the current date, compared to the same date range of the year before.

My question is, what efforts do I need to take for leap year?

UPDATE:

OK they want it like I said (compare last year up to same date) but if today is non leap year and last year is and today is feb 28th compare to last year up to 29th. Or if today is Feb 29th compare to last year up to 28th.

+4  A: 

Surely that depends on what the business wants you to do. Isn't this a question that should be answered by an accountant?

MatthieuF
+3  A: 

This strikes me as a business decision. Depending on the type of business, that extra day may not matter. Otherwise, I suppose you could treat is as "first n days of the year" rather than "Jan 1 through X".

Pesto
If I did that tho and only compared last years up to this years at the same current days at the end of the year it would be off bc this year there was 365 days and last year there were 366, so if today was the 365 day, the year would be over but it wouldn't be comparing to the total year before.
John Isaacks
@unknown: if that is the case, you could compare the two years together, but then "subtract" out the sales for February 29th and show them separately. That way you could have a fairly accurate 365-365 comparison.
TheTXI
@unknown: Which is why this is a business decision. We're happy to point out the things that need to be figured out, but ultimately you guys are going to have to pick an implementation.
Pesto
@pesto OK I am going to get more requirements info from the man in charge and then edit my post to make it more specific.
John Isaacks
+1  A: 

Here's an idea, but like others have said it might be based on your specific domain.

  1. Consider 1 "normalized" year = 365.242199 days counting all the leap stuff (says google)
  2. Calculate the average sales per day in your year based on the real number of days in that year
  3. Scale it up or down to sales per 365.242199 days

So for example

   2007 = $4000 in sales.
   There's 365 days in 2007, so avg sale per day = $10.96
   Multpiplying times num days in a normalized year (365.242199) 
      gives you $4003.05 normalized sales

You can compare this directly to a similar calculation for 2008,

   2008 = $5000 in sales.
   There's 366 days in 2008, so avg sale per day = $13.66
   Multpiplying times num days in a normalized year (365.242199) 
      gives you $4975.655 normalized sales for 2008!
Doug T.
A: 

You could scale down the leap year values to take the extra day into account.

So if you compare, say, the 1st of September of a regular year with the 1st of September of a leap year you would do:

if(year == leapyear && day > 28Feb)
    Convert date to dayOfYear
    leapYearValue *= dayOfYear / (dayOfYear + 1)

This should really be in the specification, though.

drby