uprav tento skript tak, aby se nevyplnovala data pro gregoriansky kalendar pred rokem 1583


Julian reckoning		Julian calendar date		Gregorian calendar date
Easter Full Moon (luna XIV)	25 3 (JD 1867242)		--
Easter Sunday			1 4 (JD 1867249)		--



puvodni skript



import math

def gmod(m, n):
    """Generalized modulo function to handle negative numbers."""
    return ((m % n) + n) % n

def addspace(x):
    """Adds a leading space to single-digit numbers for alignment."""
    return f" {x}" if x < 10 else f"{x}"

def yeartype(year, cal='j'):
    """
    Determines if the year is a leap year based on the calendar.
    cal='j' for Julian, 'g' for Gregorian.
    """
    yt = 0
    if gmod(year, 4) == 0:
        yt = 1
    if cal == 'g':
        if gmod(year, 100) == 0:
            yt = 0
        if gmod(year, 400) == 0:
            yt = 1
    return yt

# Arrays as per the source code
domletname = ["G","F","E","D","C","B","A","AG","GF","FE","ED","DC","CB","BA"]
epactname = ["*(XXX)","I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII","XIII",
            "XIV","XV","XVI","XVII","XVIII","XIX","XX","XXI","XXII","XXIII","XXIV","XXV",
            "XXVI","XXVII","XXVIII","XXIX"]
martyrj = ["a","b","c","d","e","f","g","h","i","k","l","m","n","p","q","r","s","t","u"]
martyrg = ["a","b","c","d","e","f","g","h","i","k","l","m","n","p","q","r","s","t","u",
           "A","B","C","D","E","F","G","H","M","N","P"]
monthname = ["January","February","March","April","May","June","July","August","September",
            "October","November","December"]
wdname = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
yearlength = ["common","bissextile"]

def calculate_jd(year, month, day, calendar='g'):
    """Calculate the Julian Day Number for the given date."""
    if month <= 2:
        year -=1
        month +=12
    A = math.floor(year / 100)
    if calendar == 'g':
        B = 2 - A + math.floor(A /4)
    else:
        B =0
    JD = math.floor(365.25*(year + 4716)) + math.floor(30.6001*(month +1)) + day + B -1524.5
    JD_int = int(math.floor(JD + 0.5))
    return JD_int

def jul_easter(year, emod):
    """Calculates Julian Easter Sunday date."""
    a = gmod(year, 19)
    gn = a + 1  # Golden Number
    b = gmod(year, 4)
    c = gmod(year, 7)
    d = gmod((19 * a + 15), 30)
    if emod == 1 and gn == 1:
        d += 1
    e = gmod((2 * b + 4 * c - d + 6), 7)
    fmj = 113 + d  # Easter full moon [days after -92 March]
    dmj = fmj + e + 1  # Easter Sunday [days after -92 March]
    fmmj = math.floor(fmj / 31)
    fmdj = gmod(fmj, 31) + 1
    esmj = math.floor(dmj / 31)
    esdj = gmod(dmj, 31) + 1
    sc = gmod((year + 8), 28) + 1  # Number in Solar Cycle
    s = gmod((4 + math.floor(5 * year / 4)), 7)
    dl_index = s + 7 * yeartype(year, 'j')
    dl = domletname[dl_index] if dl_index < len(domletname) else "Unknown"
    return [dmj, esdj, esmj, fmj, fmdj, fmmj, gn, sc, dl]

def greg_easter(year):
    """Calculates Gregorian Easter Sunday date."""
    a = gmod(year, 19)
    gn = a + 1  # Golden Number
    b = math.floor(year / 100)
    c = gmod(year, 100)
    d = math.floor(b / 4)
    e = gmod(b, 4)
    f = math.floor((b + 8) / 25)
    g = math.floor((b - f + 1) / 3)
    h = gmod((19 * a + b - d - g + 15), 30)
    i = math.floor(c / 4)
    k = gmod(c, 4)
    l = gmod((2 * e + 2 * i - h - k + 4), 7)
    m = math.floor((a + 11 * h + 22 * l) / 451)
    ep = gmod((11 * a + 8 - b + d + math.floor((8 * b + 13) / 25)), 30)
    if ep <= 23:
        fmg = 136 - ep
    elif ep in [24, 25]:
        fmg = 141
    if ep == 25 and gn > 11:
        fmg = 140
    if ep >= 26:
        fmg = 166 - ep
    dmg = 114 + h - 7 * m + l  # Easter Sunday [days after -92 March]
    fmmg = math.floor(fmg / 31)
    fmdg = gmod(fmg, 31) + 1
    esmg = math.floor(dmg / 31)
    esdg = gmod(dmg, 31) + 1
    sc = gmod((year + 8), 28) + 1  # Number in Solar Cycle
    s = gmod((6 + math.floor(5 * year / 4) - math.floor(year / 100) + math.floor(year / 400)), 7)
    dl_index = s + 7 * yeartype(year, 'g')
    dl = domletname[dl_index] if dl_index < len(domletname) else "Unknown"
    return [dmg, esdg, esmg, fmg, fmdg, fmmg, gn, ep, sc, dl]

def easter_passover(year, prol=0, emod=1):
    """
    Calculates all Easter and Passover related data for a given year.
    
    Parameters:
    - year: The year to calculate.
    - prol: Show Gregorian dates before 1583 (0 for No, 1 for Yes).
    - emod: Julian Easter mode (1 for Dionysian, 2 for Armenian/Non-Chalcedonian).
    
    Returns:
    A dictionary containing all relevant fields.
    """
    # Calculate Julian Easter
    j_easter = jul_easter(year, emod)
    # Calculate Gregorian Easter
    g_easter = greg_easter(year)

    # Calculate offset between Julian and Gregorian calendar
    diff_jg = math.floor(year / 100) - math.floor(year / 400) - 2

    # Julian reckoning dates
    j_full_moon_day = j_easter[4]
    j_full_moon_month = j_easter[5]
    j_full_moon_jd = calculate_jd(year, j_full_moon_month, j_full_moon_day, 'j')

    j_sunday_day = j_easter[1]
    j_sunday_month = j_easter[2]
    j_sunday_jd = calculate_jd(year, j_sunday_month, j_sunday_day, 'j')

    # Gregorian reckoning dates (shifted Julian dates)
    fmjg = j_easter[3] + diff_jg
    fmmjg = math.floor((fmjg -62)/30.6)
    fmdjg = math.floor(fmjg -62 -30.6 * fmmjg) +1
    fmmjg +=2

    greg_rec_full_moon_day = fmdjg
    greg_rec_full_moon_month = fmmjg
    greg_rec_full_moon_jd = calculate_jd(year, greg_rec_full_moon_month, greg_rec_full_moon_day, 'g')

    dmjg = j_easter[0] + diff_jg
    mjg = math.floor((dmjg -62)/30.6)
    djg_day = math.floor(dmjg -62 -30.6 * mjg) +1
    mjg +=2

    greg_rec_sunday_day = djg_day
    greg_rec_sunday_month = mjg
    greg_rec_sunday_jd = calculate_jd(year, greg_rec_sunday_month, greg_rec_sunday_day, 'g')

    # Gregorian calendar date (standard Gregorian Easter)
    g_full_moon_day = g_easter[4]
    g_full_moon_month = g_easter[5]
    g_full_moon_jd = calculate_jd(year, g_full_moon_month, g_full_moon_day, 'g')

    g_sunday_day = g_easter[1]
    g_sunday_month = g_easter[2]
    g_sunday_jd = calculate_jd(year, g_sunday_month, g_sunday_day, 'g')

    # Solar Cycle and Dominical Letters
    sc = j_easter[7]
    dl_j = j_easter[8]
    dl_g = g_easter[9] if (prol ==1 or year >= 1583) else "--"

    # Golden Number and Epact
    gn = j_easter[6]
    ep = g_easter[7]

    # Martyrology letters
    litmartyrj = martyrj[gn -1] if 1 <= gn <= len(martyrj) else "--"
    litmartyrg = martyrg[ep -1] if 1 <= ep <= len(martyrg) else "--"

    # Epact handling
    if prol ==0 and year < 1582:
        epact = "--"
    else:
        if ep < len(epactname):
            epact = epactname[ep]
        else:
            epact = f"Unknown({ep})"
        if ep ==25 and gn >11:
            epact = "25"

    # Offset between Julian and Gregorian calendar
    offset_j_g = diff_jg if not (prol ==0 and year <1582) else "--"

    # deljg: From Gregorian until Julian Easter Sunday
    # deljg = Julian Easter Sunday JD - Gregorian Easter Sunday JD
    deljg = (j_sunday_jd - g_sunday_jd) if not (prol ==0 and year <=1582) else "--"

    # Passover calculation
    a = gmod((12 * year + 12), 19)
    b = gmod(year, 4)
    s = (5 * (1979335 - 313 * year) + (765433 * a)) / 492480 + b /4
    q = math.floor(s)
    r = s - q
    c_calc = gmod((q + 3 * year +5 * b +1),7)
    dmh = q + diff_jg + 92
    p =0
    if c_calc in [2,4,6]:
        p =1
    if c_calc ==1 and a >6 and r >1366/2160:
        p =2
    if c_calc ==0 and a >11 and r >23268/25920:
        p =1
    dmh += p

    ddhj = j_sunday_jd - dmh  # From Passover until Julian Easter Sunday
    delhj = ddhj

    ddhg = g_sunday_jd - dmh  # From Passover until Gregorian Easter Sunday
    delhg = ddhg if not (prol ==0 and year <=1582) else "--"

    if year <=1582:
        dmh = dmh - diff_jg

    mh = math.floor((dmh -62)/30.6)
    dh = math.floor(dmh -62 -30.6 * mh) +1
    mh +=2

    # Weekday Passover
    wh = gmod(c_calc + p +5,7)
    wd_passover = wdname[wh] if 0 <= wh < len(wdname) else "--"

    # Passover Day and Month
    passover_day = addspace(dh) if isinstance(dh, int) else "--"
    passover_month = monthname[mh -1] if isinstance(mh, int) and 1 <= mh <=12 else "--"

    # Amundi
    amundi = year + 3760

    # Passover Feast Date and JD
    passover_label = f"15 Nisan {amundi} AM"
    passover_jd = calculate_jd(year, mh, dh, 'g') if (prol ==1 or year >= 1583) else calculate_jd(year, mh, dh, 'j')

    # Handle 'litmartyrg' when ep ==0
    if ep ==0 and len(martyrg) >29:
        litmartyrg = martyrg[29]
    elif 1 <= ep <= len(martyrg):
        litmartyrg = martyrg[ep -1]
    else:
        litmartyrg = "--"

    # Prepare record
    record = {
        "Year": str(year),
        "Offset between Julian and Gregorian calendar": f"{offset_j_g} days",
        "Number in Solar Cycle": str(sc),
        "Dominical Letter - Julian reckoning": dl_j,
        "Dominical Letter - Gregorian reckoning": dl_g,
        "Lunar age parameters - Golden Number": str(gn),
        "Lunar age parameters - Gregorian Epact": epact,
        "Martyrology letters - Julian reckoning": litmartyrj,
        "Martyrology letters - Gregorian reckoning": litmartyrg,
        "Julian reckoning": {
            "Easter Full Moon (luna XIV)": f"{j_full_moon_day} {j_full_moon_month} (JD {j_full_moon_jd})",
            "Easter Sunday": f"{j_sunday_day} {j_sunday_month} (JD {j_sunday_jd})"
        },
        "Gregorian reckoning": {
            "Easter Full Moon (luna XIV)": f"{greg_rec_full_moon_day} {greg_rec_full_moon_month} (JD {greg_rec_full_moon_jd})",
            "Easter Sunday": f"{greg_rec_sunday_day} {greg_rec_sunday_month} (JD {greg_rec_sunday_jd})"
        },
        "Gregorian calendar date": {
            "Easter Full Moon (luna XIV)": f"{g_full_moon_day} {g_full_moon_month} (JD {g_full_moon_jd})",
            "Easter Sunday": f"{g_sunday_day} {g_sunday_month} (JD {g_sunday_jd})"
        },
        "Jewish Passover Feast": f"{passover_label}    {wd_passover} {passover_day} {passover_month} (JD {passover_jd})",
        "From Gregorian until Julian Easter Sunday": f"{deljg} days",
        "From Passover until Gregorian Easter Sunday": f"{delhg} days",
        "From Passover until Julian Easter Sunday": f"{delhj} days"
    }

    return record

def main():
    # Settings
    prol = 0  # Show Gregorian dates before 1583 - No
    emod = 1  # Julian Easter mode - Dionysian

    # Open the output file
    with open("calculator_easter_data.txt", "w", encoding="utf-8") as f:
        # Iterate through years
        for year in range(400, 6001):
            # Calculate data using easter_passover function
            record = easter_passover(year, prol, emod)

            # Write function name
            f.write("easter_passover\n")

            # Write Year
            f.write(f"Year: {record['Year']}\n\n")

            # Write Offset between Julian and Gregorian calendar
            f.write(f"Offset between Julian and Gregorian calendar: {record['Offset between Julian and Gregorian calendar']}\n\n")

            # Write Number in Solar Cycle and Dominical Letters
            f.write(f"Number in Solar Cycle: {record['Number in Solar Cycle']}\n")
            f.write(f"Dominical Letter - Julian reckoning: {record['Dominical Letter - Julian reckoning']}  Dominical Letter - Gregorian reckoning: {record['Dominical Letter - Gregorian reckoning']}\n\n")

            # Write Lunar age parameters and Epact
            f.write(f"Lunar age parameters - Golden Number: {record['Lunar age parameters - Golden Number']}  Gregorian Epact: {record['Lunar age parameters - Gregorian Epact']}\n\n")

            # Write Martyrology letters
            f.write(f"Martyrology letters - Julian reckoning: {record['Martyrology letters - Julian reckoning']}  Martyrology letters - Gregorian reckoning: {record['Martyrology letters - Gregorian reckoning']}\n\n")

            # Write Julian reckoning dates
            f.write("Julian reckoning\t\tJulian calendar date\t\t\tGregorian calendar date\n")
            f.write(f"Easter Full Moon (luna XIV)\t{record['Julian reckoning']['Easter Full Moon (luna XIV)']}\t\t{record['Gregorian reckoning']['Easter Full Moon (luna XIV)']}\n")
            f.write(f"Easter Sunday\t\t\t{record['Julian reckoning']['Easter Sunday']}\t\t{record['Gregorian reckoning']['Easter Sunday']}\n\n")

            # Write Gregorian reckoning dates
            f.write("Gregorian reckoning\t\tGregorian calendar date\n")
            f.write(f"Easter Full Moon (luna XIV)\t{record['Gregorian calendar date']['Easter Full Moon (luna XIV)']}\n")
            f.write(f"Easter Sunday\t\t\t{record['Gregorian calendar date']['Easter Sunday']}\n\n")

            # Write Jewish Passover Feast
            f.write(f"Jewish Passover Feast\t{record['Jewish Passover Feast']}\n\n")

            # Write deljg, delhg, delhj
            f.write(f"From Gregorian until Julian Easter Sunday {record['From Gregorian until Julian Easter Sunday']}\n")
            f.write(f"From Passover until Gregorian Easter Sunday {record['From Passover until Gregorian Easter Sunday']}\n")
            f.write(f"From Passover until Julian Easter Sunday {record['From Passover until Julian Easter Sunday']}\n\n")

            # Add separator
            f.write("-" * 80 + "\n\n")

            # Optional: Print progress every 1000 years
            if year % 1000 == 0:
                print(f"Processed year: {year}")

    print("Easter data calculation completed. Check 'calculator_easter_data.txt' for results.")

if __name__ == "__main__":
    main()