Thursday, 2 September 2010

Get-UmAlQuraCalendar.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays details of a UmAlQura Calendar in PowerShell 
  4. .DESCRIPTION 
  5.     This script shows the various aspects of this calendar including key properties, 
  6.     fields and selected methods. 
  7. .NOTES 
  8.     File Name  : Get-UmAlQuraCalendar.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14.     MSDN Sample posted at: 
  15.         http://msdn.microsoft.com/en-us/library/system.globalization.umalquracalendar.aspx 
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\Get-UmAlQuraCalendar.ps1' 
  18.     Um Al Qura Calendar 
  19.     Algorithm Type          : LunarCalendar 
  20.     Eras in Calendar        : 1 
  21.     Is read only?           : False 
  22.     Max Supported Date/Time : 5/13/2029 11:59:59 PM 
  23.     Min Supported Date/Time : 4/30/1900 12:00:00 AM 
  24.     Two Digit Year Max      : 1451 
  25.   
  26.     April 3, 2002 of the Gregorian calendar equals the following in the UmAlQura calendar: 
  27.        Era:            1 
  28.        Year:           1423 
  29.        Is Leap Year?   False 
  30.        Days In Year:   354 
  31.        Month:          1 
  32.        Months in Year: 12 
  33.        Days in Month:  29 
  34.        Leap Month:     0 
  35.        DayOfYear:      20 
  36.        DayOfMonth:     20 
  37.        DayOfWeek:      Wednesday 
  38.   
  39.     After adding two years and ten months and one day: 
  40.        Era:            1 
  41.        Year:           1425 
  42.        Is Leap Year?   True 
  43.        Days In Year:   355 
  44.        Month:          11 
  45.        Months in Year: 12 
  46.        Days in Month:  30 
  47.        Leap Month:     0 
  48.        DayOfYear:      317 
  49.        DayOfMonth:     21 
  50.        DayOfWeek:      Sunday 
  51. #>     
  52.  
  53. # Helper Function 
  54. Function DisplayValues { 
  55. param ($MyCal, $MyDT
  56.  
  57. "   Era:            {0}" -f $MyCal.GetEra($MyDT)  
  58. "   Year:           {0}" -f $MyCal.GetYear($MyDT
  59. "   Is Leap Year?   {0}" -f $MyCal.IsLeapYear($MyCal.GetYear($MyDT)) 
  60. "   Days In Year:   {0}" -f $MyCal.GetDaysInYear($MyCal.GetYear($MyDT)) 
  61. "   Month:          {0}" -f $MyCal.GetMonth($MyDT
  62. "   Months in Year: {0}" -f $MyCal.GetMonthsInYear($MyCal.GetYear($MyDT)) 
  63. "   Days in Month:  {0}" -f $MyCal.GetDaysInMonth($MyCal.GetYear($MyDT), $MyDT.Month) 
  64. "   Leap Month:     {0}" -f $MyCal.GetLeapMonth($MyCal.GetYear($MyDT)) 
  65. "   DayOfYear:      {0}" -f $MyCal.GetDayOfYear($MyDT
  66. "   DayOfMonth:     {0}" -f $MyCal.GetDayOfMonth($MyDT
  67. "   DayOfWeek:      {0}" -f $MyCal.GetDayOfWeek($MyDT
  68. "" 
  69.        
  70. # Sets a DateTime to April 3, 2002 of the Gregorian calendar. 
  71.  $MyDT = New-Object System.DateTime 2002, 4, 3, (New-Object System.Globalization.GregorianCalendar) 
  72.    
  73. # Creates an instance of the UmAlQuraCalendar. 
  74. $MyCal = New-Object System.Globalization.UmAlQuraCalendar 
  75. # Display properties of the calendar 
  76. "Um Al Qura Calendar" 
  77. "Algorithm Type          : {0}" -f $MyCal.AlgorithmType 
  78. "Eras in Calendar        : {0}" -f $MyCal.Eras.count 
  79. "Is read only?           : {0}" -f $MyCal.IsReadOnly 
  80. "Max Supported Date/Time : {0}" -f $MyCal.MaxSupportedDateTime 
  81. "Min Supported Date/Time : {0}" -f $MyCal.MinSupportedDateTime 
  82. "Two Digit Year Max      : {0}" -f $MyCal.TwoDigitYearMax 
  83. "" 
  84.   
  85. # Display the values of the DateTime. 
  86.  "April 3, 2002 of the Gregorian calendar equals the following in the UmAlQura calendar:"  
  87. DisplayValues $MyCal $MyDT  
  88.  
  89. # Adds two years and ten months and one Day. 
  90. $MyDT = $MyCal.AddYears( $MyDT, 2 ) 
  91. $MyDT = $MyCal.AddMonths($MyDT, 10 ) 
  92. $MyDT = $MyCal.AddDays($MyDT, 1 ) 
  93.   
  94. # Display the values of the DateTime. 
  95. "After adding two years and ten months and one day:" 
  96. DisplayValues $MyCal $MyDT 

No comments: