Gives June 1 in 2009 & 2015.
Gives Saturdays.
The original code, as posted, fails to run.
Oops I thought I saw 'a - (b + 1)'. My mistake. But back to my
original question, is the '+' an undocumented way of doing day
incrementing/decrementing?
It is undocumented because assigning a number to a variable "holding" a
Date Object disconnects the Date Object and makes the variable hold a
Number.
AIUI, Memorial Day is the last Monday in May in America - elsewhere, it
may be different.
Such code should, if it is required to run in all years, be tested in
all types of year. For ordinary dates, that's 14 types - Leap or not,
starting on Mon-Sun. All types necessarily occur in any 28-year stretch
lacking a missing Leap Year.
So test in this sort of manner :-
for (Y=2000 ; Y<2030; Y++) {
memDayHol = new Date (Y, 4, 31);
memDayHol.setDate(memDayHol.getDate()-memDayHol.getDay()+1);
document.writeln(memDayHol, "<br>") }
The easiest way to get the last X-day of a month is to think of it as
the Zeroth X-day of the following month. There is then no need to know
the length of any month.
Reading the FAQ can get you to
function NthXdayOfYM(N, X, Y, M) { var D
// X = Sun=0..Sat=6 Sun=7.. , M=1..12, N=0 for last of prev mth.
with (D = new Date(Y, M-1, 1))
{ setDate(7*N - 6 + (7+X-getDay())%7 ) }
return D }
and test with
for (Y=2000 ; Y<2030; Y++) {
document.writeln(NthXdayOfYM(0, 1, Y, 6), "<br>") }
shows Mondays in May 25-31 as needed.
I rather believe, without remembering proving it, that such jobs always
require a conditional or a %7.
Does any nation have a Special Day on the last, last but one, etc.,
X-day of February each year?
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.