functions/Show-PersianCal.ps1
function Get-Holidays { [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [ValidateRange(1300,1500)] [int] $Year, [ValidateNotNullOrEmpty()] [ValidateRange(1,12)] [int] $Month ) if (Test-Path ($PSScriptRoot + "\" + "holidays.txt")) { $arrHolidays = New-Object System.Collections.ArrayList $rawHolidays = Get-Content ($PSScriptRoot + "\" + "holidays.txt") foreach ($item in $rawHolidays) { $splitArr = $item.Split("/") if (([int]$splitArr[0] -eq $Year) -and ([int]$splitArr[1] -eq $Month)) { $arrHolidays.Add($splitArr[2]) | Out-Null } } Return $arrHolidays } } function Show-PersianCal { [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [ValidateRange(1300,1500)] [int] $Year, [ValidateNotNullOrEmpty()] [ValidateSet("Farvardin","Ordibehesht","Khordad","Tir","Mordad","Shahrivar","Mehr","Aban","Azar","Dey","Bahman","Esfand")] [string] $Month ) $arrMonth = @("Farvardin","Ordibehesht","Khordad","Tir","Mordad","Shahrivar","Mehr","Aban","Azar","Dey","Bahman","Esfand") $objPcal = New-Object System.Globalization.PersianCalendar $objPerToday = Get-PersianDate if ($Year -and (-not $Month)) { $cursorPos = $Host.UI.RawUI.CursorPosition $initialX = $cursorPos.X $cursorPos.X += 30 $Host.UI.RawUI.CursorPosition = $cursorPos Write-Host $Year $cursorPos.X = $initialX $cursorPos.Y++ for ($i =1; $i -le 12; $i++) { switch ($i) { 2 { $cursorPos.X += 22} 3 { $cursorPos.x += 22} 4 { $cursorPos.X = $initialX ; $cursorPos.Y += 9} 5 { $cursorPos.X += 22} 6 { $cursorPos.X += 22} 7 { $cursorPos.X = $initialX ; $cursorPos.Y += 9} 8 { $cursorPos.X += 22} 9 { $cursorPos.X += 22} 10{ $cursorPos.X = $initialX ; $cursorPos.Y += 9} 11 { $cursorPos.X += 22} 12 { $cursorPos.X += 22} } $initDate = $objPcal.ToDateTime($Year,$i,1,0,0,0,0,0) $objPdate = Get-PersianDate -Date $initDate $FirstDayOfMonth = (Get-PersianDate -ToGregorian -Year $objPdate.Year -Month $objPdate.Month -Day 1).DayOfWeek.value__ $holidays = Get-Holidays -Year $Year -Month $i if (($objpdate.Year -eq $objPerToday.Year) -and (($objpdate.Month -eq $objPerToday.Month)) ) { Draw-Month -Title Month -Year $objPdate.Year -Month $objPdate.Month -FirstDayOfMonth $FirstDayOfMonth ` -DaysInMonth $objPdate.DaysInMonth ` -today $objPerToday.Day -holidays $holidays -cursorPos $cursorPos }else { Draw-Month -Title Month -Year $objPdate.Year ` -Month $objPdate.Month -FirstDayOfMonth $FirstDayOfMonth -DaysInMonth $objPdate.DaysInMonth -holidays $holidays -cursorPos $cursorPos } } }elseif ($Year -and $month) { $monthNum = $arrMonth.IndexOf($month) + 1 $initDate = $objPcal.ToDateTime($Year,$monthNum,1,0,0,0,0,0) $objPdate = Get-PersianDate -Date $initDate $FirstDayOfMonth = (Get-PersianDate -ToGregorian -Year $objPdate.Year -Month $objPdate.Month -Day 1).DayOfWeek.value__ $holidays = Get-Holidays -Year $Year -Month $monthNum if (($objpdate.Year -eq $objPerToday.Year) -and (($objpdate.Month -eq $objPerToday.Month)) ) { Draw-Month -Title Month -Year $objPdate.Year -Month $objPdate.Month -FirstDayOfMonth $FirstDayOfMonth ` -DaysInMonth $objPdate.DaysInMonth -today $objPerToday.Day -holidays $holidays }else { Draw-Month -Title Month -Year $objPdate.Year ` -Month $objPdate.Month -FirstDayOfMonth $FirstDayOfMonth -DaysInMonth $objPdate.DaysInMonth -holidays $holidays } } elseif ($Month) { $monthNum = $arrMonth.IndexOf([string]$Month) + 1 $initDate = $objPcal.ToDateTime($objPerToday.Year,$monthNum,1,0,0,0,0,0) $objPdate = Get-PersianDate -Date $initDate $FirstDayOfMonth = (Get-PersianDate -ToGregorian -Year $objPdate.Year -Month $objPdate.Month -Day 1).DayOfWeek.value__ $holidays = Get-Holidays -Year $objPdate.Year -Month $monthNum if ((($objpdate.Month -eq $objPerToday.Month))) { Draw-Month -Title MonthAndYear -Year $objPdate.Year -Month $objPdate.Month -FirstDayOfMonth $FirstDayOfMonth -DaysInMonth $objPdate.DaysInMonth` -today $objPdate.Day -holidays $holidays } else { Draw-Month -Title MonthAndYear -Year $objPdate.Year -Month $objPdate.Month -FirstDayOfMonth $FirstDayOfMonth -DaysInMonth $objPdate.DaysInMonth` -holidays $holidays } } else { $objPdate = Get-PersianDate $FirstDayOfMonth = (Get-PersianDate -ToGregorian -Year $objPdate.Year -Month $objPdate.Month -Day 1).DayOfWeek.value__ $holidays = Get-Holidays -Year $objPdate.Year -Month ($arrMonth.IndexOf([string]$objPdate.Month) + 1) Draw-Month -Title MonthAndYear -Year $objPdate.Year -Month $objPdate.Month -FirstDayOfMonth $FirstDayOfMonth -DaysInMonth $objPdate.DaysInMonth` -today $objPdate.Day -holidays $holidays } } |