Computing the Nth DoW of Any Year / MonthThis algorithm handles the problem of computing the Nth DoW of a given year and month. It was designed to help determine such things as the calendar dates of moving dates like Election Day and holidays (U.S.), like Thanksgiving Day.
For example, if a certain holiday was always observed on the third (N=3) Monday (DoW=1) of a certain month (m=Month number), then the following algorithm could be used to find the corresponding calendar date for any given year (y).
To compute the (
Given the above arguments and using Algorithm 1 and Algorithm 2, the following pseudocode algorithm computes the ISO integer-encoded date (
Compute the corresponding ISO integer-encoded date (
if (y < 0) then YearSign = -1 else YearSign = 1 ISOymd1 = YearSign*(10000*abs(y) + 100*m + 1) JD1 = JD_For_ISOymd (ISOymd1, CalMode) DoW1 = (JD1 + 1) mod 7 dDoW = DoW - DoW1 if (dDoW < 0) then u = dDoW + 7 else u = dDoW JD = JD1 + u + 7*(N-1) ISOymd = ISOymd_For_JD (JD, CalMode)or
ISOymd1 = ((y < 0)? -1:1)*(10000*abs(y) + 100*m + 1) JD1 = JD_For_ISOymd (ISOymd1, CalMode) DoW1 = (JD1 + 1) mod 7 dDoW = DoW - DoW1 JD = JD1 + ((dDoW < 0)? dDoW + 7 : dDoW) + 7*(N-1) ISOymd = ISOymd_For_JD (JD, CalMode)
© PHP Science Labs - 2017