feat: add yearly summary page with navigation and formatting improvements
All checks were successful
Publish Container / publish (push) Successful in 3m17s
All checks were successful
Publish Container / publish (push) Successful in 3m17s
This commit is contained in:
parent
0991128b30
commit
0d003903cf
12 changed files with 406 additions and 70 deletions
37
Formatting/DurationFormatter.cs
Normal file
37
Formatting/DurationFormatter.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
namespace WorkTracker.Formatting;
|
||||
|
||||
public static class DurationFormatter
|
||||
{
|
||||
public static string FormatHours(decimal value, bool blankWhenZero = false)
|
||||
{
|
||||
var totalMinutes = (int)Math.Round(value * 60m, MidpointRounding.AwayFromZero);
|
||||
if (totalMinutes == 0)
|
||||
{
|
||||
return blankWhenZero ? string.Empty : "0";
|
||||
}
|
||||
|
||||
var sign = totalMinutes < 0 ? "-" : string.Empty;
|
||||
totalMinutes = Math.Abs(totalMinutes);
|
||||
|
||||
var hours = totalMinutes / 60;
|
||||
var minutes = totalMinutes % 60;
|
||||
return minutes == 0
|
||||
? $"{sign}{hours}"
|
||||
: $"{sign}{hours}:{minutes:00}";
|
||||
}
|
||||
|
||||
public static string FormatSignedHours(decimal value)
|
||||
{
|
||||
if (value > 0m)
|
||||
{
|
||||
return $"+{FormatHours(value)}";
|
||||
}
|
||||
|
||||
if (value < 0m)
|
||||
{
|
||||
return $"-{FormatHours(Math.Abs(value))}";
|
||||
}
|
||||
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue