开发者

Javascript algorithm that calculates week number in Fiscal Year

I have been looking for a Javascript algorithms that gives me the week number of a given Date object within a custom fiscal year. The fiscal year of my company starts on 1 September and ends on 3开发者_如何学Go1 August.

Say today happens to be September 1st and I pass in a newly instanced Date object to this function; I would expect it to return 1.

Hopefully someone will be able to help me with it.


Say you want the fiscal year for date X.

if X > September 1st
  week = week_nr(X) - week_nr(Sept 1st) + 1
else
  // We're in a new year
  week = week_nr(X) + week_nr(Sept 1st) - 1

That should do it - maybe there's a problem around new year, but easy enough to figure out I guess.

To get the week number within any year, there are plenty of solutions. Here's just one of them: http://syn.ac/tech/19/get-the-weeknumber-with-javascript/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜