cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Craige_Hales
Super User
Doomsday

Valentine's day coincides with Doomsday this year.  Again. 

The Doomsday rule is neat, here's a JSL snippet to illustrate part of the idea.

 

For( year = 1901, year <= 2099, year++, // 1900 was not a leap year and 2100 won't be
  really =
  Day Of Week( Date DMY( if(mod(year,4),3,4), 1, year ) ) == // 3rd day of January, 3 years out of 4
  Day Of Week( Date DMY( if(mod(year,4),28,29), 2, year ) ) == // last day of February (29 on leap years)
  Day Of Week( Date DMY( 14, 3, year ) ) == // PI-day
  Day Of Week( Date DMY( 4, 4, year ) ) == // even months, same day, after February
  Day Of Week( Date DMY( 6, 6, year ) ) == //
  Day Of Week( Date DMY( 8, 8, year ) ) == //
  Day Of Week( Date DMY( 10, 10, year ) ) == //
  Day Of Week( Date DMY( 12, 12, year ) ) == //
  Day Of Week( Date DMY( 7, 11, year ) ) == // familiar store name in US
  Day Of Week( Date DMY( 11, 7, year ) ) == //
  Day Of Week( Date DMY( 9, 5, year ) ) == // 9-to-5 working hours
  Day Of Week( Date DMY( 5, 9, year ) ) == //
  Day Of Week( Date DMY( 4, 7, year ) ) == // US Independence Day
  Day Of Week( Date DMY( 26, 12, year ) ); // boxing day
  If( !really, Show( year ) );
);
Write( "done\!n" );
Write( {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"}[Day Of Week( Date DMY( 4, 4, 2015 ) )] );

The cool part of the rule is the memorable pattern of dates throughout the year (after February, at least) that fall on the same day of the week all year long.  For 2015, Doomsday is Saturday; 4/4/2015, 6/6/2015, 8/8/2015, 10/10/2015, 12/12/2015 are all Saturdays,  As are 7/11, 11/7, 5/9, and 9/5.  DMY or MDY.  Lucky for us leap days happen fairly early in the year or the rule would be uglier.

The mod() function is used in the JSL above to pick the right days in January and February depending on leap years.  Remember 2000 was a leap year because it was divisible by 400, even though most years divisible by 100 are not leap years...thus the limit on the for loop.

You might be wondering about the chain of == comparisons in the JSL, especially if you are a programmer familiar with almost any other programming language.  JMP really does that.  For example (don't mix'n'match < and > ),

1 < 2 < 3 < 4 < 5

1

and

1 < 2 < 4 < 3 < 5

0

In the JSL above, the result of the chain of == is assigned to really; the value is 1 so the !really test is 0 and the JSL never prints a year because they all pass the test.  If you add 1900 or 2100 to the for loop, they will print, not because the Doomsday rule is wrong, but because the JSL above doesn't pick the right days in January and February.

The final statement needs a little explaining too:

Write( {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}[Day Of Week( Date DMY( 4, 4, 2015 ) )] );

Saturday

That's one call to the write() function; the list of days in { curly brackets } is subscripted by the expression in [ square brackets ].  DayOfWeek returns 1 for Sunday ... 7 for Saturday for whatever date is supplied.  April 4 is always on Doomsday.

edit  30Sep2017: repair formatting

Last Modified: Sep 30, 2017 10:03 AM