############################################################
#
#use constant IslamicEpoch => 227014
#
############################################################
IslamicEpoch = 227014
hijri_date = {'year':'', 'month':'', 'date':'','hmonth':''}
eng_date = {'year':'', 'month':'', 'date':'','emonth':''}
def get_hijri_month(m):
n_month = False
if m==1:
n_month = "Muharram"
if m==2:
n_month = "Safar"
if m==3:
n_month = "Rabi'ul Awal"
if m==4:
n_month = "Rabi'ul Akhir"
if m==5:
n_month = "Jamadil Awal"
if m==6:
n_month = "Jamadil Akhir"
if m==7:
n_month = "Rajab"
if m==8:
n_month = "Sha'ban"
if m==9:
n_month = "Ramadhan"
if m==10:
n_month = "Shawwal"
if m==11:
n_month = "Zul Qida"
if m==12:
n_month = "Zul Hijja"
return n_month
def get_english_month(m):
eMonth = False
if m==1:
eMonth = "January"
if m==2:
eMonth = "February"
if m==3:
eMonth = "March"
if m==4:
eMonth = "April"
if m==5:
eMonth = "May"
if m==6:
eMonth = "June"
if m==7:
eMonth = "July"
if m==8:
eMonth = "August"
if m==9:
eMonth = "September"
if m==10:
eMonth = "October"
if m==11:
eMonth = "November"
if m==12:
eMonth = "December"
return eMonth
def lastDayOfGregorianMonth(month, year):
# Compute the last date of the month for the Gregorian calendar.
res = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if (month == 2):
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
return 29
i = (month-1)
return res[i]
def Gregorian2Absolute(day, month, year):
# Computes the absolute date from the Gregorian date.
N = day # days this month
for m in range(1,month): # days in prior months this year
N = N + lastDayOfGregorianMonth(m, year)
return int(N # days this year
+ 365 * (year - 1) # days in previous years ignoring leap days
+ (year - 1) / 4 # Julian leap days before this year...
- (year - 1) / 100 # ...minus prior century years...
+ (year - 1) / 400) # ...plus prior years divisible by 400
def Absolute2Gregorian(d):
# Computes the Gregorian date from the absolute date.
# Search forward year by year from approximate year
year = int(d / 366 + 0.5)
while (d >= Gregorian2Absolute(1,1,year+1)):
year = year + 1
# Search forward month by month from January
month = 1
while (d >= Gregorian2Absolute(lastDayOfGregorianMonth(month, year), month, year)):
month = month + 1
day = d - Gregorian2Absolute(1, month, year)
# return [day, month, year]
eng_date["year"] = year
eng_date["month"] = month
eng_date["date"] = day
eng_date["emonth"] = get_english_month(month)
return eng_date
def IslamicLeapYear(year):
# True if year is an Islamic leap year
if ((((11 * year) + 14) % 30) < 11):
return 1
return 0
def lastDayOfIslamicMonth(month, year):
# Last day in month during year on the Islamic calendar.
if (month % 2 == 1) or (month == 12 and IslamicLeapYear(year)):
return 30
return 29
def Islamic2Absolute(day, month, year):
# Computes the absolute date from the Islamic date.
return int(day # days so far this month
+ 29 * (month - 1) # days so far...
+ int(month /2) # ...this year
+ 354 * (year - 1) # non-leap days in prior years
+ (3 + (11 * year)) / 30 # leap days in prior years
+ IslamicEpoch) # days before start of calendar
def Absolute2Islamic(d):
# Computes the Islamic date from the absolute date.
if (d <= IslamicEpoch):
# Date is pre-Islamic
month = 0
day = 0
year = 0
else:
# Search forward year by year from approximate year
year = int((d - IslamicEpoch) / 355)
while (d >= Islamic2Absolute(1,1,year+1)):
year = year + 1
# Search forward month by month from Muharram
month = 1
while (d > Islamic2Absolute(lastDayOfIslamicMonth(month,year), month, year)):
month = month + 1
day = d - Islamic2Absolute(0, month, year) +1
hijri_date["year"] = year
hijri_date["month"] = month
hijri_date["date"] = day
hijri_date["hmonth"] = get_hijri_month(month)
return hijri_date
print "in which you want to convert \n for eng to hijri 1\n for hijri to eng 2"
n = raw_input()
print "Enter Year"
yy = raw_input()
print "Enter Month"
mm = raw_input()
print "Enter date"
dd= raw_input()
if int(n) == 1:
date_n=Absolute2Islamic(Gregorian2Absolute(int(dd),int(mm),int(yy)))
print "nowwwwwwwww Hijri",date_n
if int(n) == 2:
date_n=Absolute2Gregorian(Islamic2Absolute(int(dd),int(mm),int(yy)))
print "nowwwwwwwww eng",date_n
No comments:
Post a Comment