🛠️ToolsShed

Season Calculator

Find the current meteorological season for any date and hemisphere.

❄️

Winter

12, 1, 2

🌸

Spring

3, 4, 5

☀️

Summer

6, 7, 8

🍂

Autumn

9, 10, 11

Frequently Asked Questions

Code Implementation

from datetime import date

def get_meteorological_season(month: int, hemisphere: str = "northern") -> str:
    """Get meteorological season for a given month."""
    northern = {
        12: "Winter", 1: "Winter", 2: "Winter",
        3: "Spring", 4: "Spring", 5: "Spring",
        6: "Summer", 7: "Summer", 8: "Summer",
        9: "Autumn", 10: "Autumn", 11: "Autumn",
    }
    southern = {
        12: "Summer", 1: "Summer", 2: "Summer",
        3: "Autumn", 4: "Autumn", 5: "Autumn",
        6: "Winter", 7: "Winter", 8: "Winter",
        9: "Spring", 10: "Spring", 11: "Spring",
    }
    if hemisphere.lower() == "southern":
        return southern[month]
    return northern[month]

def season_dates(month: int, year: int, hemisphere: str = "northern") -> dict:
    """Get season start/end dates for the given month."""
    season = get_meteorological_season(month, hemisphere)
    if hemisphere.lower() == "southern":
        starts = {"Summer": 12, "Autumn": 3, "Winter": 6, "Spring": 9}
    else:
        starts = {"Spring": 3, "Summer": 6, "Autumn": 9, "Winter": 12}

    start_month = starts[season]
    start_year = year if start_month <= month else year - 1
    start = date(start_year, start_month, 1)
    end_month = (start_month + 2) % 12 + 1
    end_year = start_year + (1 if start_month + 2 > 12 else 0)
    import calendar
    end_day = calendar.monthrange(end_year, end_month)[1]
    end = date(end_year, end_month, end_day)
    return {"season": season, "start": start.isoformat(), "end": end.isoformat()}

today = date.today()
info = season_dates(today.month, today.year)
print(f"Season: {info['season']} ({info['start']} to {info['end']})")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.