Skip to content

Commit

Permalink
see changlelog for v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Oct 23, 2018
1 parent bcb7959 commit 0c0070c
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 26 deletions.
2 changes: 1 addition & 1 deletion PSCalendar.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
RootModule = 'PSCalendar.psm1'

# Version number of this module.
ModuleVersion = '1.3.1'
ModuleVersion = '1.4.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
57 changes: 38 additions & 19 deletions calendar-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Function Get-Calendar {
[ValidateNotNullorEmpty()]
[ValidateScript( {
$names = Get-MonthsByCulture
# ((Get-Culture).DateTimeFormat.MonthNames).Where( {$_ -match "\w+"})
if ($names -contains $_) {
$True
}
Expand Down Expand Up @@ -44,6 +43,7 @@ Function Get-Calendar {
})]
[DateTime]$End,

[ValidateNotNullorEmpty()]
[string[]]$HighlightDate = (Get-Date).date.toString()
)

Expand All @@ -63,6 +63,7 @@ Function Get-Calendar {
$start = New-Object DateTime $start.Year, $start.Month, 1
$end = New-Object DateTime $end.Year, $end.Month, 1
}

Write-Verbose "Starting at $start"
Write-Verbose "Ending at $End"
#Convert the highlight dates into real dates
Expand Down Expand Up @@ -105,15 +106,18 @@ Function Get-Calendar {
#Pad the day number for display, highlighting if necessary
$displayDay = " {0,2} " -f $currentDay.Day

#See if we should highlight a specific date
if ($highlightDates) {
$compareDate = New-Object DateTime $currentDay.Year,
$currentDay.Month, $currentDay.Day
if ($highlightDates -contains $compareDate) {
$displayDay = "*" + ("{0,2}" -f $currentDay.Day) + "*"
}
#highlight a specific date
if ($highlightDates -ne (Get-Date).date.toString() ) {
$highlightDates+= (Get-Date).date.toString()
}

$compareDate = New-Object DateTime $currentDay.Year,
$currentDay.Month, $currentDay.Day
if ($highlightDates -contains $compareDate) {
$displayDay = "*" + ("{0,2}" -f $currentDay.Day) + "*"
}


#Add in the day of week and day number as note properties.
$currentWeek | Add-Member NoteProperty $dayName $displayDay

Expand Down Expand Up @@ -165,7 +169,6 @@ Function Show-Calendar {
[ValidateNotNullorEmpty()]
[ValidateScript( {
$names = Get-MonthsByCulture
#((Get-Culture).DateTimeFormat.MonthNames).Where( {$_ -match "\w+"})
if ($names -contains $_) {
$True
}
Expand All @@ -182,8 +185,17 @@ Function Show-Calendar {

[string[]]$HighlightDate = (Get-Date).date.toString(),

[Parameter(HelpMessage = "Specify a color for the highlighted days.")]
[ValidateNotNullOrEmpty()]
[consolecolor]$HighlightColor = "Green",

[Parameter(HelpMessage = "Specify a color for the days of the month heading.")]
[ValidateNotNullOrEmpty()]
[consolecolor]$HighlightColor = "Green"
[consolecolor]$TitleColor = "Yellow",

[Parameter(HelpMessage = "Specify a color for the days of the week heading.")]
[ValidateNotNullOrEmpty()]
[consolecolor]$DayColor = "Cyan"
)

Write-Verbose "Starting $($myinvocation.mycommand)"
Expand All @@ -196,10 +208,13 @@ Function Show-Calendar {
}
}

#remove color parameter if specified
if ($PSBoundParameters.Containskey("HighlightColor")) {
$PSBoundParameters.Remove("HighlightColor")
}
#remove color parameters if specified
"HighlightColor","TitleColor","DayColor" | foreach-object {
if ($PSBoundParameters.Containskey($_)) {
$PSBoundParameters.Remove($_) | Out-Null
}
} #foreach color parameter

$cal = Get-Calendar @PSBoundParameters

#turn the calendar into an array of strings
Expand All @@ -212,11 +227,11 @@ Function Show-Calendar {
foreach ($line in $calarray) {
if ($line -match "\d{4}") {
#write the line with the month and year
write-Host $line -ForegroundColor Yellow
write-Host $line -ForegroundColor $TitleColor
}
elseif ($line -match "\w{3}|-{3}") {
#write the day names and underlines
Write-Host $line -ForegroundColor cyan
Write-Host $line -ForegroundColor $DayColor
}
elseif ($line -match "\*") {
#break apart lines with asterisks
Expand Down Expand Up @@ -364,6 +379,11 @@ Function Show-GuiCalendar {
#color is set for development purposes. It won't be seen normally.
$form.Background.Color = "green"
$form.background.Opacity = 0
$form.ShowInTaskbar = $False
$form.Add_Loaded({
$form.Topmost = $True
$form.Activate()
})

$form.Add_MouseLeftButtonDown( {$form.DragMove()})

Expand Down Expand Up @@ -401,7 +421,7 @@ Function Show-GuiCalendar {
$myCals = @()
foreach ($month in $months) {
$cal = New-Object System.Windows.Controls.Calendar
$cal.DisplayMode = "Calendar"
$cal.DisplayMode = "Month"

$cal.Opacity = 1
$cal.FontFamily = $font
Expand All @@ -419,7 +439,6 @@ Function Show-GuiCalendar {
foreach ($d in $HighlightDate) {
if ($d.month -eq $month.Month) {
$cal.SelectedDates.add($d)

}
}
}
Expand Down Expand Up @@ -461,11 +480,11 @@ Function Show-GuiCalendar {
$psCmd.Runspace = $newRunspace
Write-Verbose "Invoking calendar runspace"
$psCmd.BeginInvoke() | Out-Null

Write-Verbose "Ending $($myinvocation.mycommand)"

} #close Show-GuiCalendar


#a helper function to retrieve names
function Get-MonthsbyCulture {
[cmdletbinding()]
Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log for PSCalendar

## v1.4.0

+ Added parameters to `Show-Calendar` to let user specify colors. (Issue #4)
+ Fixed highlight display bug in `Get-Calendar` (Issue #8)
+ Fixed DisplayMode bug in `Show-GuiCalendar`
+ Modified `Show-GuiCalendar` to not display in the taskbar
+ Added Pester tests to the module
+ Updated documentation

## v1.3.1

+ Help documentation updates for clarity (Issue #5)
Expand Down
190 changes: 184 additions & 6 deletions test/PSCalendar.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,188 @@
$ModuleManifestName = 'PSCalendar.psd1'
#these tests are acceptance tests and validate that the module has the
#settings I intend and that the commands work as expected.

$moduleName = (Get-Item -path $PSScriptRoot).Parent.Name
$ModuleManifestName = "$modulename.psd1"
$ModuleManifestPath = "$PSScriptRoot\..\$ModuleManifestName"

Describe 'PSCalendar Manifest Tests' {
It 'Passes Test-ModuleManifest' {
Test-ModuleManifest -Path $ModuleManifestPath | Should Not BeNullOrEmpty
$? | Should Be $true
import-module $ModuleManifestPath -Force

Describe $ModuleName {
$myModule = Test-ModuleManifest -Path $ModuleManifestPath
Context Manifest {
It 'Passes Test-ModuleManifest' {
$myModule | Should Not BeNullOrEmpty
}
It "Should have a root module" {
$myModule.RootModule | Should Not BeNullOrEmpty
}
It "Contains exported commands" {
$myModule.ExportedCommands | Should Not BeNullOrEmpty
}
It "Should have a module description" {
$myModule.Description | Should Not BeNullOrEmpty
}
It "Should have a company" {
$myModule.Description | Should Not BeNullOrEmpty
}
It "Should have an author of 'Jeff Hicks'" {
$mymodule.Author | Should Be 'Jeff Hicks'
}
It "Should have tags" {
$mymodule.Tags | Should Not BeNullOrEmpty
}
It "Should have a license URI" {
$mymodule.LicenseUri | should Not BeNullOrEmpty
}
It "Should have a project URI" {
$mymodule.ProjectUri | Should Not BeNullOrEmpty
}
}
}
Context Exports {
$exported = Get-Command -Module $ModuleName -CommandType Function
It "Should have an exported command of Get-Calendar" {
$exported.name | Should Contain "Get-Calendar"
}
It "Should have an exported command of Show-Calendar" {
$exported.name | Should Contain "Show-Calendar"
}
It "Should have an exported command of Show-GuiCalendar" {
$exported.name | Should Contain "Show-GuiCalendar"
}
It "Should have an alias of cal" {
(Get-Alias -Name cal).ResolvedCommandName | Should be "Get-Calendar"
}
It "Should have an alias of scal" {
(Get-Alias -Name scal).ResolvedCommandName | Should be "Show-Calendar"
}
It "Should have an alias of cal" {
(Get-Alias -Name gcal).ResolvedCommandName | Should be "Show-GuiCalendar"
}
}
Context Structure {
It "Should have a Docs folder" {
Get-Item $PSScriptRoot\..\docs | Should Be $True
}
foreach ($cmd in $myModule.ExportedFunctions.keys) {
It "Should have a markdown help file for $cmd" {
Get-Item $PSScriptRoot\..\docs\$cmd.md | Should be $True
}
}
It "Should have an external help file" {
get-item $PSScriptRoot\..\en-us\*.xml | Should Be $True
}

It "Should have a license file" {
Get-Item $PSScriptRoot\..\license.* | Should be $True
}

It "Should have a changelog file" {
Get-Item $PSScriptRoot\..\changelog* | Should be $True
}

It "Should have a README.md file" {
Get-Item $PSScriptRoot\..\README.md | Should be $True
}
}
} -Tag module

InModuleScope $moduleName {
Describe Get-Calendar {

It "Should run without error with defaults" {
{Get-Calendar} | Should Not Throw
}
It "Should throw an exception with a bad month" {
{Get-Calendar -month foo} | Should Throw
}
It "Should write a STRING to the pipeline" {
$c = Get-Calendar
$c | Should beOfType String
}
It "Should display the month and year" {
#use the current month
$c = Get-Calendar -month January -year 2020
$c -match "January 2020" | Should be $True
}
It "Should fail with a year unless using 4 digits" {
{get-Calendar -year 2020 } | Should Not Throw
{Get-Calendar -year 20} | Should Throw
{Get-Calendar -year 20200} | Should Throw
}
It "Should let you higlight a date" {
$c = Get-Calendar -month January -Year 2020 -HighlightDate 1/15/2020
$c -match "\*15\*" | Should Be $True
}
It "Should let you specify a start month and end month" {
$c = Get-Calendar -Start "1/1/2020" -end "2/1/2020"
$c.length | Should be 2
$c -match "January 2020" | Should be $true
$c -match "February 2020" | Should be $true
}
} -tag command

Describe "Show-Calendar" {
$moduleName = (Get-Item -path $PSScriptRoot).Parent.Name
$ModuleManifestName = "$modulename.psd1"
$ModuleManifestPath = "$PSScriptRoot\..\$ModuleManifestName"
#use a runspace to avoid displaying the Write-Host output
$ps = [powershell]::Create()
$ps.AddScript({
param([string]$Name)

Import-Module -Name $Name
Show-Calendar

},$True) | out-null

$ps.AddParameter("Name",$ModuleManifestPath) | Out-Null

$r = $ps.Invoke()

It "Should run without error with defaults" {
$ps.streams.error | Should BeNullOrEmpty
$ps.streams.information | Should Not BeNullOrEmpty
$ps.streams.information -match $((Get-Date).Year) | Should Not BeNullOrEmpty
}
It "Should not write anything to the pipeline" {
$r | Should BeNullOrEmpty
}
$ps.Dispose()

#test with a new set of values
$ps = [powershell]::Create()
$ps.AddScript({
param([string]$Name)

Import-Module -Name $Name
Show-Calendar

},$True) | out-null

$h = @{
Name = $mod
Month = "foo"
}
$ps.AddParameters($h)
$r = $ps.Invoke()
It "Should fail with a bad month name" {
$ps.streams.error | Should Not BeNullOrEmpty
}
$ps.dispose()
} -tag command
Describe Show-GuiCalendar {
It "Should run without error." {
{Show-GuiCalendar} | Should Not Throw
}
It "Should let you customize the layout" {
Show-GuiCalendar -end (Get-Date).AddMonths(2) -font "Century Gothic" -FontStyle Italic -FontWeight demibold
}
It "Should fail with a bad month" {
{Show-GuiCalendar -start "13/1/2020" } | Should Throw
}
It "Should display a warning when specifying more than 3 months" {
Show-GuiCalendar -start 1/1/2020 -end 6/1/2020 -WarningAction SilentlyContinue -WarningVariable w
$w | Should Not BeNullOrEmpty
}
} -tag command
}

0 comments on commit 0c0070c

Please sign in to comment.