Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for easter.vbs

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

  1. ' Easter.vbs,  Version 1.01 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. ' Check command line parameters
  7. Select Case WScript.Arguments.Count
  8. 	Case 0
  9. 		ChkYear = Year(Date)
  10. 	Case 1
  11. 		strChkYear = Wscript.Arguments(0)
  12. 		On Error Resume Next
  13. 		ChkYear = CInt(strChkYear)
  14. 		If Err.Number <> 0 Then
  15. 			Syntax
  16. 			Wscript.Quit(1)
  17. 		End If
  18. 		If VarType(ChkYear) <> 2 Then
  19. 			Syntax
  20. 			Wscript.Quit(1)
  21. 		End If
  22. 		ChkYear = CInt(Wscript.Arguments(0))
  23. 		If ChkYear < 1752 Or ChkYear > 3000 Then
  24. 			Syntax
  25. 			Wscript.Quit(1)
  26. 		End If
  27. 	Case Else
  28. 		Syntax
  29. 		Wscript.Quit(1)
  30. End Select
  31.  
  32. ' Calculate Easter Day using the instructions found at
  33. ' Simon Kershaw's "KEEPING THE FEAST"
  34. ' http://www.oremus.org/liturgy/etc/ktf/app/easter.html
  35. G   = ( ChkYear Mod 19 ) + 1
  36. S   = (( ChkYear - 1600 ) \ 100 ) - (( ChkYear - 1600 ) \ 400 )
  37. L   = ((( ChkYear - 1400 ) \ 100 ) * 8 ) \ 25
  38. PP  = ( 30003 - 11 * G + S - L ) Mod 30
  39. Select Case PP
  40. 	Case 28
  41. 		If G > 11 Then P = 27
  42. 	Case 29
  43. 		P = 28
  44. 	Case Else
  45. 		P = PP
  46. End Select
  47. D   = ( ChkYear + ( ChkYear \ 4 ) - ( ChkYear \ 100 ) + ( ChkYear \ 400 )) Mod 7
  48. DD  = ( 8 - D ) Mod 7
  49. PPP = ( 70003 + P ) Mod 7
  50. X   = (( 70004 - D - P ) Mod 7 ) + 1
  51. E   = P + X
  52. If E < 11 Then
  53. 	ED = E + 21
  54. 	EM = "March"
  55. Else
  56. 	ED = E - 10
  57. 	EM = "April"
  58. End If
  59. thisYear = Year(Date)
  60. If ChkYear < thisYear Then
  61. 	strIS = "was"
  62. ElseIf ChkYear = thisYear Then
  63. 	strIS = "is"
  64. Else
  65. 	strIS = "will be"
  66. End If
  67.  
  68. ' Display the result
  69. Wscript.Echo vbCrLf & "In " & ChkYear & " Easter Day " & strIS & " " & EM & " " & ED
  70.  
  71. ' Done
  72. Wscript.Quit(0)
  73.  
  74.  
  75.  
  76. Sub Syntax
  77. msg = vbCrLf & "Easter.vbs,  Version 1.01 for WSH 1.0" & vbCrLf & _
  78.       "Calculate the date of Easter Day for the specified year." & vbCrLf & _
  79.       vbCrLf & "Usage:  CSCRIPT  EASTER.VBS  [ year ]" & vbCrLf & vbCrLf & _
  80.       "Where:  year should be within the range of 1752 through 3000" & _
  81.       vbCrLf & vbCrLf & _
  82.       "Written by Rob van der Woude" & vbCrLf & _
  83.       "http://www.robvanderwoude.com" & vbCrLf & vbCrLf & _
  84.       "Based on the instructions found at" & vbCrLf & _
  85.       "Simon Kershaw's " & Chr(34) & "KEEPING THE FEAST" & Chr(34) & _
  86.       vbCrLf & "http://www.oremus.org/liturgy/etc/ktf/app/easter.html"
  87. Wscript.Echo(msg)
  88. End Sub
  89.  

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