Comments (5)
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.
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.
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.
from convertdate.
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)
- install fails with pytz 2020.1 HOT 4
- Confusing example in README HOT 1
- hebrew.to_jd() results differ between Python2 and Python3 HOT 3
- Some US Federal holidays are incorrect and/or incomplete. HOT 1
- Incorrect conversion in Bahá'í calendar for Ayyám-i-Há
- Ordinal is wrong for December 31st HOT 2
- Hebrew Calendar should include method to return date where Tishrei is 1 HOT 7
- hebrew.to_jd_gregorianyear(...) cannot unpack non-iterable float object HOT 5
- Julian Date converstion wrong for astronomical years less than -4716 HOT 2
- Islamic Julian Day conversion incorrect for julian day < 1948085.5 HOT 2
- indian_civil.from_gregorian() wrong for gregorian dates before November 25th, 4714 BCE HOT 1
- julian.leap() always truthy for BC years HOT 1
- Human Era support HOT 1
- Add Buddhist Calendar support HOT 1
- Add Babylonian Calendar support HOT 1
- Migrate CI to github workflows
- LGPL-3.0 dependency HOT 1
- Possibly incorrect results for hebrew calendar if years are small HOT 1
- hebrew.monthcalendar returns a 6-day week HOT 1
- Hijri year before year 1 is year -1 not 0.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from convertdate.