Skip to content
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
12 changes: 8 additions & 4 deletions Evergreen/Private/ConvertTo-DateTime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ function ConvertTo-DateTime {
back to the specified pattern using invariant culture if automatic parsing fails.
Ambiguous dates are interpreted as month/day/year when automatically detected.
Use -AutoDetect:$false to parse only with the specified pattern.
The returned DateTime object is formatted according to the culture of its consumer.
Returns the parsed date as an invariant yyyy-MM-dd string.
.EXAMPLE
ConvertTo-DateTime -DateTime "December 31, 2024 11:45 PM"
.EXAMPLE
ConvertTo-DateTime -DateTime "31/12/2024 23:45" -Pattern "dd/MM/yyyy HH:mm"
#>
[OutputType([System.DateTime])]
[OutputType([System.String])]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNullOrEmpty()]
[Alias("Date")]
[System.String] $DateTime,

[Parameter(Position = 1)]
Expand All @@ -40,6 +41,7 @@ function ConvertTo-DateTime {
"MM/dd/yyyy HH:mm:ss"
"M/d/yyyy h:mm tt"
"M/d/yyyy h:mm:ss tt"
"M/d/yyyy hh:mm:ss tt"
"MM-dd-yyyy"
"yyyy-MM-dd"
"yyyy-MM-dd HH:mm:ss"
Expand All @@ -50,6 +52,7 @@ function ConvertTo-DateTime {
"d/M/yyyy"
"dd/MM/yyyy hh:mm tt"
"dd/MM/yyyy hh:mm:ss tt"
"dd/MM/yyyy HH:mm"
"dd/MM/yyyy HH:mm:ss"
)
$Output = [System.DateTime]::MinValue
Expand Down Expand Up @@ -82,6 +85,7 @@ function ConvertTo-DateTime {
}
}

Write-Verbose -Message "$($MyInvocation.MyCommand): Returning DateTime: [$Output]."
Write-Output -InputObject $Output
$FormattedDate = $Output.ToString("yyyy-MM-dd", [System.Globalization.CultureInfo]::InvariantCulture)
Write-Verbose -Message "$($MyInvocation.MyCommand): Returning date: [$FormattedDate]."
Write-Output -InputObject $FormattedDate
}
2 changes: 1 addition & 1 deletion Evergreen/Shared/Get-CodebergRepoRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function Get-CodebergRepoRelease {
if ((Get-Platform -String $asset.browser_download_url) -eq "Windows") {
$PSObject = [PSCustomObject] @{
Version = $Version
Date = ConvertTo-DateTime -DateTime $item.created_at -Pattern "MM/dd/yyyy HH:mm:ss"
Date = ConvertTo-DateTime -DateTime $item.created_at
Size = $asset.size
Architecture = Get-Architecture -String $(Split-Path -Path $asset.browser_download_url -Leaf)
InstallerType = Get-InstallerType -String $(Split-Path -Path $asset.browser_download_url -Leaf)
Expand Down
2 changes: 1 addition & 1 deletion Evergreen/Shared/Get-GitLabRepoRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function Get-GitLabRepoRelease {

[PSCustomObject] @{
Version = $Version
Date = ConvertTo-DateTime -DateTime $dateValue -Pattern "MM/dd/yyyy HH:mm:ss"
Date = ConvertTo-DateTime -DateTime $dateValue
Architecture = Get-Architecture -String $leafName
InstallerType = Get-InstallerType -String $leafName
Type = Get-FileType -File $leafName
Expand Down
2 changes: 1 addition & 1 deletion Evergreen/Shared/Get-JetBrainsApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function Get-JetBrainsApp {
Version = $Release.version
Build = $Release.build
Edition = $Edition.Key
Date = ConvertTo-DateTime -DateTime $Release.date -Pattern $Update.DatePattern
Date = ConvertTo-DateTime -DateTime $Release.date
Sha256 = $Sha256
Size = $WindowsDownload.size
Architecture = Get-Architecture -String $WindowsDownload.link
Expand Down
2 changes: 1 addition & 1 deletion Evergreen/Shared/Get-OracleJava.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function Get-OracleJava {
[PSCustomObject] @{
Version = $LatestVersion.version
FullVersion = $LatestVersion.fullversion
Date = ConvertTo-DateTime -DateTime $LatestVersion.ga -Pattern $res.Get.Update.DateFormat
Date = ConvertTo-DateTime -DateTime $LatestVersion.ga
Sha256 = $Sha256
Architecture = Get-Architecture -String $res.Get.Download.Uri[$Type.Key]
Type = Get-FileType -File $res.Get.Download.Uri[$Type.Key]
Expand Down
6 changes: 3 additions & 3 deletions scripts/Export-EvergreenAppToFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
Reads any existing JSON for that application, adds the new version content, sorts for unique versions,
then outputs the new content back to the target JSON file.
#>
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(
Mandatory = $False,
Mandatory = $false,
Position = 0,
ValueFromPipeline,
HelpMessage = "An application name supported by Evergreen.")]
[ValidateNotNull()]
[System.String[]] $Name = "MicrosoftEdge",

[Parameter(
Mandatory = $False,
Mandatory = $false,
Position = 1,
ValueFromPipelineByPropertyName,
HelpMessage = "Specify a top-level directory path where the application JSON file will be saved into.",
Expand Down
40 changes: 20 additions & 20 deletions tests/Private/ConvertTo-DateTime.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ BeforeAll {
}

Describe -Name "ConvertTo-DateTime" {
Context "Convert a date/time string to a DateTime object" {
It "Preserves the date and time from the provided format" {
Context "Convert a date/time string to a formatted date string" {
It "Formats the parsed date as yyyy-MM-dd" {
InModuleScope -ModuleName "Evergreen" {
$Result = ConvertTo-DateTime -DateTime "2000/14/2 16:35:42" -Pattern "yyyy/d/M HH:mm:ss"

$Result | Should -BeOfType [System.DateTime]
$Result | Should -Be ([System.DateTime]::new(2000, 2, 14, 16, 35, 42))
$Result | Should -BeOfType [System.String]
$Result | Should -Be "2000-02-14"
}
}

Expand All @@ -34,9 +34,8 @@ Describe -Name "ConvertTo-DateTime" {
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $LocalCulture
$Result = ConvertTo-DateTime -DateTime "12/31/2024 11:45:32 PM" -Pattern "MM/dd/yyyy hh:mm:ss tt"

$Result | Should -BeOfType [System.DateTime]
$Result | Should -Be ([System.DateTime]::new(2024, 12, 31, 23, 45, 32))
$Result.ToString("d", $LocalCulture) | Should -Be "31/12/2024"
$Result | Should -BeOfType [System.String]
$Result | Should -Be "2024-12-31"
}
finally {
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OriginalCulture
Expand All @@ -58,10 +57,10 @@ Describe -Name "ConvertTo-DateTime" {
InModuleScope -ModuleName "Evergreen" {
$Result = ConvertTo-DateTime -DateTime "12/31/2024"

$Result | Should -BeOfType [System.DateTime]
$Result | Should -Be ([System.DateTime]::new(2024, 12, 31))
$Result | Should -BeOfType [System.String]
$Result | Should -Be "2024-12-31"
ConvertTo-DateTime -DateTime "December 31, 2024 11:45 PM" |
Should -Be ([System.DateTime]::new(2024, 12, 31, 23, 45, 0))
Should -Be "2024-12-31"
}
}
}
Expand All @@ -72,13 +71,15 @@ Describe -Name "ConvertTo-DateTime" {
@{ InputDate = "12/31/2024 23:45:32"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 32) }
@{ InputDate = "12/31/2024 11:45 PM"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 0) }
@{ InputDate = "12/31/2024 11:45:32 PM"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 32) }
@{ InputDate = "6/10/2026 12:00:00 AM"; Expected = [System.DateTime]::new(2026, 6, 10, 0, 0, 0) }
@{ InputDate = "12-31-2024"; Expected = [System.DateTime]::new(2024, 12, 31) }
@{ InputDate = "2024-12-31 23:45:32"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 32) }
@{ InputDate = "Tue, 31 Dec 2024 23:45:32 GMT"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 32, [System.DateTimeKind]::Utc).ToLocalTime() }
@{ InputDate = "Tue, 31 Dec 2024 23:45:32 +02:00"; Expected = [System.DateTime]::new(2024, 12, 31, 21, 45, 32, [System.DateTimeKind]::Utc).ToLocalTime() }
@{ InputDate = "31/12/2024"; Expected = [System.DateTime]::new(2024, 12, 31) }
@{ InputDate = "31/12/2024 11:45 PM"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 0) }
@{ InputDate = "31/12/2024 11:45:32 PM"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 32) }
@{ InputDate = "31/12/2024 23:45"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 0) }
@{ InputDate = "31/12/2024 23:45:32"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 32) }
@{ InputDate = "2024-12-31"; Expected = [System.DateTime]::new(2024, 12, 31) }
@{ InputDate = "2024-12-31T23:45:32"; Expected = [System.DateTime]::new(2024, 12, 31, 23, 45, 32) }
Expand All @@ -90,9 +91,8 @@ Describe -Name "ConvertTo-DateTime" {
InModuleScope -ModuleName "Evergreen" -Parameters @{ InputDate = $InputDate; Expected = $Expected } {
$Result = ConvertTo-DateTime -DateTime $InputDate

$Result | Should -BeOfType [System.DateTime]
$Result.Ticks | Should -Be $Expected.Ticks
$Result.Kind | Should -Be $Expected.Kind
$Result | Should -BeOfType [System.String]
$Result | Should -Be $Expected.ToString("yyyy-MM-dd", [System.Globalization.CultureInfo]::InvariantCulture)
}
}

Expand All @@ -107,14 +107,14 @@ Describe -Name "ConvertTo-DateTime" {
foreach ($InputDate in @("December 31, 2024 11:45 PM", "12/31/2024 23:45:00", "2024-12-31T23:45:00")) {
$Result = ConvertTo-DateTime -DateTime $InputDate

$Result | Should -BeOfType [System.DateTime]
$Result | Should -Be ([System.DateTime]::new(2024, 12, 31, 23, 45, 0))
$Result | Should -BeOfType [System.String]
$Result | Should -Be "2024-12-31"
}
$AmbiguousResult = ConvertTo-DateTime -DateTime "04/05/2024"
$AmbiguousResult | Should -Be ([System.DateTime]::new(2024, 4, 5))
$AmbiguousResult | Should -Be "2024-04-05"
foreach ($InputDate in @("04/05/2024 11:45 PM", "04/05/2024 11:45:00 PM", "04/05/2024 23:45:00")) {
ConvertTo-DateTime -DateTime $InputDate |
Should -Be ([System.DateTime]::new(2024, 4, 5, 23, 45, 0))
Should -Be "2024-04-05"
}
}
finally {
Expand All @@ -134,21 +134,21 @@ Describe -Name "ConvertTo-DateTime" {
It "Prefers automatic parsing over an explicit pattern" {
InModuleScope -ModuleName "Evergreen" {
ConvertTo-DateTime -DateTime "04/05/2024" -Pattern "dd/MM/yyyy" |
Should -Be ([System.DateTime]::new(2024, 4, 5))
Should -Be "2024-04-05"
}
}

It "Falls back to an explicit pattern when automatic parsing fails" {
InModuleScope -ModuleName "Evergreen" {
ConvertTo-DateTime -DateTime "2024|31|12" -Pattern "yyyy|dd|MM" -AutoDetect |
Should -Be ([System.DateTime]::new(2024, 12, 31))
Should -Be "2024-12-31"
}
}

It "Allows automatic parsing to be explicitly disabled" {
InModuleScope -ModuleName "Evergreen" {
ConvertTo-DateTime -DateTime "04/05/2024" -Pattern "dd/MM/yyyy" -AutoDetect:$false |
Should -Be ([System.DateTime]::new(2024, 5, 4))
Should -Be "2024-05-04"
{ ConvertTo-DateTime -DateTime "December 31, 2024" -AutoDetect:$false } |
Should -Throw "*Failed to parse date*"
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Private/Invoke-RestMethodWrapper.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#>
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "This is OK for tests.")]
param ()

BeforeDiscovery {
Expand Down Expand Up @@ -192,7 +193,7 @@ InModuleScope -ModuleName "Evergreen" {
ContentType = "application/vnd.github.v3+json"
ErrorAction = "SilentlyContinue"
Method = "Default"
SkipCertificateCheck = $True
SkipCertificateCheck = $true
SslProtocol = "Tls12"
UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Safari
Uri = "https://api.github.com/rate_limit"
Expand Down
3 changes: 2 additions & 1 deletion tests/Private/Invoke-WebRequestWrapper.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#>
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "This is OK for tests.")]
param ()

BeforeDiscovery {
Expand Down Expand Up @@ -241,7 +242,7 @@ InModuleScope -ModuleName "Evergreen" {
#Raw
#ReturnObject = "Content"
Method = "Default"
SkipCertificateCheck = $True
SkipCertificateCheck = $true
SslProtocol = "Tls12"
UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Safari
Uri = "https://github.com"
Expand Down
1 change: 1 addition & 0 deletions tests/Private/Remove-ProxyEnv.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#>
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "This is OK for tests.")]
param ()

BeforeDiscovery {
Expand Down
1 change: 1 addition & 0 deletions tests/Private/Set-ProxyEnv.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#>
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "This is OK for tests.")]
param ()

BeforeDiscovery {
Expand Down
26 changes: 26 additions & 0 deletions tests/Public/Get-EvergreenApp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "", Justification = "Outputs to log host.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "This is OK for tests.")]
param ()

BeforeDiscovery {
Expand Down Expand Up @@ -107,6 +108,31 @@ Describe -Tag "Get" -Name "Get-EvergreenApp works with supported application: <a
$item.URI | Should -BeOfType [System.String]
}
}

It "Output for <application> should return Date values as yyyy-MM-dd strings" {
if ($null -ne $RetrievalError -or $null -eq $Output -or @($Output).Count -eq 0) {
Set-ItResult -Skipped -Because "Get-EvergreenApp did not return output for '$application'."
return
}

$ItemsWithDates = @($Output | Where-Object { $null -ne $_.PSObject.Properties["Date"] })
if ($ItemsWithDates.Count -eq 0) {
Set-ItResult -Skipped -Because "Output for '$application' does not include the optional Date property."
return
}

foreach ($item in $ItemsWithDates) {
$item.Date | Should -BeOfType [System.String]
$ParsedDate = [System.DateTime]::MinValue
[System.DateTime]::TryParseExact(
$item.Date,
"yyyy-MM-dd",
[System.Globalization.CultureInfo]::InvariantCulture,
[System.Globalization.DateTimeStyles]::None,
[ref] $ParsedDate
) | Should -BeTrue -Because "Date '$($item.Date)' must be a valid date in yyyy-MM-dd format"
}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Public/Save-EvergreenApp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "", Justification = "Outputs to log host.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "This is OK for tests.")]
param ()

BeforeDiscovery {
Expand Down Expand Up @@ -52,7 +53,7 @@ Describe -Tag "Save", "Integration" -Name "Save-EvergreenApp" -ForEach $Installe
# Test that the file downloaded into the path: "$Path/Stable/Enterprise/<version>/x64/MicrosoftEdgeEnterpriseX64.msi"
It "Should save in the right path" {
$File = [System.IO.Path]::Combine($Path, $installer.Channel, $installer.Release, $installer.Version, $installer.Architecture, $(Split-Path -Path $installer.URI -Leaf))
Test-Path -Path $File -PathType "Leaf" | Should -Be $True
Test-Path -Path $File -PathType "Leaf" | Should -Be $true
}

It "Save-EvergreenApp should not throw with CustomPath" {
Expand Down
1 change: 1 addition & 0 deletions tests/Public/Start-EvergreenLibraryUpdate.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This OK for the tests files.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "", Justification = "Outputs to log host.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "This is OK for tests.")]
param ()

BeforeDiscovery {
Expand Down
1 change: 1 addition & 0 deletions tests/Public/Test-EvergreenApp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification="This is OK for the test files.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "", Justification="Outputs to log host.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "This is OK for tests.")]
param ()

BeforeDiscovery {
Expand Down
12 changes: 6 additions & 6 deletions tests/Public/Test-EvergreenLibrary.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Describe -Tag "Library" -Name "Test Evergreen Library functions" {
$params = @{
Path = "$env:GITHUB_WORKSPACE\tests\EvergreenLibrary.json"
Destination = "$Path\EvergreenLibrary\EvergreenLibrary.json"
Force = $True
Confirm = $False
Force = $true
Confirm = $false
}
Copy-Item @params
}
Expand All @@ -61,8 +61,8 @@ Describe -Tag "Library" -Name "Test Evergreen Library functions" {
$params = @{
Path = "$env:GITHUB_WORKSPACE\tests\EvergreenLibrary.json"
Destination = "$Path\EvergreenLibrary\EvergreenLibrary.json"
Force = $True
Confirm = $False
Force = $true
Confirm = $false
}
Copy-Item @params
}
Expand Down Expand Up @@ -106,8 +106,8 @@ Describe -Tag "Library" -Name "Test Evergreen Library functions" {
BeforeAll {
$params = @{
FilePath = "$Path\EvergreenLibrary\EvergreenLibrary.json"
Force = $True
Confirm = $False
Force = $true
Confirm = $false
}
"nonsense" | Out-File @params
}
Expand Down
Loading
Loading