Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for easter.js

(view source code of easter.js as plain text)

  1. // Easter.js,  Version 1.11 for WSH 1.0
  2. // Calculate Easter Day for a specified year
  3. // Written by Rob van der Woude
  4. // http://www.robvanderwoude.com
  5.  
  6. // Define variable to insert CR/LF
  7. jsCrLf = String.fromCharCode( 13, 10 );
  8.  
  9. // Determine current year
  10. objToday = new Date();
  11. thisYear = objToday.getFullYear();
  12.  
  13. // Check command line parameters
  14. objArgs = WScript.Arguments;
  15. if ( objArgs.length == 0 ) {
  16. 	// Default is current year
  17. 	myYear = thisYear;
  18. };
  19. if ( objArgs.length == 1 ) {
  20. 	// Check datatype and range of argument
  21. 	myYear = objArgs(0).valueOf( );
  22. 	if ( isNaN( myYear ) ) Syntax( );
  23. 	// Convert argument string to number
  24. 	myYear = Math.floor( myYear );
  25. 	if ( myYear < 1752 )   Syntax( );
  26. 	if ( myYear > 3000 )   Syntax( );
  27. };
  28. if ( objArgs.length > 1 ) Syntax( );
  29.  
  30.  
  31. // Calculate Easter Day using the instructions found at
  32. // Simon Kershaw's "KEEPING THE FEAST"
  33. // http://www.oremus.org/liturgy/etc/ktf/app/easter.html
  34. G   = ( myYear % 19 ) + 1;
  35. S   = Math.floor(( myYear - 1600 ) / 100 ) - Math.floor(( myYear - 1600 ) / 400 );
  36. L   = Math.floor(( Math.floor(( myYear - 1400 ) / 100 ) * 8 ) / 25 );
  37. PP  = ( 30003 - ( 11 * G ) + S - L ) % 30;
  38. if ( PP == 28 ) {
  39. 	if ( G > 11 ) {
  40. 		P = 27;
  41. 	}
  42. } else {
  43. 	if ( PP == 29 ) {
  44. 		P = 28;
  45. 	} else {
  46. 		P = PP;
  47. 	}
  48. }
  49. D   = ( Math.floor( myYear / 4 ) - Math.floor( myYear / 100 ) + Math.floor( myYear / 400 ) + myYear ) % 7;
  50. DD  = ( 8 - D ) % 7;
  51. PPP = ( 70003 + P ) % 7;
  52. X   = (( 70004 - D - P ) % 7 ) + 1;
  53. E   = P + X;
  54. if ( E < 11 ) {
  55. 	ED = E + 21;
  56. 	EM = "March";
  57. } else {
  58. 	ED = E - 10;
  59. 	EM = "April";
  60. }
  61. if ( myYear < thisYear ) {
  62. 	strIS = "was";
  63. } else {
  64. 	if ( myYear == thisYear ) {
  65. 		strIS = "is";
  66. 	} else {
  67. 		strIS = "will be";
  68. 	}
  69. }
  70.  
  71. // Display the result
  72. WScript.Echo( jsCrLf + "In " + myYear + " Easter Day " + strIS + " " + EM + " " + ED );
  73.  
  74. // Done
  75. WScript.Quit(0);
  76.  
  77.  
  78. function Syntax( ) {
  79. 	strMsg  = jsCrLf + "Easter.js,  Version 1.11 for WSH 1.0" + jsCrLf;
  80. 	strMsg += "Calculate the date of Easter Day for the specified year.";
  81. 	strMsg += jsCrLf + jsCrLf;
  82. 	strMsg += "Usage:  CSCRIPT  EASTER.JS  [ year ]";
  83. 	strMsg += jsCrLf + jsCrLf;
  84. 	strMsg += "Where:  year should be within the range 1752 through 3000";
  85. 	strMsg += jsCrLf + jsCrLf;
  86. 	strMsg += "Written by Rob van der Woude" + jsCrLf;
  87. 	strMsg += "http://www.robvanderwoude.com";
  88. 	strMsg += jsCrLf + jsCrLf;
  89. 	strMsg += "Based on the instructions found at" + jsCrLf;
  90. 	strMsg += "Simon Kershaw's 'KEEPING THE FEAST'" + jsCrLf;
  91. 	strMsg += "http://www.oremus.org/liturgy/etc/ktf/app/easter.html";
  92. 	WScript.Echo( strMsg );
  93. 	WScript.Quit(1);
  94. }
  95.  

page last modified: 2024-04-16; loaded in 0.0231 seconds