Powered by GeSHi

Source code for leapyear.ps1

(view source code of leapyear.ps1 as plain text)

  1. #
  2. # LeapYear.ps1,  Version 1.00
  3. #
  4. # Usage:  .\LEAPYEAR.PS1  [ year ]
  5. #
  6. # Where:  "year"  is the year which you want to test
  7. #                 (default is current year)
  8. #
  9. # Written by Rob van der Woude
  10. # http://www.robvanderwoude.com
  11. #
  12.  
  13. # Get the specified year
  14. param( [int]$year = ( Get-Date ).Year )
  15.  
  16. # Get the current year
  17. [int]$thisyear = ( Get-Date ).Year
  18.  
  19. # Format the output text (past, present or future?)
  20. $is1 = "is"
  21. $is2 = ""
  22. If ( $year -lt $thisyear ) {
  23. 	$is1 = "was"
  24. }
  25. If ( $year -gt $thisyear ) {
  26. 	$is1 = "will"
  27. 	$is2 = " be"
  28. }
  29.  
  30. # Check if the specified year is a leap year
  31. [boolean]$leapyear = ( [boolean]!( $year % 4 ) -and [boolean]( $year % 100 ) ) -or [boolean]!( $year % 400 )
  32.  
  33. # Display the result
  34. If ( $leapyear ) {
  35. 	Write-Host "$year $is1$is2 a leap year"
  36. }
  37. Else {
  38. 	Write-Host "$year $is1 NOT$is2 a leap year"
  39. }
  40.