Skip to content

Commit

Permalink
Unify date/time format and make it cultureInfo independent (#524)
Browse files Browse the repository at this point in the history
* Unify date format and make it independent of specific cultureInfo

* moduleMessages.json should have correct datetime format dd/MM/yyyy HH:mm:ss
  • Loading branch information
mnieto committed May 14, 2023
1 parent bf8f488 commit a5e282b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Source/Private/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ function _showModuleLoadingMessages {

# dont show messages if display until date is in the past
$currentDate = Get-Date
$filteredMessages = $filteredMessages | Where-Object { $currentDate -le ([DateTime]::Parse($_.toDate))
$filteredMessages = $filteredMessages | Where-Object { $currentDate -le ([DateTime]::ParseExact($_.toDate, "dd/MM/yyyy HH:mm:ss", [cultureInfo]::InvariantCulture))
}

# stop processing if no messages left
Expand Down
8 changes: 4 additions & 4 deletions Tests/SampleFiles/moduleMessages.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[
{
"msg": "Message for minimum version 5.6.0",
"toDate": "2099-02-14 13:36:17Z",
"toDate": "14/02/2099 13:36:17",
"displayFromVersion": "5.6.0",
"type": "info"
},
{
"msg": "Message for minimum version 7.0.0",
"toDate": "2099-02-13 13:36:17Z",
"toDate": "13/02/2099 13:36:17",
"displayFromVersion": "7.0.0",
"type": "warning"
},
{
"msg": "Message for minimum version 6.9.0",
"toDate": "2021-12-31 23:59:59Z",
"toDate": "31/12/2021 23:59:59",
"displayFromVersion": "6.9.0",
"type": "warning"
},
{
"msg": "Message for minimum version 7.8.0 to maximum version 8.0.0",
"toDate": "2099-12-31 23:59:59Z",
"toDate": "31/12/2099 23:59:59",
"displayFromVersion": "7.8.0",
"displayToVersion": "8.0.0",
"type": "warning"
Expand Down
8 changes: 8 additions & 0 deletions Tests/function/tests/common.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,14 @@ Describe 'Common' {
{ _showModuleLoadingMessages -ModuleVersion 'notaversion' } | Should -Throw -ExpectedMessage '*Cannot convert value "notaversion" to type "System.Version*'
}

It 'should have correct datetime format' {
$moduleMessagesRes = Open-SampleFile 'moduleMessages.json'
$moduleMessagesRes | ForEach-Object {
$outDate = [datetime]::Now
[datetime]::TryParseExact($_.toDate, "dd/MM/yyyy HH:mm:ss", [cultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::None, [ref] $outDate) | Should -BeTrue
}
}

}

Context '_checkForModuleUpdates' {
Expand Down

0 comments on commit a5e282b

Please sign in to comment.