mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add Milliseconds Parameter to New-TimeSpan (#17621)
This commit is contained in:
@@ -88,6 +88,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ParameterSetName = "Time")]
|
||||
public int Seconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Allows the user to override the millisecond.
|
||||
/// </summary>
|
||||
[Parameter(ParameterSetName = "Time")]
|
||||
public int Milliseconds { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region methods
|
||||
@@ -119,7 +125,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
break;
|
||||
|
||||
case "Time":
|
||||
result = new TimeSpan(Days, Hours, Minutes, Seconds);
|
||||
result = new TimeSpan(Days, Hours, Minutes, Seconds, Milliseconds);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
Describe "New-TimeSpan DRT Unit Tests" -Tags "CI" {
|
||||
|
||||
It "Should works proper with new-timespan"{
|
||||
$results = New-TimeSpan -Days 10 -Hours 10 -Minutes 10 -Seconds 10
|
||||
$results = New-TimeSpan -Days 10 -Hours 10 -Minutes 10 -Seconds 10 -Milliseconds 10
|
||||
$results | Should -BeOfType System.Timespan
|
||||
$results.Days | Should -Be 10
|
||||
$results.Hours | Should -Be 10
|
||||
$results.Minutes | Should -Be 10
|
||||
$results.Seconds | Should -Be 10
|
||||
$results.Milliseconds | Should -Be 10
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,29 +21,30 @@ Describe "New-TimeSpan" -Tags "CI" {
|
||||
}
|
||||
|
||||
Context "Core Functionality Tests" {
|
||||
New-Variable -Name testObject -Value $(New-TimeSpan -Days 2 -Hours 23 -Minutes 4 -Seconds 3) -Force
|
||||
New-Variable -Name testObject -Value $(New-TimeSpan -Days 2 -Hours 23 -Minutes 4 -Seconds 3 -Milliseconds 2) -Force
|
||||
|
||||
$expectedOutput = @{ "Days" = "2";
|
||||
"Hours" = "23";
|
||||
"Minutes" = "4";
|
||||
"Seconds" = "3";
|
||||
"Milliseconds" = "0";
|
||||
"Ticks" = "2558430000000";
|
||||
"TotalDays" = "2.96114583333333";
|
||||
"TotalHours" = "71.0675";
|
||||
"TotalMinutes" = "4264.05";
|
||||
"TotalSeconds" = "255843";
|
||||
"TotalMilliseconds" = "255843000"
|
||||
"Milliseconds" = "2";
|
||||
"Ticks" = "2558430020000";
|
||||
"TotalDays" = "2.96114585648148";
|
||||
"TotalHours" = "71.0675005555556";
|
||||
"TotalMinutes" = "4264.05003333333";
|
||||
"TotalSeconds" = "255843.002";
|
||||
"TotalMilliseconds" = "255843002"
|
||||
}
|
||||
|
||||
$TEN_MILLION = 10000000
|
||||
|
||||
It "Should have expected values for time properties set during creation" {
|
||||
$testObject.Days | Should -Be $expectedOutput["Days"]
|
||||
$testObject.Hours | Should -Be $expectedOutput["Hours"]
|
||||
$testObject.Minutes | Should -Be $expectedOutput["Minutes"]
|
||||
$testObject.Seconds | Should -Be $expectedOutput["Seconds"]
|
||||
$testObject.Ticks | Should -Be $expectedOutput["Ticks"]
|
||||
$testObject.Days | Should -Be $expectedOutput["Days"]
|
||||
$testObject.Hours | Should -Be $expectedOutput["Hours"]
|
||||
$testObject.Minutes | Should -Be $expectedOutput["Minutes"]
|
||||
$testObject.Seconds | Should -Be $expectedOutput["Seconds"]
|
||||
$testObject.Milliseconds | Should -Be $expectedOutput["Milliseconds"]
|
||||
$testObject.Ticks | Should -Be $expectedOutput["Ticks"]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user