Mike Phares be7a6abbf4 AppSettings and Configuration changes,
major changes to E_Distance and minor for D_Face
2022-08-19 21:37:36 -07:00

40 lines
2.0 KiB
C#

using System.Globalization;
namespace View_by_Distance.Shared.Models.Stateless.Methods;
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 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 Models.PersonBirthday? GetPersonBirthday(string personKey)
{
Models.PersonBirthday? result;
DateTime? dateTime = GetDateTime(personKey);
if (dateTime is null)
result = null;
else
result = new(dateTime.Value);
return result;
}
internal static TimeSpan? GetTimeSpan(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday)
{
TimeSpan? timeSpan;
if (isWrongYear is null || isWrongYear.Value || personBirthday.Value.Year < 1900)
timeSpan = null;
else
timeSpan = new(minimumDateTime.Ticks - personBirthday.Value.Ticks);
return timeSpan;
}
}