diff --git a/PSCalendar.psd1 b/PSCalendar.psd1 index 234639e..4f738ef 100644 --- a/PSCalendar.psd1 +++ b/PSCalendar.psd1 @@ -6,7 +6,7 @@ RootModule = 'PSCalendar.psm1' # Version number of this module. - ModuleVersion = '2.3.0' + ModuleVersion = '2.3.1' # Supported PSEditions CompatiblePSEditions = @("Desktop", "Core") diff --git a/README.md b/README.md index da9f45f..ee4b698 100644 --- a/README.md +++ b/README.md @@ -262,4 +262,4 @@ For example, if you are running under the `en-AU` culture, you would need to use I have tried to make this module culture-aware. Testing across cultures is not an easy process. If you encounter a problem and are not running PowerShell under the `EN-US` culture, run the calendar command you are trying to use with `-Verbose` and post the results in a new issue. Or if you have both Windows PowerShell and PowerShell 7 installed, try the same command in both versions. -Last Updated 2021-07-30 16:30:17Z +Last Updated2021-11-01 18:36:52Z diff --git a/changelog.md b/changelog.md index 0e2fa4d..136684e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Change Log for PSCalendar +## v2.3.1 + ++ Fixed alignment problem when first day of a row is highlighted in `Get-NCalendar`. [Issue #25](https://github.com/jdhitsolutions/PSCalendar/issues/25). ++ Updated `Get-Calendar` to fix validation bug when the end date is less than the start date. [Issue #26](https://github.com/jdhitsolutions/PSCalendar/issues/26) + ## v2.3.0 + Added `Get-PNCalendar` and its alias `ncal`. [Issue #16](https://github.com/jdhitsolutions/PSCalendar/issues/16). diff --git a/functions/public.ps1 b/functions/public.ps1 index d67db92..b8d0ad9 100644 --- a/functions/public.ps1 +++ b/functions/public.ps1 @@ -10,7 +10,7 @@ Function Get-Calendar { Param( [Parameter(Position = 1, ParameterSetName = "month")] [ValidateNotNullorEmpty()] - [ValidateScript( { + [ValidateScript({ $names = _getMonthsByCulture if ($names -contains $_) { $True @@ -32,15 +32,6 @@ Function Get-Calendar { [Parameter(Mandatory, HelpMessage = "Enter an ending date for the month like 3/1/2020 that is correct for your culture.", ParameterSetName = "span")] [ValidateNotNullOrEmpty()] - [ValidateScript( { - if ($_ -ge $Start) { - $True - } - else { - Throw "The end date ($_) must be later than the start date ($start)" - $False - } - })] [string]$End, [Parameter(HelpMessage = "Specify a collection of dates to highlight in the calendar display.")] @@ -64,6 +55,14 @@ Function Get-Calendar { } Process { Write-Verbose "Using parameter set: $($pscmdlet.ParameterSetName)" + + #validate $End Issue #26 + if ($PSCmdlet.ParameterSetName -eq 'span') { + if ([datetime]$end -le [datetime]$Start) { + Write-Verbose "Validating End ($end) compared to Start ($Start)" + Throw "[Validation Error] The end date ($end) must be later than the start date ($start)" + } + } Write-Verbose "Using culture: $($currculture.displayname) [$($currCulture.name)]" Write-Verbose "Using PSBoundParameters:" Write-Verbose ($PSBoundParameters | Out-String).trim() @@ -624,7 +623,9 @@ Function Get-NCalendar { $daylist.AddRange($daynames) } - $daylist | ForEach-Object -Begin { $dayHash = [ordered]@{} } -Process { + $daylist | ForEach-Object -Begin { + $dayHash = [ordered]@{} + } -Process { $dayHash.Add($_, @()) } @@ -634,6 +635,7 @@ Function Get-NCalendar { $dayname = "{0:ddd}" -f $day if ((-NOT $HideHighlight) -AND ($day -eq $today)) { $dom = "$([char]27)[7m$($day.day)$([char]27)[0m" + $dayLength = $day.day.ToString() } else { $dom = $day.day @@ -651,15 +653,18 @@ Function Get-NCalendar { $str = $_.tostring() if ($str -match [char]27) { #add extra padding to account for ANSI escape sequence - $ansipad = 8 + Write-Verbose "Adjusting for ANSI sequence" + $ansipad = $str.length - $daylength #8 + Write-Verbose "Padding $ansipad" + $str = " $str" } else { $ansipad = 0 } - $str.padleft(2) + $str.padleft(2+$ansipad) }) -join " ").padleft($maxDayLength + 12 + $ansipad) } - #Write-verbose "display length = $($out[0].length)" + Write-verbose "display length = $($out[0].length)" #write-Verbose "head length = $($head.length)" $pad = (($out[0].length - $head.length) / 2) + $head.length + 1 #Write-Verbose "padding $pad"