Files
StockSharp/Reporting/FormatExtensions.cs
mika@stocksharp.com 8b8d0a95ed Reporting: format durations with the invariant constant TimeSpan format
FormatExtensions formatted TimeSpan as hh\:mm\:ss, which drops sub-second precision and cannot
represent durations of a day or more. Use the constant (c) format with the invariant culture, matching
the JSON report representation.

Update the expected report fixtures accordingly and harden the CSV report tests to assert full rows
(including the fractional duration) under an invariant-culture scope, plus an exact trades row count.
2026-06-19 02:36:13 +03:00

37 lines
1.3 KiB
C#

namespace StockSharp.Reporting;
using System.Globalization;
/// <summary>
/// Format extensions.
/// </summary>
static class FormatExtensions
{
/// <summary>
/// To format the <see cref="TimeSpan"/> in <see cref="string"/>.
/// </summary>
/// <param name="time"><see cref="TimeSpan"/> value.</param>
/// <returns><see cref="string"/>.</returns>
public static string Format(this TimeSpan? time)
=> time?.Format() ?? string.Empty;
/// <summary>
/// To format the <see cref="TimeSpan"/> in <see cref="string"/>.
/// </summary>
/// <param name="time"><see cref="TimeSpan"/> value.</param>
/// <returns><see cref="string"/>.</returns>
public static string Format(this TimeSpan time)
=> time.ToString("c", CultureInfo.InvariantCulture);
/// <summary>
/// To format the <see cref="DateTime"/> in <see cref="string"/>.
/// </summary>
/// <param name="time"><see cref="DateTime"/> value.</param>
/// <returns><see cref="string"/>.</returns>
public static string Format(this DateTime time)
// Invariant ISO-8601. The leading '.' before the 'F' specifiers is emitted only when the
// fractional part is non-zero, and trailing zero digits are trimmed, so whole-second values
// render as 2024-01-15T10:00:00Z - matching the JSON report representation.
=> time.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFFK", CultureInfo.InvariantCulture);
}