<div dir="ltr"><div>Dear Mr Egli,</div><div><br></div><div>online I found your Python code for Islamic & Gregorian Dates</div><div>(<a href="https://mail.python.org/pipermail/db-sig/1997-December/000361.html">https://mail.python.org/pipermail/db-sig/1997-December/000361.html</a>) and wondered whether you might help me:<br></div><div><br></div><div>I have python script (see below) that to translate Hijri Dates to Gregorian Date and vice versa. But the days might be off for about 1 day.</div><div>eg </div><div>gregorian date: 31/01/2013 is translated into</div><div>Hirji date: 19-03-1434</div><div>instead of the correct 20-03-2013.</div><div><br></div><div>My guess: there is a problem with leap years and last days of month and/or leap years.</div><div>Python knowledge is not good enough to correct the code implement your suggestions.</div><div>Would you kindly help me? Any tiny advice will be helpful!</div><div>What do I have to change (add) to get the correct result?</div><div><br></div><div>Thanks for any effort!</div><div><br></div><div>All the best, </div><div>Lucie Krennwallner</div><div><br></div><div><br></div><div>Python Script modified from <a href="http://gersham-xbmc-repo.googlecode.com/svn/trunk/addons/script.islamic.prayer.times/resources/lib/Hijri.py">http://gersham-xbmc-repo.googlecode.com/svn/trunk/addons/script.islamic.prayer.times/resources/lib/Hijri.py</a></div><div><br></div><div><br></div><div>1) GREGORIAN DATE CONVERTED TO HIJRI DATES</div><div><br></div><div><div>import math</div><div><br></div><div>def intPart(floatNum):</div><div>    if floatNum < -0.0000001: return math.ceil(floatNum - 0.0000001)</div><div>    return math.floor(floatNum + 0.0000001)</div><div><br></div><div><br></div><div>def Gregorian2Hijri(yr, mth, day):</div><div><br></div><div>        jd1 = intPart((1461 * (yr + 4800 + intPart((mth - 14) / 12.0))) / 4)</div><div>        jd2 = intPart((367 * (mth - 2 - 12 *  (intPart((mth - 14) / 12.0)))) / 12)</div><div>        jd3 = intPart((3 * (intPart((yr + 4900 + intPart((mth - 14) / 12.0)) / 100))) / 4)</div><div>        jd = jd1 + jd2 - jd3 + day - 32075</div><div><br></div><div>        l = jd - 1948440 + 10632</div><div>        n = intPart((l - 1) /10631.0)</div><div>        l = l - 10631 * n + 354</div><div><br></div><div>        j1 = (intPart((10985 - l) / 5316.0)) * (intPart((50 * l) / 17719.0))</div><div>        j2 = (intPart(l / 5670.0)) * (intPart((43 * l) / 15238.0))</div><div>        j = j1 + j2</div><div><br></div><div>        l1 = (intPart((30 - j) / 15.0)) * (intPart((17719 * j) / 50.0))</div><div>        l2 = (intPart(j / 16.0)) * (intPart((15238 * j) / 43.0))</div><div>        l = l - l1 - l2 + 29</div><div><br></div><div><br></div><div>        m = intPart((24 * l) / 709.0)</div><div>        y = 30 * n + j - 30</div><div>        d = l - intPart((709 * m) / 24.0)</div><div>       </div><div><br></div><div><br></div><div>yr = int(raw_input("Gegorian year: "))</div><div>mth= int(raw_input("Gegorian month: "))</div><div>day = int(raw_input("Gegorian day: "))</div><div>hi = Gregorian2Hijri(yr, mth, day)</div><div><br></div><div>print hi</div></div><div><br></div><div>2) HIJRI DATE CONVERTED TO GREGORIAN DATES</div><div><br></div><div><div>import math</div><div><br></div><div>def intPart(floatNum):</div><div>    if floatNum < -0.0000001: return math.ceil(floatNum - 0.0000001)</div><div>    return math.floor(floatNum + 0.0000001)</div><div><br></div><div>def Hijri2Gregorian(yr, mth, day):</div><div>    jd1 = intPart((11 * yr + 3) / 30.0)</div><div>    jd2 = intPart((mth - 1) / 2.0)</div><div>    jd = jd1 + 354 * yr + 30 * mth - jd2 + day + 1948440 - 385</div><div><br></div><div><br></div><div>    l = jd + 68569</div><div>    n = intPart((4 * l) / 146097.0)</div><div>    l = l - intPart((146097 * n + 3) / 4.0)</div><div>    i = intPart((4000 * (l + 1)) / 1461001.0)</div><div>    l = l - intPart((1461 * i) / 4.0) + 31</div><div>    j = intPart((80 * l) / 2447.0)</div><div>    d = l - intPart((2447 * j) / 80.0)</div><div>    l = intPart(j / 11.0)</div><div>    m = j + 2 - 12 * l</div><div>    y = 100 * (n - 49) + i + l</div><div>    return y, m, d<br></div><div><br></div><div>yr = int(raw_input("Provide year, like 1395: "))</div><div>mth = int(raw_input("Provide year, like 07: "))</div><div>day = int(raw_input("Provide year, like 12: "))</div><div><br></div><div>inp =Hijri2Gregorian(yr, mth, day)</div><div>print inp</div></div><div><br></div><div><br></div><div class="gmail_signature"><div dir="ltr"><span style="color:rgb(0,0,0);font-family:Times;font-size:medium"> </span><span style="color:rgb(0,0,0);font-family:Times;font-size:medium"></span><table cellpadding="0" style="font-family:Times;border-top-width:1px;border-top-style:dotted;border-top-color:rgb(204,204,204);border-bottom-width:1px;border-bottom-style:dotted;border-bottom-color:rgb(204,204,204)"><tbody><tr><td><span style="font-family:Arial,Helvetica,sans-serif;font-size:10pt;font-weight:bold;color:rgb(27,27,27)">Lucie Krennwallner</span><span style="font-family:Arial,Helvetica,sans-serif;font-size:10pt;color:rgb(102,102,102)"> | BI Consultant</span><br><span style="font-family:Arial,Helvetica,sans-serif;font-size:9pt;font-weight:bold;line-height:14pt;color:rgb(207,155,57)">t: </span><span style="font-family:Arial,Helvetica,sans-serif;font-size:9pt;color:rgb(102,102,102)">+44 (0)1202 373333 |</span> <span style="font-family:Arial,Helvetica,sans-serif;font-size:9pt;font-weight:bold;line-height:14pt;color:rgb(207,155,57)">m: </span><span style="font-family:Arial,Helvetica,sans-serif;font-size:9pt;color:rgb(102,102,102)">+49 (0)176 328 324 62</span><br><span style="font-family:Arial,Helvetica,sans-serif;font-size:10pt;line-height:16pt;color:rgb(102,102,102)"><a alt="InterWorks Careers" title="InterWorks Careers" href="http://interworks.co.uk/careers/" target="_blank">We're Hiring!</a> | <a alt="InterWorks Support" title="InterWorks Support" href="http://support.interworks.co.uk/" target="_blank">Support</a> | <a alt="InterWorks Blog" title="InterWorks Blog" href="http://interworks.co.uk/blog/" target="_blank">Blog</a> | <a alt="InterWorks LinkedIn" title="InterWorks LinkedIn" href="http://www.linkedin.com/company/interworks-uk" target="_blank">LinkedIn</a> | <a alt="InterWorks Facebook" title="InterWorks Facebook" href="https://www.facebook.com/interworks" target="_blank">Facebook</a></span></td><td align="right"><a alt="InterWorks Europe" title="InterWorks Europe" href="http://interworks.co.uk/" target="_blank"><img alt="InterWorks Europe" title="InterWorks Europe" src="http://trusted.interworks.co.uk/email/interworks-logo+gp.jpg"></a></td></tr><tr><td><span style="font-family:Arial,Helvetica,sans-serif;font-size:7.5pt;line-height:10pt;color:rgb(138,138,138)">Unit 1, Christchurch Business Park, Dorset, BH23 4FL</span></td><td align="right"><span style="font-family:Arial,Helvetica,sans-serif;font-size:7.5pt;color:rgb(138,138,138)">Co Reg No 08368863 | VAT 154881290</span></td></tr></tbody></table></div></div>
</div>