46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
namespace View_by_Distance.Shared.Models.Stateless;
|
|
|
|
internal abstract class Age
|
|
{
|
|
|
|
internal static (int, TimeSpan) GetAge(long minuendTicks, long subtrahendTicks)
|
|
{
|
|
TimeSpan result;
|
|
int years = 0;
|
|
DateTime check = new(subtrahendTicks);
|
|
for (int i = 0; i < int.MaxValue; i++)
|
|
{
|
|
check = check.AddYears(1);
|
|
if (check.Ticks > minuendTicks)
|
|
break;
|
|
years += 1;
|
|
}
|
|
result = new(minuendTicks - check.AddYears(-1).Ticks);
|
|
return (years, result);
|
|
}
|
|
|
|
internal static (int, TimeSpan) GetAge(long minuendTicks, DateTime subtrahend)
|
|
{
|
|
(int years, TimeSpan result) = GetAge(minuendTicks, subtrahend.Ticks);
|
|
return (years, result);
|
|
}
|
|
|
|
internal static (int, TimeSpan) GetAge(DateTime minuend, DateTime subtrahend)
|
|
{
|
|
(int years, TimeSpan result) = GetAge(minuend.Ticks, subtrahend.Ticks);
|
|
return (years, result);
|
|
}
|
|
|
|
internal static int? GetApproximateYears(char[] personCharacters, string personDisplayDirectoryName)
|
|
{
|
|
int? result;
|
|
const int zero = 0;
|
|
string[] segments = personDisplayDirectoryName.Split(personCharacters);
|
|
if (segments.Length == 1 || !int.TryParse(segments[1].Split('-')[zero], out int years))
|
|
result = null;
|
|
else
|
|
result = years;
|
|
return result;
|
|
}
|
|
|
|
} |