2026-01-22 20:47:55 +00:00
|
|
|
namespace RealCV.Application.Helpers;
|
2026-01-20 16:45:43 +01:00
|
|
|
|
|
|
|
|
public static class DateHelpers
|
|
|
|
|
{
|
2026-01-21 02:09:26 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Calculates the number of months between two dates.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int MonthsBetween(DateOnly start, DateOnly end)
|
|
|
|
|
{
|
|
|
|
|
return ((end.Year - start.Year) * 12) + (end.Month - start.Month);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Calculates the number of months between two dates.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int MonthsBetween(DateTime start, DateTime end)
|
|
|
|
|
{
|
|
|
|
|
return ((end.Year - start.Year) * 12) + (end.Month - start.Month);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-20 16:45:43 +01:00
|
|
|
public static DateOnly? ParseDate(string? dateString)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(dateString))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DateOnly.TryParse(dateString, out var date))
|
|
|
|
|
{
|
|
|
|
|
return date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|