Files
lux/EgwCoreLib.Lux.Core/DtUtils.cs
T
2025-12-09 15:56:05 +01:00

39 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EgwCoreLib.Lux.Core
{
public class DtUtils
{
/// <summary>
/// Formattaione dataora:
/// - fino ad 1 h Ym Zs
/// - fino ad 24h Xh Ym
/// - oltre 24h Wd Xh Ym
/// </summary>
/// <param name="tsReq">Timespan da mostrare</param>
/// <returns></returns>
public static string FormatDateTime(TimeSpan tsReq)
{
if (tsReq.TotalHours < 1)
{
// Only minutes and seconds
return $"{tsReq.Minutes:00}\' {tsReq.Seconds:00}\"";
}
else if (tsReq.TotalHours < 24)
{
// Hours, minutes, seconds
return $"{tsReq.Hours}h {tsReq.Minutes:00}\'";
}
else
{
// Days + hours + minutes
return $"{tsReq.Days}d {tsReq.Hours}h {tsReq.Minutes:00}\'";
}
}
}
}