Z28601

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z28601"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z28600",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z610",
            "Z16K2": "def Z28600(Z28600K1, Z28600K2, Z28600K3):\n    \"\"\"\n    Convert Hijri (Islamic) date to Gregorian date with a\n    correction mechanism for Saudi Arabia (Umm al-Qura calendar).\n\n    Parameters:\n    Z28600K1 (int): The day of the Hijri month.\n    Z28600K2 (str): The Wikidata QID for the Hijri month (e.g., \"Q1952053\").\n    Z28600K3 (int): The Hijri year.\n\n    Returns:\n    Gregorian object: The corresponding Gregorian Date in \"DD Month YYYY\" format.\n    \"\"\"\n\n    # Assign inputs to descriptive variable names\n    hijri_day = Z28600K1\n    hijri_year = Z28600K3\n    hijri_month_qid = Z28600K2['Z26582K1']['Z6091K1']\n\n    # A mapping dictionary to convert Hijri month Wikidata QIDs to numbers (1-12).\n    qid_month_map = {\n        \"Q1952053\": 1,  # Muharram\n        \"Q489557\":  2,  # Safar\n        \"Q474167\":  3,  # Rabi' al-awwal\n        \"Q273815\":  4,  # Rabi' al-thani\n        \"Q852002\":  5,  # Jumada al-awwal\n        \"Q822218\":  6,  # Jumada al-thani\n        \"Q194210\":  7,  # Rajab\n        \"Q220914\":  8,  # Sha'ban\n        \"Q8867089\": 9,  # Ramadan\n        \"Q685440\":  10, # Shawwal\n        \"Q150853\":  11, # Dhu al-Qa'dah\n        \"Q186022\":  12  # Dhu al-Hijjah\n    }\n\n    # Convert the month QID to its numeric equivalent\n    hijri_month = qid_month_map.get(hijri_month_qid)\n    \n    if hijri_month is None:\n        raise ValueError(f\"Unknown or invalid Hijri month QID provided: {hijri_month_qid}\")\n\n    def days_since_hijri_epoch(year, month, day):\n        \"\"\"Calculates total days since 1/1/1 AH using an arithmetic approximation.\"\"\"\n        completed_years = year - 1\n        num_leap_years = (11 * completed_years + 14) // 30\n        month_days_cumulative = [0, 30, 59, 89, 118, 148, 177, 207, 236, 266, 295, 325]\n        total_days = (completed_years * 354 + num_leap_years + \n                      month_days_cumulative[month - 1] + day)\n        return total_days\n\n    # Correction Anchor: A known correct date pair for Saudi Arabia's Umm al-Qura calendar.\n    # 8 Rabi II 1447 AH corresponds to September 30, 2025 Gregorian.\n    anchor_hijri_year = 1447\n    anchor_hijri_month = 4\n    anchor_hijri_day = 8\n    anchor_gregorian_year = 2025\n    anchor_gregorian_month = 9\n    anchor_gregorian_day = 30\n\n    days_for_target = days_since_hijri_epoch(hijri_year, hijri_month, hijri_day)\n    days_for_anchor = days_since_hijri_epoch(anchor_hijri_year, anchor_hijri_month, anchor_hijri_day)\n    day_difference = days_for_target - days_for_anchor\n\n    # --- Gregorian Date Calculation from Anchor ---\n    def is_gregorian_leap(year):\n        return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)\n\n    def date_to_ordinal(year, month, day):\n        days_in_month = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n        if is_gregorian_leap(year):\n            days_in_month[2] = 29\n        return sum(days_in_month[:month]) + day\n\n    def ordinal_to_date(year, ordinal_day):\n        days_in_month = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n        if is_gregorian_leap(year):\n            days_in_month[2] = 29\n        month = 1\n        while ordinal_day \u003E days_in_month[month]:\n            ordinal_day -= days_in_month[month]\n            month += 1\n        return year, month, ordinal_day\n\n    total_days_anchor = 0\n    for y in range(1, anchor_gregorian_year):\n        total_days_anchor += 366 if is_gregorian_leap(y) else 365\n    total_days_anchor += date_to_ordinal(anchor_gregorian_year, anchor_gregorian_month, anchor_gregorian_day)\n    \n    total_days_target = total_days_anchor + day_difference\n    \n    target_year = 1\n    days_in_current_year = 366 if is_gregorian_leap(target_year) else 365\n    while total_days_target \u003E days_in_current_year:\n        total_days_target -= days_in_current_year\n        target_year += 1\n        days_in_current_year = 366 if is_gregorian_leap(target_year) else 365\n        \n    gregorian_year, gregorian_month, gregorian_day = ordinal_to_date(target_year, int(total_days_target))\n\n    # Return the Gregorian date formatted as a string \"YYYY-MM-DD\"\n    return {\n    \t\"K1\": gregorian_year,\n    \t\"K2\": gregorian_month,\n    \t\"K3\": gregorian_day\n    }"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1001",
                "Z11K2": "دالة تحويل التاريخ الهجري إلى الميلادي، بايثون"
            },
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "Converting Hijri Date to Gregorian Date, python"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11"
        ]
    }
}