Moved more to Map library
This commit is contained in:
@ -8,14 +8,12 @@ internal abstract class PersonBirthday
|
||||
internal static DateTime GetDefaultValue() => DateTime.MinValue; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
internal static string GetFormat() => "yyyy-MM-dd_HH";
|
||||
internal static string GetFormatted(Models.PersonBirthday personBirthday) => personBirthday.Value.ToString(GetFormat());
|
||||
internal static string GetFileName(Models.PersonBirthday personBirthday) => $"{personBirthday.Value.ToString(GetFormat())}.json";
|
||||
internal static string GetFormatted(Models.PersonBirthday personBirthday) => personBirthday.Value.ToString(Stateless.IPersonBirthday.Format);
|
||||
internal static string GetFileName(Models.PersonBirthday personBirthday) => $"{personBirthday.Value.ToString(Stateless.IPersonBirthday.Format)}.json";
|
||||
internal static bool DoesBirthDateExits(Properties.IStorage storage, Models.PersonBirthday personBirthday) => File.Exists(GetFileFullName(storage, personBirthday));
|
||||
internal static Models.PersonBirthday GetNextBirthDate(Properties.IStorage storage) => throw new Exception(storage.ToString()); // Person.GetNextBirthDate(storage);
|
||||
internal static string GetFileFullName(Properties.IStorage storage, Models.PersonBirthday personBirthday) => Path.Combine(storage.PeopleRootDirectory, "{}", GetFileName(personBirthday));
|
||||
internal static DateTime? GetDateTime(string personKey) => DateTime.TryParseExact(personKey, GetFormat(), CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;
|
||||
internal static DateTime? GetDateTime(string personKey) => DateTime.TryParseExact(personKey, Stateless.IPersonBirthday.Format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;
|
||||
|
||||
internal static Models.PersonBirthday? GetPersonBirthday(string personKey)
|
||||
{
|
||||
@ -37,4 +35,41 @@ internal abstract class PersonBirthday
|
||||
timeSpan = new(minimumDateTime.Ticks - personBirthday.Value.Ticks);
|
||||
return timeSpan;
|
||||
}
|
||||
|
||||
internal static (int, TimeSpan) GetAge(DateTime dateTime, Models.PersonBirthday birthday)
|
||||
{
|
||||
TimeSpan result;
|
||||
int years;
|
||||
if (birthday?.Value is null)
|
||||
throw new NullReferenceException(nameof(birthday.Value));
|
||||
(years, result) = Age.GetAge(dateTime, birthday.Value);
|
||||
return (years, result);
|
||||
}
|
||||
|
||||
internal static (int, double) GetAge(DateTime dateTime, DateTime dayBeforeLeapDate, Models.PersonBirthday birthday)
|
||||
{
|
||||
double result;
|
||||
(int years, TimeSpan timeSpan) = GetAge(dateTime, birthday);
|
||||
if (!DateTime.IsLeapYear(dateTime.Year) || dateTime < dayBeforeLeapDate.AddDays(1))
|
||||
result = timeSpan.TotalDays / 365;
|
||||
else
|
||||
result = timeSpan.TotalDays / 366;
|
||||
return (years, result);
|
||||
}
|
||||
|
||||
internal static double? GetAge(Models.PersonBirthday birthday)
|
||||
{
|
||||
double? result;
|
||||
if (birthday is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
DateTime dateTime = DateTime.Now;
|
||||
DateTime dayBeforeLeapDate = new(dateTime.Year, 2, 28);
|
||||
(int years, double r) = GetAge(dateTime, dayBeforeLeapDate, birthday);
|
||||
result = years + r;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user