mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-24 19:08:27 +02:00
Update list-calendar.ps1
This commit is contained in:
parent
3cdf8fff36
commit
f8b3301c02
@ -33,16 +33,17 @@ function Print-Month ($month, $year) {
|
|||||||
|
|
||||||
$header = (Get-Date $firstDayOfMonth -Format MMMM) + " " + $firstDayOfMonth.Year
|
$header = (Get-Date $firstDayOfMonth -Format MMMM) + " " + $firstDayOfMonth.Year
|
||||||
Write-Host
|
Write-Host
|
||||||
Write-Host ((" " * (($daysLine.Length - $header.Length) / 2)) + $header)
|
Write-Host $header.ToUpper()
|
||||||
|
Write-Host "__________________________"
|
||||||
Write-Host $daysLine
|
Write-Host $daysLine
|
||||||
|
|
||||||
for ($day = $firstDayOfMonth; $day -le $lastDayOfMonth; $day = $day.AddDays(1)) {
|
for ($day = $firstDayOfMonth; $day -le $lastDayOfMonth; $day = $day.AddDays(1)) {
|
||||||
if ($day.day -eq 1) {
|
if ($day.day -eq 1) {
|
||||||
Write-Host (" " * 3 * [int](Get-Date $day -uformat %u)) -NoNewLine
|
Write-Host (" " * 4 * [int](Get-Date $day -uformat %u)) -NoNewLine
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host ((Get-Date $day -Format dd).ToString()) -NoNewLine
|
Write-Host ((Get-Date $day -Format dd).ToString()) -NoNewLine
|
||||||
Write-Host " " -NoNewLine
|
Write-Host " " -NoNewLine
|
||||||
|
|
||||||
if ($day.DayOfWeek -eq "Saturday") {
|
if ($day.DayOfWeek -eq "Saturday") {
|
||||||
Write-Host
|
Write-Host
|
||||||
@ -65,7 +66,7 @@ function Print-Year($year) {
|
|||||||
|
|
||||||
for ($i = $month; $i -lt $month + 3; $i++) {
|
for ($i = $month; $i -lt $month + 3; $i++) {
|
||||||
$tempHeader = (Get-Date -month $i -Format MMMM) + " " + $year.ToString()
|
$tempHeader = (Get-Date -month $i -Format MMMM) + " " + $year.ToString()
|
||||||
$header += ((" " * (($daysLine.Length - $tempHeader.Length) / 2)) + $tempHeader + (" " * (($daysLine.Length - $tempHeader.Length) / 2)))
|
$header += ((" " * (($daysLine.Length - $tempHeader.Length) / 2)) + $tempHeader.toUpper() + (" " * (($daysLine.Length - $tempHeader.Length) / 2)))
|
||||||
$header += " "
|
$header += " "
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,14 +85,14 @@ function Print-Year($year) {
|
|||||||
$dayOffset = [int](Get-Date -day 1 -month ($month + $i) -year $year -uformat %u)
|
$dayOffset = [int](Get-Date -day 1 -month ($month + $i) -year $year -uformat %u)
|
||||||
|
|
||||||
if ($dayOfMonth -eq 1) {
|
if ($dayOfMonth -eq 1) {
|
||||||
Write-Host (" " * 3 * $dayOffSet) -NoNewLine
|
Write-Host (" " * 4 * $dayOffSet) -NoNewLine
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dayOfMonth -le (Get-Date -day 1 -month ((($i + $month) % 12) + 1) -year $year).AddDays(-1).day) {
|
if ($dayOfMonth -le (Get-Date -day 1 -month ((($i + $month) % 12) + 1) -year $year).AddDays(-1).day) {
|
||||||
$currentDay = (Get-Date -day $dayOfMonth -month ((($i + $month - 1) % 12) + 1) -year $year)
|
$currentDay = (Get-Date -day $dayOfMonth -month ((($i + $month - 1) % 12) + 1) -year $year)
|
||||||
|
|
||||||
Write-Host ((Get-Date -month ($i + $month) -day $dayOfMonth -year $year -Format dd).ToString()) -NoNewLine
|
Write-Host ((Get-Date -month ($i + $month) -day $dayOfMonth -year $year -Format dd).ToString()) -NoNewLine
|
||||||
Write-Host " " -NoNewLine
|
Write-Host " " -NoNewLine
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host " " -NoNewLine
|
Write-Host " " -NoNewLine
|
||||||
@ -145,21 +146,21 @@ function Find-LastWeekDay ($year, $month, $dayOfWeek) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Set-Variable -name daysLine -option Constant -value "Su Mo Tu We Th Fr Sa "
|
Set-Variable -name daysLine -option Constant -value "Su Mo Tu We Th Fr Sa "
|
||||||
|
|
||||||
if ($year -lt 0) { throw "Year parameter must be greater than 0" }
|
if ($year -lt 0) { throw "Year parameter must be greater than 0" }
|
||||||
if ($month -lt 0) { throw "Month parameter must be between 1 and 12" }
|
if ($month -lt 0) { throw "Month parameter must be between 1 and 12" }
|
||||||
|
|
||||||
if (($month -gt 12) -and ($year -eq (Get-Date).Year)) {
|
if (($month -gt 12) -and ($year -eq (Get-Date).Year)) {
|
||||||
$year = $month
|
$year = $month
|
||||||
$month = 0
|
$month = 0
|
||||||
} elseif (($month -gt 12) -and ($year -ne (Get-Date).Year)) {
|
} elseif (($month -gt 12) -and ($year -ne (Get-Date).Year)) {
|
||||||
throw "Month parameter must be between 1 and 12"
|
throw "Month parameter must be between 1 and 12"
|
||||||
}
|
}
|
||||||
if ($month -ne 0) {
|
if ($month -ne 0) {
|
||||||
Print-Month $month $year
|
Print-Month $month $year
|
||||||
} else {
|
} else {
|
||||||
Print-Year $year
|
Print-Year $year
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user