From df30975d5ed9dd6adcc89c44ece637e40409d8ff Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Tue, 28 May 2019 19:30:50 -0600 Subject: [PATCH] Display Duration when displaying HistoryInfo - impl #9518 --- .../PowerShellCore_format_ps1xml.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index a4169406bce..38d4fe125ce 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -342,9 +342,26 @@ private static IEnumerable ViewsOf_Microsoft_PowerShell_Co yield return new FormatViewDefinition("history", TableControl.Create() .AddHeader(Alignment.Right, width: 4) + .AddHeader(Alignment.Right, label: "Duration", width: 12) .AddHeader() .StartRowDefinition() .AddPropertyColumn("Id") + .AddScriptBlockColumn(@" + if ($_.Duration.TotalHours -ge 10) { + return ""{0}:{1:mm}:{1:ss}.{1:fff}"" -f [int]$_.Duration.TotalHours, $_.Duration + } + elseif ($_.Duration.TotalHours -ge 1) { + $formatString = ""h\:mm\:ss\.fff"" + } + elseif ($_.Duration.TotalMinutes -ge 1) { + $formatString = ""m\:ss\.fff"" + } + else { + $formatString = ""s\.fff"" + } + + $_.Duration.ToString($formatString) + ") .AddPropertyColumn("CommandLine") .EndRowDefinition() .EndTable());