2026-03-21 00:58:01 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using Wino.Core.Domain.Enums;
|
|
|
|
|
|
|
|
|
|
namespace Wino.Core.Domain.Models.Calendar;
|
|
|
|
|
|
|
|
|
|
public sealed class CalendarRangeTextFormatter : ICalendarRangeTextFormatter
|
|
|
|
|
{
|
|
|
|
|
public string Format(VisibleDateRange range, IDateContextProvider dateContextProvider)
|
|
|
|
|
{
|
|
|
|
|
var culture = dateContextProvider.Culture;
|
|
|
|
|
|
2026-03-24 16:57:13 +01:00
|
|
|
if (range.DayCount >= 28)
|
2026-03-21 00:58:01 +01:00
|
|
|
{
|
2026-03-24 16:57:13 +01:00
|
|
|
return FormatMonth(range.PrimaryDate, culture);
|
2026-03-21 00:58:01 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 16:57:13 +01:00
|
|
|
if (range.DayCount == 1 || range.DisplayType == CalendarDisplayType.Day)
|
|
|
|
|
{
|
|
|
|
|
return FormatDate(range.StartDate, culture);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:05:09 +01:00
|
|
|
if (range.SpansSingleMonth)
|
|
|
|
|
{
|
|
|
|
|
return $"{FormatDate(range.StartDate, culture)} - {FormatDay(range.EndDate, culture)}";
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 16:57:13 +01:00
|
|
|
return $"{FormatDate(range.StartDate, culture)} - {FormatDate(range.EndDate, culture)}";
|
2026-03-21 00:58:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string FormatDate(DateOnly date, CultureInfo culture)
|
2026-03-24 16:57:13 +01:00
|
|
|
=> date.ToString(culture.DateTimeFormat.MonthDayPattern, culture);
|
|
|
|
|
|
2026-03-24 18:05:09 +01:00
|
|
|
private static string FormatDay(DateOnly date, CultureInfo culture)
|
|
|
|
|
=> date.Day.ToString(culture);
|
|
|
|
|
|
2026-03-24 16:57:13 +01:00
|
|
|
private static string FormatMonth(DateOnly date, CultureInfo culture)
|
|
|
|
|
=> date.ToString(culture.DateTimeFormat.YearMonthPattern, culture);
|
2026-03-21 00:58:01 +01:00
|
|
|
}
|