Pythontr

husonet | Tarih: 28.01.2011

python miladi takvimi hicri takvime çevirme, bayram günlerini bulma, dini tatilleri bulma

Bu yazdığım kodla Miladi Takvimi Hicri Takvime cevirebilir ve Dini Bayram tatillerini bulabilirsiniz.

#!/usr/bin/python
#-*- coding:utf-8 -*-

import math
from datetime import datetime
import time

#--------------------------------------
#İnt Part fonksiyonu
#Kullanıcı adı: husonet
#Hüseyin Özdemir
#pythontr.com
#28.01.2011

#--------------------------------------
#Yuvarlama·
def intPart(sFloatNum):
if sFloatNum < -0.0000001:
return math.ceil(sFloatNum -0.0000001)
else:
return math.floor(sFloatNum +0.0000001)
#--------------------------------------
#String olarak Hicri ay getir
def ayBul(sAy):
vAy = sAy
vAyS = ""
if vAy == 1:
vAyS = 'Muharrem'
elif vAy == 2:
vAyS = 'Safer'
elif vAy == 3:
vAyS = 'Rebiü\'l- Evvel'
elif vAy == 4:
vAyS = 'Rebiü\'l- Ahir'
elif vAy == 5:
vAyS = 'Cemaziye\'l- Evvel'
elif vAy == 6:
vAyS = 'Cemaziye\'l- Ahir'
elif vAy == 7:
vAyS = 'Recep'
elif vAy == 8:
vAyS = 'Saban'
elif vAy == 9:
vAyS = 'Ramazan'
elif vAy == 10:
vAyS = 'Sevval'
elif vAy == 11:
vAyS = 'Zi\'l-ka\'de'
elif vAy == 12:
vAyS = 'Zi\'l-Hicce'
return vAyS

#--------------------------------------
#Çevirme Fonksiyonu
def miladiToHicri(sGun, sAy, sYil):
vAyStr = ''
vMesaj = ''
jd = intPart((1461*(sYil + 4800 + intPart((sAy-14)/ 12)))/ 4) + intPart((367*(sAy-2-12*(intPart((sAy-14)/ 12))))/ 12)-intPart((3*(intPart((sYil+4900+intPart((sAy-14)/ 12))/ 100)))/ 4)+sGun-32075
l = jd - 1948440 + 10632
n = intPart((l-1)/10631)
l = l - 10631 * n + 354;
j = (intPart((10985-l)/5316))*(intPart((50*l)/17719))+(intPart(l/5670))*(intPart((43*l)/15238))
l = l-(intPart((30-j)/15))*(intPart((17719*j)/50))-(intPart(j/16))*(intPart((15238*j)/43))+29
vAy = math.ceil(((intPart((24*l)/ 709))))
vGun = math.ceil(l-intPart((709*vAy)/ 24))
vYil = math.ceil(30* n + j -30)
vAyStr = ayBul(int(vAy))
if vAyStr == 'Sevval':
if vGun >= 1 and vGun <= 3:
vMesaj = 'Ramazan Bayramı Tatili !!!'
elif vAyStr == 'Zi''l-Hicce': #Örnek 21/01/2005 Tarihi Kurban Bayramı
if vGun >= 10 and vGun <= 13:
vMesaj = 'Kurban Bayramı Tatili !!!'
vReturn = """
Tarih: %02d %s %04d
Mesaj: %s
""" % (vGun, vAyStr, vYil, vMesaj)

#return str(vGun) + ' ' + vAyStr + ' ' + str(vYil) + ' ' + vMesaj
return vReturn

#--------------------------------------
#Örnek Deneme
print miladiToHicri(float(19),float(8),float(2012))