forked from stcu/SharedScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test-USFederalHoliday.ps1
140 lines (124 loc) · 3.56 KB
/
Test-USFederalHoliday.ps1
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<#
.SYNOPSIS
Returns true if the given date is a U.S. federal holiday.
.DESCRIPTION
The following holidays are checked:
* New Year's Day, January 1 (± 1 day, if observed)
* Birthday of Martin Luther King, Jr., Third Monday in January
* Washington's Birthday, Third Monday in February
* Memorial Day, Last Monday in May
* Juneteenth, June 19 (± 1 day, if observed)
* Independence Day, July 4 (± 1 day, if observed)
* Labor Day, First Monday in September
* Columbus Day, Second Monday in October
* Veterans Day, November 11 (±1 day, if observed)
* Thanksgiving Day, Fourth Thursday in November
* Christmas Day, December 25 (±1 day, if observed)
.NOTES
Thanks to the Uniform Monday Holiday Act, Washington's "Birthday" always falls
*between* Washington's birthdays. He had two, and we still decided to celebrate
a third day.
https://en.wikipedia.org/wiki/Uniform_Monday_Holiday_Act
https://en.wikipedia.org/wiki/Washington%27s_Birthday#History
.INPUTS
System.DateTime values to check.
.OUTPUTS
System.Boolean indicating whether the date is a holiday.
.FUNCTIONALITY
Date and time
.LINK
http://www.federalreserve.gov/aboutthefed/k8.htm
.EXAMPLE
Test-USFederalHoliday.ps1 2016-11-11
Veterans Day
.EXAMPLE
Test-USFederalHoliday.ps1 2017-02-20
Washington's Birthday
.EXAMPLE
if(Test-USFederalHoliday.ps1 (Get-Date)) { return }
Returns from a function or script if today is a holiday.
#>
[CmdletBinding()][OutputType([bool])] Param(
# The date to check.
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][datetime] $Date,
# Return the holiday name as a truthy value, rather than true.
[Parameter(HelpMessage='Return the holiday name?')][Alias('ReturnName','ReturnHolidayName')][switch] $AsHolidayName,
# Indicates Saturday holidays are observed on Fridays.
[Parameter(HelpMessage='Are Saturday holidays observed on Friday?')][switch] $SatToFri,
# Indicates Sunday holidays are observed on Mondays.
[Parameter(HelpMessage='Are Sunday holidays observed on Monday?')][switch] $SunToMon
)
Process
{
$showdate = Get-Date $Date -f D
$MMdd= '{0:MMdd}' -f $Date
$holiday =
switch($MMdd)
{
'0101' {"New Year's Day"}
'0619' {"Juneteenth"}
'0704' {"Independence Day"}
'1111' {"Veteran's Day"}
'1225' {"Christmas Day"}
default
{
switch($Date.DayOfWeek)
{
Monday
{
switch -regex ($MMdd)
{
'^01(?:1[5-9]|2[01])$' {"Birthday of Martin Luther King, Jr."}
'^02(?:1[5-9]|2[01])$' {"Washington's Birthday"}
'^05(?:2[5-9]|3[01])$' {"Memorial Day"}
'^090[1-7]$' {"Labor Day"}
'^10(?:0[89]|1[01-4])$' {"Columbus Day"}
}
if($SunToMon)
{
switch($MMdd)
{
'0102' {"New Year's Day (Observed)"}
'0620' {"Juneteenth (Observed)"}
'0705' {"Independence Day (Observed)"}
'1112' {"Veterans Day (Observed)"}
'1226' {"Christmas Day (Observed)"}
}
}
}
Thursday
{
if($MMdd -match '^112[2-8]$') {"Thanksgiving Day"}
}
Friday
{
if($SatToFri)
{
switch($MMdd)
{
'1231' {"New Year's Day (Observed)"}
'0618' {"Juneteenth (Observed)"}
'0703' {"Independence Day (Observed)"}
'1110' {"Veteran's Day (Observed)"}
'1224' {"Christmas Day (Observed)"}
}
}
}
}
}
}
if($holiday)
{
if($ReturnName) {return $holiday}
else
{
Write-Verbose "$showdate is $holiday"
return $true
}
}
else
{
Write-Verbose "$showdate is not a US federal holiday"
return $false
}
}