B4A Library Hijri Converter (Gregorian to Hijri and vice versa)

Hello everyone

Here is a small library to convert Gregorian date to Hijri (Islamic) calendar and vice versa.

The result is a list of day,month,year,name of month

Please note that this library does some calculations to convert to Hijri and vice versa so results can differ from real date (Usually one day earlier or one day later )



HijriConverter
Author:
SMM
Version: 0.01
  • HijriConverter
    Methods:
    • GregorianToHijri (Year As Int, Month As Int, Day As Int) As List
      Returns Hijri date as a list
      (day,month,year,nameofmonth)
      Note:
      This library just does some calculation that sometimes differ from real moon-related calendar
    • HijriToGregorian (Year As String, Month As String, Day As Int) As List
    • TodayGregorianToHijri As List
      Quick way for getting today's Hijri date
 

Attachments

  • HijriConverter.zip
    4.5 KB · Views: 623

Beja

Expert
Licensed User
Longtime User
somed3v3loper
Salam and Ramadan Mubarak
Thanks so much.. will try it in a dual Gregorian/Hijri calendar project.

I assume you already provided for the year 650 AD
 

ArminKH

Well-Known Member
thank u i will test it tonight
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
somed3v3loper
Salam and Ramadan Mubarak
Thanks so much.. will try it in a dual Gregorian/Hijri calendar project.

I assume you already provided for the year 650 AD

I don't think I understand your point regarding 650 AD .
Please check and tell us .

If the Gregorian date is prior to the start of Hijri , it will return negative value .
 

rad

Member
Licensed User
Longtime User
Assalamualaikum, can anyone give me an example how to use this library....
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Assalamualaikum, can anyone give me an example how to use this library....
Waalaikum Assalam
B4X:
    Dim hijri As List=HijriConverter.GregorianToHijri(2016,03,23 )
   
    Log("Day is: "&hijri.Get(0))
    Log("Month is: "&hijri.Get(1))
    Log("Year is: "&hijri.Get(2))
    Log("Name of month is : "&hijri.Get(3))
 

rad

Member
Licensed User
Longtime User
Hi somed3v3loper, thanks for your quick response

I have trying your given example above, but I dont know how, my application automatically quit without any alert message.
This is my script:
Dim hijri As List=HijriConverter.GregorianToHijri(2016,03,23 )
lblHijri.Text= hijri.Get(0) & "/" & hijri.Get(1) & "/" & hijri.Get(2) & ", " & hijri.Get(3)

Notes: I just a beginner...
 

rad

Member
Licensed User
Longtime User
Waalaikum Assalam
B4X:
    Dim hijri As List=HijriConverter.GregorianToHijri(2016,03,23 )
  
    Log("Day is: "&hijri.Get(0))
    Log("Month is: "&hijri.Get(1))
    Log("Year is: "&hijri.Get(2))
    Log("Name of month is : "&hijri.Get(3))

Hi somed3v3loper, thanks for your quick response

I have trying your given example above, but I dont know how, my application automatically quit without any alert message.
This is my script:
Dim hijri As List=HijriConverter.GregorianToHijri(2016,03,23 )
lblHijri.Text= hijri.Get(0) & "/" & hijri.Get(1) & "/" & hijri.Get(2) & ", " & hijri.Get(3)

Notes: I just a beginner...
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hi somed3v3loper, thanks for your quick response

I have trying your given example above, but I dont know how, my application automatically quit without any alert message.
This is my script:
Dim hijri As List=HijriConverter.GregorianToHijri(2016,03,23 )
lblHijri.Text= hijri.Get(0) & "/" & hijri.Get(1) & "/" & hijri.Get(2) & ", " & hijri.Get(3)

Notes: I just a beginner...
I got this when logging hijri.Get(0) & "/" & hijri.Get(1) & "/" & hijri.Get(2) & ", " & hijri.Get(3)
13/6/1437, Jumādá al-Ākhira

Do you have DateUtils library ?
 

rad

Member
Licensed User
Longtime User
I use B4A V.3.8, and the result as a I said before...
And then I purchare B4A V.5.8 and your Library is running well...

Thanks you so much for the library and your support for me as a beginner...;)
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I use B4A V.3.8, and the result as a I said before...
And then I purchare B4A V.5.8 and your Library is running well...

Thanks you so much for the library and your support for me as a beginner...;)
You are welcome I am still a beginner :)
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
HI @somed3v3loper if possible, could you make this same library for B4j? it seems that this library is dependent on DateUtils but in B4J we have JDateUtils.
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
HI @somed3v3loper if possible, could you make this same library for B4j? it seems that this library is dependent on DateUtils but in B4J we have JDateUtils.
Is it work

I lost the source code but found this here and modified it to fit B4X

B4X:
Sub HijriToGregorian( Y As Int,M As Int,D As Int) As Long
    Dim jd As Long
    Dim I As Long
    Dim N As Long
    Dim J As Long
    Dim K As Long
    Dim H As Long

    jd = Fix((11 * Y + 3) / 30) + 354 * Y + 30 * M - Fix((M - 1) / 2) + D + 1948440 - 385
    If jd > 2299160 Then
        I = jd + 68569
        N = Fix((4 * I) / 146097)
        I = I - Fix((146097 * N + 3) / 4)
        H = Fix((4000 * (I + 1)) / 1461001)
        I = I - Fix((1461 * H) / 4) + 31
        J = Fix((80 * I) / 2447)
        D = I - Fix((2447 * J) / 80)
        I = Fix(J / 11)
        M = J + 2 - 12 * I
        Y = 100 * (N - 49) + H + I
    Else
        J = jd + 1402
        K = Fix((J - 1) / 1461)
        I = J - 1461 * K
        N = Fix((I - 1) / 365) - Fix(I / 1461)
        H = I - 365 * N + 30
        J = Fix((80 * H) / 2447)
        D = H - Fix((2447 * J) / 80)
        H = Fix(J / 11)
        M = J + 2 - 12 * H
        Y = 4 * K + N + H - 4716
    End If
    DateTime.DateFormat="dd/MM/yyyy"
    Return DateTime.DateParse(D&"/"&M&"/"&Y)
End Sub
Sub GregorianToHijri(TheDate As Long) As List
    Dim jd As Long
    Dim I As Long
    Dim N As Long
    Dim J As Long
   

    Dim D As Long
    Dim M As Long
    Dim Y As Long

    D = DateTime.GetDayOfMonth( TheDate)
    M = DateTime.getMonth(TheDate)
    Y = DateTime.GetYear(TheDate)
    If ((Y > 1582) Or ((Y = 1582) And (M > 10)) Or ((Y = 1582) And (M = 10) And (D > 14))) Then
        jd = Fix((1461 * (Y + 4800 + Fix((M - 14) / 12))) / 4) + Fix((367 * (M - 2 - 12 * (Fix((M - 14) / 12)))) / 12) - Fix((3 * (Fix((Y + 4900 + Fix((M - 14) / 12)) / 100))) / 4) + D - 32075
    Else
        jd = 367 * Y - Fix((7 * (Y + 5001 + Fix((M - 9) / 7))) / 4) + Fix((275 * M) / 9) + D + 1729777
    End If
    I = jd - 1948440 + 10632
    N = Fix((I - 1) / 10631)
    I = I - 10631 * N + 354
    J = (Fix((10985 - I) / 5316)) * (Fix((50 * I) / 17719)) + (Fix(I / 5670)) * (Fix((43 * I) / 15238))
    I = I - (Fix((30 - J) / 15)) * (Fix((17719 * J) / 50)) - (Fix(J / 16)) * (Fix((15238 * J) / 43)) + 29
    M = Fix((24 * I) / 709)
    D = I - Fix((709 * M) / 24)
    Y = 30 * N + J - 30
    Return Array (Y,M,D)
End Sub
Sub Fix(arg As Int) As Int
    Return Ceil(arg )
End Sub
 
Last edited:
Top