diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props
index 9a93c8fcb..a9099bb36 100644
--- a/src/Directory.Packages.props
+++ b/src/Directory.Packages.props
@@ -3,6 +3,7 @@
true
+
@@ -28,4 +29,4 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
-
\ No newline at end of file
+
diff --git a/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs b/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs
index b6e9a6500..b9d036fb0 100644
--- a/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs
+++ b/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs
@@ -9,30 +9,28 @@ public sealed class ElapsedTimeColumn : ProgressColumn
protected internal override bool NoWrap => true;
///
- /// Gets or sets the style of the remaining time text.
+ /// Gets or sets the style of the elapsed time text.
///
public Style Style { get; set; } = Color.Blue;
+ ///
+ /// Gets or sets the format of the elapsed time text.
+ ///
+ public string? Format { get; set; } = @"hh\:mm\:ss";
+
///
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
{
- var elapsed = task.ElapsedTime;
- if (elapsed == null)
+ if (task.ElapsedTime is not TimeSpan elapsed)
{
return new Markup("--:--:--");
}
- if (elapsed.Value.TotalHours > 99)
+ if (elapsed.TotalHours > 99)
{
return new Markup("**:**:**");
}
- return new Text($"{elapsed.Value:hh\\:mm\\:ss}", Style ?? Style.Plain);
- }
-
- ///
- public override int? GetColumnWidth(RenderOptions options)
- {
- return 8;
+ return new Text($"{elapsed.ToString(Format)}", Style ?? Style.Plain);
}
-}
\ No newline at end of file
+}
diff --git a/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs b/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs
index 9495877d6..d4e24fd30 100644
--- a/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs
+++ b/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs
@@ -13,26 +13,24 @@ public sealed class RemainingTimeColumn : ProgressColumn
///
public Style Style { get; set; } = Color.Blue;
+ ///
+ /// Gets or sets the format of the remaining time text.
+ ///
+ public string? Format { get; set; } = @"hh\:mm\:ss";
+
///
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
{
- var remaining = task.RemainingTime;
- if (remaining == null)
+ if (task.RemainingTime is not TimeSpan remaining)
{
return new Markup("--:--:--");
}
- if (remaining.Value.TotalHours > 99)
+ if (remaining.TotalHours > 99)
{
return new Markup("**:**:**");
}
- return new Text($"{remaining.Value:hh\\:mm\\:ss}", Style ?? Style.Plain);
- }
-
- ///
- public override int? GetColumnWidth(RenderOptions options)
- {
- return 8;
+ return new Text($"{remaining.ToString(Format)}", Style ?? Style.Plain);
}
-}
\ No newline at end of file
+}
diff --git a/src/Spectre.Console/Live/Progress/ProgressTask.cs b/src/Spectre.Console/Live/Progress/ProgressTask.cs
index c0acfac62..4a5bf7f74 100644
--- a/src/Spectre.Console/Live/Progress/ProgressTask.cs
+++ b/src/Spectre.Console/Live/Progress/ProgressTask.cs
@@ -47,12 +47,12 @@ public double Value
///
/// Gets the start time of the task.
///
- public DateTime? StartTime { get; private set; }
+ public long? StartTime { get; private set; }
///
/// Gets the stop time of the task.
///
- public DateTime? StopTime { get; private set; }
+ public long? StopTime { get; private set; }
///
/// Gets the task state.
@@ -118,7 +118,7 @@ public ProgressTask(int id, string description, double maxValue, bool autoStart
Id = id;
State = new ProgressTaskState();
- StartTime = autoStart ? DateTime.Now : null;
+ StartTime = autoStart ? TimeProvider.System.GetTimestamp() : null;
}
///
@@ -133,7 +133,7 @@ public void StartTask()
throw new InvalidOperationException("Stopped tasks cannot be restarted");
}
- StartTime = DateTime.Now;
+ StartTime = TimeProvider.System.GetTimestamp();
StopTime = null;
}
}
@@ -145,7 +145,7 @@ public void StopTask()
{
lock (_lock)
{
- var now = DateTime.Now;
+ var now = TimeProvider.System.GetTimestamp();
StartTime ??= now;
StopTime = now;
@@ -263,17 +263,17 @@ private double GetPercentage()
{
lock (_lock)
{
- if (StartTime == null)
+ if (StartTime is not long start)
{
return null;
}
- if (StopTime != null)
+ if (StopTime is long stop)
{
- return StopTime - StartTime;
+ return TimeProvider.System.GetElapsedTime(start, stop);
}
- return DateTime.Now - StartTime;
+ return TimeProvider.System.GetElapsedTime(start);
}
}
@@ -310,4 +310,4 @@ void IProgress.Report(double value)
{
Update(increment: value - Value);
}
-}
\ No newline at end of file
+}
diff --git a/src/Spectre.Console/Spectre.Console.csproj b/src/Spectre.Console/Spectre.Console.csproj
index 67b629704..3e1eda6aa 100644
--- a/src/Spectre.Console/Spectre.Console.csproj
+++ b/src/Spectre.Console/Spectre.Console.csproj
@@ -17,6 +17,7 @@
+