Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify date/time format and make it cultureInfo independent #524

Merged
merged 2 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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