Где то так, но пробегитесь тестами по крайним датам
Console.WriteLine(new DateTime(2023, 3, 1).GetSeason());
Console.WriteLine(new DateTime(2023, 6, 1).GetSeason());
Console.WriteLine(new DateTime(2023, 9, 1).GetSeason());
Console.WriteLine(new DateTime(2023, 12, 1).GetSeason());
Console.WriteLine(new DateTime(2023, 12, 2).GetSeasonDay());
public enum Season
{
Spring,
Summer,
Autumn,
Winter
}
public static class SeasonTools
{
public static Season GetSeason(this DateTime date)
{
int month = date.Month;
if (month >= 3 && month <= 5) return Season.Spring;
else if (month >= 6 && month <= 8) return Season.Summer;
else if (month >= 9 && month <= 11) return Season.Autumn;
else return Season.Winter;
}
public static int GetSeasonDay(this DateTime date)
{
int month = date.Month;
if (month >= 3 && month <= 5) return GetDay(date,Season.Spring);
else if (month >= 6 && month <= 8) return GetDay(date,Season.Summer);
else if (month >= 9 && month <= 11) return GetDay(date,Season.Autumn);
else return GetDay(date, Season.Winter);
}
private static int GetDay(DateTime date, Season season)
{
if (season == Season.Spring) return (int) (date - new DateTime(date.Year, 3, 1) ).TotalDays ;
else if (season == Season.Summer) return (int)(date - new DateTime(date.Year, 6, 1)).TotalDays;
else if (season == Season.Autumn) return (int)(date - new DateTime(date.Year, 9, 1)).TotalDays;
else return (int)(date - new DateTime(date.Year, 12, 1)).TotalDays;
}
}