Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 4, 2025
1 parent a2f4506 commit 9d06b9b
Show file tree
Hide file tree
Showing 3 changed files with 13,164 additions and 2,915 deletions.
87 changes: 0 additions & 87 deletions src/Verify.Tests/CultureToDateBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#if NET9_0
public class CultureToDateBuilder
{
const string monthDayFormat = "MMMM MMM dddd ddd";

[Fact]
public Task BuildCultureToDate()
{
Expand All @@ -23,16 +21,6 @@ static partial class DateScrubber
""");
foreach (var culture in cultures)
{
var (longDate, shortDate) = FindDates(culture);
if (culture.Name.Contains('-'))
{
var (parentLongDate, parentShortDate) = FindDates(culture.Parent);
if (longDate == parentLongDate && shortDate == parentShortDate)
{
continue;
}
}

var formatInfo = culture.DateTimeFormat;

var calendar = culture.Calendar;
Expand All @@ -51,8 +39,6 @@ static partial class DateScrubber
{
"{{culture.Name}}",
new(
new(2023, {{longDate.Month}}, {{longDate.Day}}, {{longDate.Hour}}, 10, 10, 10),
new(2023, {{shortDate.Month}}, {{shortDate.Day}}, {{shortDate.Hour}}, 0, 0),
{{int.Max(amLength, pmLength)}},
{{int.Min(amLength, pmLength)}},
{{monthNames.Long}},
Expand Down Expand Up @@ -89,78 +75,5 @@ static partial class DateScrubber
.ToList();
return (lengths.Max(), lengths.Min());
}

static (DateTime longDate, DateTime shortDate) FindDates(CultureInfo culture)
{
var formatInfo = culture.DateTimeFormat;
var longDate = FindLongDate(formatInfo);
var shortDate = FindShortDate(formatInfo);
return (longDate, shortDate);
}

static DateTime FindLongDate(DateTimeFormatInfo formatInfo)
{
DateTime longDate = default;
var longFormatted = "";
var amLength = formatInfo.AMDesignator.Length;
var pmLength = formatInfo.PMDesignator.Length;
for (var month = 1; month <= 12; month++)
{
for (var day = 20; day <= 27; day++)
{
DateTime date;
if (amLength > pmLength)
{
date = new(2023, month, day, 1, 0, 0, 0);
}
else
{
date = new(2023, month, day, 12, 0, 0, 0);
}

var formatted = date.ToString(monthDayFormat, formatInfo);
if (formatted.Length > longFormatted.Length)
{
longFormatted = formatted;
longDate = date;
}
}
}

return longDate;
}

static DateTime FindShortDate(DateTimeFormatInfo formatInfo)
{
DateTime shortDate = default;
string? shortFormatted = null;
var amLength = formatInfo.AMDesignator.Length;
var pmLength = formatInfo.PMDesignator.Length;
for (var month = 1; month <= 12; month++)
{
for (var day = 1; day <= 7; day++)
{
DateTime date;
if (amLength <= pmLength)
{
date = new(2023, month, day, 1, 0, 0, 0);
}
else
{
date = new(2023, month, day, 13, 0, 0, 0);
}

var formatted = date.ToString(monthDayFormat, formatInfo);
if (shortFormatted == null ||
formatted.Length < shortFormatted.Length)
{
shortFormatted = formatted;
shortDate = date;
}
}
}

return shortDate;
}
}
#endif
4 changes: 0 additions & 4 deletions src/Verify/Serialization/Scrubbers/CultureDate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
readonly struct CultureDate(
DateTime longDate,
DateTime shortDate,
int amPmLong,
int amPmShort,
int monthNameLong,
Expand All @@ -16,8 +14,6 @@
int eraLong = 0,
int eraShort = 0)
{
public DateTime Long { get; } = longDate;
public DateTime Short { get; } = shortDate;
public int AmPmLong { get; } = amPmLong;
public int AmPmShort { get; } = amPmShort;
public int MonthNameLong { get; } = monthNameLong;
Expand Down
Loading

0 comments on commit 9d06b9b

Please sign in to comment.