Accounting for leap year in comparing year to year sales

百般思念 提交于 2019-12-11 03:33:18

问题


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.


回答1:


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




回答2:


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".




回答3:


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!



回答4:


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.



来源:https://stackoverflow.com/questions/610752/accounting-for-leap-year-in-comparing-year-to-year-sales

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!