Facebook logic, IsDefaultName, GetFiles update and
HardCoded tests
This commit is contained in:
@ -132,4 +132,77 @@ internal abstract class PersonBirthday
|
||||
return results;
|
||||
}
|
||||
|
||||
private static string? GetMonthShortForm(string month)
|
||||
{
|
||||
string? result = month.ToLower()[0] switch
|
||||
{
|
||||
// 'j' => "jan",
|
||||
'f' => "feb",
|
||||
// 'm' => "mar",
|
||||
// 'a' => "apr",
|
||||
// 'm' => "may",
|
||||
// 'j' => "jun",
|
||||
// 'j' => "jul",
|
||||
// 'a' => "aug",
|
||||
's' => "sep",
|
||||
'o' => "oct",
|
||||
'n' => "nov",
|
||||
'd' => "dec",
|
||||
_ => null
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static DateTime? GetDate(string month, string day, string year)
|
||||
{
|
||||
DateTime? result;
|
||||
DateTime dayDateTime;
|
||||
DateTime yearDateTime;
|
||||
DateTime monthDateTime;
|
||||
string? monthShortHand = string.IsNullOrEmpty(month) ? "x" : GetMonthShortForm(month);
|
||||
if (month.Length > 3)
|
||||
{
|
||||
if (!DateTime.TryParseExact($"{month},1,1500", "MMMM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out monthDateTime))
|
||||
monthDateTime = DateTime.MinValue;
|
||||
}
|
||||
else if (month.Length == 3)
|
||||
{
|
||||
if (!DateTime.TryParseExact($"{month},1,1500", "MMM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out monthDateTime))
|
||||
monthDateTime = DateTime.MinValue;
|
||||
}
|
||||
else if (month.Length == 1 && monthShortHand is not null)
|
||||
{
|
||||
if (!DateTime.TryParseExact($"{monthShortHand},1,1500", "MMM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out monthDateTime))
|
||||
monthDateTime = DateTime.MinValue;
|
||||
}
|
||||
else if (int.TryParse(month, out int _))
|
||||
{
|
||||
if (!DateTime.TryParseExact($"{month.PadLeft(2, '0')[..2]},1,1500", "MM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out monthDateTime))
|
||||
monthDateTime = DateTime.MinValue;
|
||||
}
|
||||
else
|
||||
monthDateTime = DateTime.MinValue;
|
||||
if (!int.TryParse(day, out int _))
|
||||
dayDateTime = DateTime.MinValue;
|
||||
else
|
||||
{
|
||||
if (!DateTime.TryParseExact($"01,{day.PadLeft(2, '0')[..2]},1500", "MM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dayDateTime))
|
||||
dayDateTime = DateTime.MinValue;
|
||||
}
|
||||
if (year.Length == 2 && int.TryParse(year, out int _))
|
||||
{
|
||||
if (!DateTime.TryParseExact($"01,01,{year.PadLeft(4, '0')[..4]}", "MM,dd,yy", CultureInfo.InvariantCulture, DateTimeStyles.None, out yearDateTime))
|
||||
yearDateTime = DateTime.MinValue;
|
||||
}
|
||||
else if (year.Length == 4 && int.TryParse(year, out int _))
|
||||
{
|
||||
if (!DateTime.TryParseExact($"01,01,{year.PadLeft(4, '0')[..4]}", "MM,dd,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out yearDateTime))
|
||||
yearDateTime = DateTime.MinValue;
|
||||
}
|
||||
else
|
||||
yearDateTime = DateTime.MinValue;
|
||||
result = monthDateTime == DateTime.MinValue ? null : dayDateTime == DateTime.MinValue ? null : yearDateTime == DateTime.MinValue ? null : new(yearDateTime.Year, monthDateTime.Month, dayDateTime.Day);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user