Giter Club home page Giter Club logo

liturgical-dates's Introduction

Liturgical Dates

Just a collections of functions for calculating liturgical dates. The goal is not to be scientifically accurate, but to be accurate according to the Gregorian Calendar. The dates for the moon are rarely off by more than a day, and work with this margin of error until about the year 5200.

Function List

Convert an interger to roman numerals

Not a date, but a useful function for the correct output of the epact.

def interger_to_roman(num=int) -> int:
    romans = {
        1: "I", 5: "V", 10: "X", 50: "L", 100: "C",
        500: "D", 1000: "M", 5000: "G", 10000: "H",
    }
    div, result = 1, ''
    while num >= div:
        div *= 10
    div /= 10
    while num:
        last_num = int(num / div)
        if last_num <= 3:
            result += (romans[div]*last_num)
        elif last_num == 4:
            result += (romans[div]+romans[div*5])
        elif 5 <= last_num <= 8:
            result += (romans[div*5]+(romans[div]*(last_num-5)))
        elif last_num == 9:
            result += (romans[div]+romans[div*10])
        num = floor(num % div)
        div /= 10
    return result

Dominical Letter

def dominical(year=int) -> str:
    letter, y, c = '', int(str(year)[2:]), int(str(year)[:2])
    index = (y+(y/4)+5*(c % 4)-1) % 7
    letters = ['G', 'F', 'E', 'D', 'C', 'B', 'A']
    first_letter, second_letter = '', ''
    try:
        datetime(year, 2, 29)
        first_letter = letters[int(index)-1]
        if int(index) < 0:
            first_letter = letters[6]
        second_letter = letters[int(index)]
    except ValueError:
        second_letter = letters[int(index)]
    letter = first_letter+second_letter
    return letter

Golden Number

def golden_number(year=int) -> int:
    return (year+1) % 19

Epact (for the years 1600-5199)

This does not calculate the special 25th epact. This is being worked on.

def epact_adjust(year=int) -> int:
    l, s, c = 0, 0, int(str(year)[:2])
    if c % 2:
        l = -1
    if not (c-2) % 4:
        l = -1
    if not c % 3:
        if not (c-17) % 25:
            s = 0
        else:
            s = 1
    if not (c-18) % 25:
        s = 1
    return l + s


def epact_build(adjust=int) -> list:
    build_base, day, x = [], 1, 0
    while x != 19:
        day += 11*(x if x == 0 else 1)
        if day > 30:
            day -= 30
        build_base.append(day)
        x += 1
    build = []
    for y in build_base:
        y += adjust
        if y > 31:
            y -= 31
        elif y <= 0:
            y += 31
        build.append(y)
    return build


def epact(year=int) -> str:
    e, base, i = '', 1600, 0
    while year >= base:
        i += epact_adjust(year)
        year -= 100
    epact_list = epact_build(i)
    e = interger_to_roman(epact_list[golden_number(year)-1])
    if e == 'XXXI':
        e = '*'
    return e

Letter of the Martyrology

Still working on this one.

liturgical-dates's People

Contributors

corei8 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.