Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for easter.pl

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

  1. #! perl
  2.  
  3. # Check command line parameters
  4. if ( !$ARGV[0] ) {
  5. 	($sec,$min,$hour,$mday,$mon,$ChkYear,$wday,$yday,$isdst) = localtime(time);
  6. 	$ChkYear = $ChkYear + 1900;
  7. } else {
  8. 	if ( $ARGV[1] ) {
  9. 		Syntax( );
  10. 	} else {
  11. 		$strChkYear = $ARGV[0];
  12. 		$ChkYear = abs( $strChkYear );
  13. 		if ( $strChkYear != $ChkYear ) {
  14. 			Syntax( );
  15. 		}
  16. 		if ( ( $ChkYear < 1752 ) or ( $ChkYear > 3000 ) ) {
  17. 			Syntax( );
  18. 		}
  19. 	}
  20. }
  21.  
  22. # Calculate Easter Day using the instructions found at
  23. # Simon Kershaw's "KEEPING THE FEAST"
  24. # http://www.oremus.org/liturgy/etc/ktf/app/easter.html
  25.  
  26. $G  = ( $ChkYear % 19 ) + 1;
  27. $S  = int( ( $ChkYear - 1600 ) / 100 ) - int( ( $ChkYear - 1600 ) / 400 );
  28. $L  = int( ( int( ( $ChkYear - 1400 ) / 100 ) * 8 ) / 25 );
  29. $PP = ( 30003 - 11 * $G + $S - $L ) % 30;
  30. if ( ( ( $PP == 28 ) and ( $G > 11 ) ) or ( $PP == 29 ) ) {
  31. 	$P = $PP - 1;
  32. } else {
  33. 	$P = $PP;
  34. }
  35. $D   = ( $ChkYear + int( $ChkYear / 4 ) - int( $ChkYear / 100 ) + int( $ChkYear / 400 )) % 7;
  36. $DD  = ( 8 - $D ) % 7;
  37. $PPP = ( 70003 + $P ) % 7;
  38. $X   = (( 70004 - $D - $P ) % 7 ) + 1;
  39. $E   = $P + $X;
  40. if ( $E < 11 ) {
  41. 	$ED = $E + 21;
  42. 	$EM = "March";
  43. } else {
  44. 	$ED = $E - 10;
  45. 	$EM = "April";
  46. }
  47.  
  48. # Use default if no (valid) year was specified
  49. if ( ( $year < 0 ) or ( $year > 10000 ) or !( $year ) ) {
  50. 	# Parse time string
  51. 	($s,$m,$h,$md,$mo,$thisYear,$wd,$yd,$isdst) = localtime(time);
  52. 	$thisYear = $thisYear + 1900;
  53. }
  54. if ( $ChkYear < $thisYear ) {
  55. 	$Is = "was";
  56. } else {
  57. 	if ( $ChkYear == $thisYear ) {
  58. 		$Is = "is";
  59. 	} else {
  60. 		$Is = "will be";
  61. 	}
  62. }
  63.  
  64. # Display the result
  65. print( "\nIn $ChkYear Easter Day $Is $EM $ED\n" );
  66.  
  67. # Done
  68. exit 0;
  69.  
  70.  
  71.  
  72. sub Syntax {
  73. 	print "\nEaster.pl,  Version 1.00\n",
  74. 	      "Calculate the date of Easter Day for the specified year\n\n",
  75. 	      "Usage:  EASTER.PL  [ year ]\n\n",
  76. 	      "Where:  year should be within the range of 1752 through 3000",
  77. 	      "\n\nWritten by Rob van der Woude\n",
  78. 	      "http://www.robvanderwoude.com\n\n",
  79. 	      "Based on the instructions found at\n",
  80. 	      "Simon Kershaw\'s \"KEEPING THE FEAST\"",
  81. 	      "http://www.oremus.org/liturgy/etc/ktf/app/easter.html\n";
  82. 	exit 1;
  83. }
  84.  

page last uploaded: 2017-04-06, 13:33