Add GetDifference method to DateTimeExtension and implement TimeCheck endpoint in LeaveRequestController
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m35s
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m35s
This commit is contained in:
parent
5b054f9948
commit
c20e1b48bd
2 changed files with 60 additions and 33 deletions
|
|
@ -174,6 +174,29 @@ namespace BMA.EHR.Domain.Extensions
|
|||
}
|
||||
}
|
||||
|
||||
public static (int Years, int Months, int Days) GetDifference(this DateTime from, DateTime to)
|
||||
{
|
||||
if (from > to) (from, to) = (to, from); // swap ถ้าลำดับสลับ
|
||||
|
||||
int years = to.Year - from.Year;
|
||||
int months = to.Month - from.Month;
|
||||
int days = to.Day - from.Day;
|
||||
|
||||
if (days < 0)
|
||||
{
|
||||
months--;
|
||||
days += DateTime.DaysInMonth(to.Year, to.Month == 1 ? 12 : to.Month - 1);
|
||||
}
|
||||
|
||||
if (months < 0)
|
||||
{
|
||||
years--;
|
||||
months += 12;
|
||||
}
|
||||
|
||||
return (years, months, days);
|
||||
}
|
||||
|
||||
public static int CalculateAge(this DateTime date, int plusYear = 0, int subtractYear = 0)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue