-
Notifications
You must be signed in to change notification settings - Fork 0
/
PsCalendar.psm1
86 lines (79 loc) · 2.75 KB
/
PsCalendar.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Function Get-Calendar
{
<#
.Synopsis
PowerShell calendar display
.EXAMPLE
Get-Calendar
.EXAMPLE
Get-Calendar -date 01/01/2000
#>
Param([Parameter(Position=0)][DateTime]$date=(Get-Date))
$dateTimeObject = new-object System.Globalization.DateTimeFormatInfo
$title = (Get-Date($date) -Format $dateTimeObject.YearMonthPattern)
Write-Host -NoNewline $title.PadLeft(((27 - $title.Length) / 2) + $title.Length)
$p = $dateTimeObject.ShortestDayNames
$col1 = @{expression=$dateTimeObject.AbbreviatedDayNames[0];alignment="right"}
$col2 = @{expression=$dateTimeObject.AbbreviatedDayNames[1];alignment="right"}
$col3 = @{expression=$dateTimeObject.AbbreviatedDayNames[2];alignment="right"}
$col4 = @{expression=$dateTimeObject.AbbreviatedDayNames[3];alignment="right"}
$col5 = @{expression=$dateTimeObject.AbbreviatedDayNames[4];alignment="right"}
$col6 = @{expression=$dateTimeObject.AbbreviatedDayNames[5];alignment="right"}
$col7 = @{expression=$dateTimeObject.AbbreviatedDayNames[6];alignment="right"}
Get-MonthObject -date $date |
Format-Table -Property $col1, $col2, $col3, $col4, $col5, $col6, $col7 -AutoSize
}
Function Get-MonthObject
{
Param([DateTime]$date)
$dateTimeObject = new-object System.Globalization.DateTimeFormatInfo
[DateTime]$first = Get-FirstDayOfMonth $date
[DateTime]$last = Get-LastDayOfMonth $date
[DateTime]$day=$first
do
{
$week = (0..6)
for ($inx=0; $inx -le 6; $inx++)
{
if ($day.DayOfWeek.value__ -eq $inx -and $day -le $last) {
$week[$inx] = if ($day.Date -eq (Get-Date).Date) {
$day.Day.ToString() + "*"
} else {
$day.Day.ToString().PadRight(3)
}
$day = $day.AddDays(1)
}
else
{
$week[$inx] = ""
}
}
Get-WeekObject($week)
}
While ($day -le $last)
}
Function Get-WeekObject
{
Param($week)
New-Object PSObject -Property @{
$dateTimeObject.AbbreviatedDayNames[0] = $week[0];
$dateTimeObject.AbbreviatedDayNames[1] = $week[1];
$dateTimeObject.AbbreviatedDayNames[2] = $week[2];
$dateTimeObject.AbbreviatedDayNames[3] = $week[3];
$dateTimeObject.AbbreviatedDayNames[4] = $week[4];
$dateTimeObject.AbbreviatedDayNames[5] = $week[5];
$dateTimeObject.AbbreviatedDayNames[6] = $week[6];
}
}
Function Get-FirstDayOfMonth
{
Param([DateTime]$date)
Get-Date $date -day 1 -hour 0 -minute 0 -Second 0
}
Function Get-LastDayOfMonth
{
Param([DateTime]$date)
$date = Get-FirstDayOfMonth($date).AddMonths(1)
$date.AddDays(-1)
}
New-Alias Cal Get-Calendar