fix dateextension

This commit is contained in:
Suphonchai Phoonsawat 2024-01-03 10:59:27 +07:00
parent b371717f89
commit e6f2654d9c

View file

@ -126,7 +126,11 @@ namespace BMA.EHR.Domain.Extensions
if (currentDate.Day < date.Day)
{
months--;
int lastMonthDays = DateTime.DaysInMonth(currentDate.Year, currentDate.Month - 1);
int lastMonthDays = 0;
if (currentDate.Month == 1)
lastMonthDays = DateTime.DaysInMonth(currentDate.Year - 1, 12);
else
lastMonthDays = DateTime.DaysInMonth(currentDate.Year, currentDate.Month - 1);
days = lastMonthDays - date.Day + currentDate.Day;
}
else
@ -141,7 +145,11 @@ namespace BMA.EHR.Domain.Extensions
if (currentDate.Day < date.Day)
{
months--;
int lastMonthDays = DateTime.DaysInMonth(currentDate.Year, currentDate.Month - 1);
int lastMonthDays = 0;
if (currentDate.Month == 1)
lastMonthDays = DateTime.DaysInMonth(currentDate.Year - 1, 12);
else
lastMonthDays = DateTime.DaysInMonth(currentDate.Year, currentDate.Month - 1);
days = lastMonthDays - date.Day + currentDate.Day;
}
else