GithubHelp home page GithubHelp logo

Comments (5)

snoopyjc avatar snoopyjc commented on August 16, 2024

Here is the code for Ramadan:

def ramadan(year):
    islamic_year = islamic.from_gregorian(year, 1, 1)[0]
    result = islamic.to_gregorian(islamic_year, 9, 1)
    if result[0] < year:
        result = islamic.to_gregorian(islamic_year+1, 9, 1)
    elif result[0] > year:
        result = islamic.to_gregorian(islamic_year-1, 9, 1)
    return date(*result)

from convertdate.

snoopyjc avatar snoopyjc commented on August 16, 2024

Here is the code for Chinese New Year:

from lunardate import LunarDate

_yot = ('Rat', 'Ox', 'Tiger', 'Rabbit', 'Dragon', 'Snake', 'Horse', 'Goat', 'Monkey', 'Rooster', 'Dog', 'Pig')

def year_of_the(year):
    yr = (year - 2020) % len(_yot)
    return _yot[yr]

def chinese_new_year(year):
    """Returns a tuple of the (date, year_of_the: str)"""
    return (LunarDate(year, 1, 1).toSolarDate(), year_of_the(year))

from convertdate.

fitnr avatar fitnr commented on August 16, 2024

Islamic holidays raise an issue because they can occur twice in a Gregorian year. Should the function return a list of date tuples, which isn't in line with the other functions, or return only one of the holidays, which is incomplete behavior?

from convertdate.

snoopyjc avatar snoopyjc commented on August 16, 2024

from convertdate.

uy-rrodriguez avatar uy-rrodriguez commented on August 16, 2024

Hi, have you got anywhere with this request? I think returning both Ramadan dates would be correct.
Based on @snoopyjc 's proposal, something like below.
The second condition was removed, given the Islamic calendar is strictly shorter than Gregorian, I don't think that can ever happen.

def ramadan(year):
    islamic_year = islamic.from_gregorian(year, 1, 1)[0]
    result_1 = islamic.to_gregorian(islamic_year, 9, 1)
    result_2 = islamic.to_gregorian(islamic_year + 1, 9, 1)

    # Ramadan falls towards the end of the Gregorian year
    if result_1[0] < year:
        return ( date(*result_2), )

    # Ramadan falls both at the beginning and end of the Gregorian year
    elif result_1[0] == result_2[0] and result_1 != result_2:
        return ( date(*result_1), date(*result_2) )

    return ( date(*result_1), )

Another option could be to return the "next" date for beginning of Ramadan.

def next_ramadan(year, month, day):
    islamic_date = islamic.from_gregorian(year, month, day)
    # Returns the given date if Islamic date is exactly the beginning of Ramadan
    if islamic_date[1] < 9 or islamic_date[1] == 9 and islamic_date[2] == 1:
        result = islamic.to_gregorian(islamic_date[0], 9, 1)
    else:
        result = islamic.to_gregorian(islamic_date[0] + 1, 9, 1)
    return date(*result)

from convertdate.

Related Issues (20)

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.