Jump to content

how to get the islamic date using autoit


Recommended Posts

  • Moderators

nacerbaaziz,

Here is my version of a javaScript algorithm that I found:

_KCal()

#cs
function kuwaiticalendar(adjust){
    var today = new Date();
    if(adjust) {
        adjustmili = 1000*60*60*24*adjust;
        todaymili = today.getTime()+adjustmili;
        today = new Date(todaymili);
    }

    day = today.getDate();
    month = today.getMonth();
    year = today.getFullYear();
    m = month+1;
    y = year;
    if(m<3) {
        y -= 1;
        m += 12;
    }
#ce

Func _KCal($sY = @YEAR, $sM = @MON, $sD = @MDAY)

    $iM = Number($sM) + 1
    $iY = Number($sY)
    If $iM < 3 Then
        $iY -= 1
        $iM += 12
    EndIf
    $iD = Number($sD)

#cs
    a = Math.floor(y/100.);
    b = 2-a+Math.floor(a/4.);
    if(y<1583) b = 0;
    if(y==1582) {
        if(m>10)  b = -10;
        if(m==10) {
            b = 0;
            if(day>4) b = -10;
        }
    }
#ce

    $iA = Floor($iY / 100)
    $iB = 2 - $iA + Floor($iA / 4)
    If $iY < 1583 Then
        $iB = 0
    EndIf
    If $iY = 1582 Then
        If $iM > 10 Then
            $iB = -10
        ElseIf $iM = 10 Then
            $iB = 0
            If $iD > 4 Then
                $iB = -10
            EndIf
        EndIf
    EndIf

#cs
    jd = Math.floor(365.25*(y+4716))+Math.floor(30.6001*(m+1))+day+b-1524;
#ce
    $iJD = Floor(365.25 * ($iY + 4716)) + Floor(30.6001 * ($iM + 1)) + $iD + $iB - 1524
#cs
    b = 0;
    if(jd>2299160){
        a = Math.floor((jd-1867216.25)/36524.25);
        b = 1+a-Math.floor(a/4.);
    }
#ce
    $iB = 0
    If $iJD > 2299160 Then
        $iA = Floor(($iJD - 1867216) / 36524.25)
        $iB = 1 + $iA - Floor($iA / 4)
    EndIf
#cs
    bb = jd+b+1524;
    cc = Math.floor((bb-122.1)/365.25);
    dd = Math.floor(365.25*cc);
    ee = Math.floor((bb-dd)/30.6001);
#ce
    $iBB = $iJD + $iB + 1524
    $iCC = Floor(($iBB - 122.1) / 365.25)
    $iDD = Floor(365.25 * $iCC)
    $iEE = Floor(($iBB - $iDD) / 30.6001)

#cs
    day =(bb-dd)-Math.floor(30.6001*ee);
    month = ee-1;
    if(ee>13) {
        cc += 1;
        month = ee-13;
    }
    year = cc-4716;
#ce

    $iDAY = ($iBB - $iDD) - Floor(30.6001 * $iEE)
    $iMONTH = $iEE - 1
    If $iEE > 13 Then
        $iCC += 1
        $iMONTH = $iEE - 13
    EndIf
    $iYEAR = $iCC - 4716
#cs
    if(adjust) {
        wd = gmod(jd+1-adjust,7)+1;
    } else {
        wd = gmod(jd+1,7)+1;
    }

    iyear = 10631./30.;
    epochastro = 1948084;
    epochcivil = 1948085;

    shift1 = 8.01/60.;
#ce
    $iIYEAR = 10631/30
    $iEpochAstro = 1948084
    $iEpochCivil = 1948085

    $nShift1 = 8.01 / 60
#cs
    z = jd-epochastro;
    cyc = Math.floor(z/10631.);
    z = z-10631*cyc;
    j = Math.floor((z-shift1)/iyear);
    iy = 30*cyc+j;
    z = z-Math.floor(j*iyear+shift1);
    im = Math.floor((z+28.5001)/29.5);
    if(im==13) im = 12;
    id = z-Math.floor(29.5001*im-29);
#ce
    $iZ = $iJD - $iEpochAstro
    $iCYC = Floor($iZ / 10631)
    $iZ -= 10631 * $iCYC
    $iJ = Floor(($iZ - $nShift1) / $iYEAR)
    $iIY = (30 * $iCYC) + $iJ
    $iZ -= Floor(($iJ * $iYEAR) + $nShift1)
    $iIM = Floor(($iZ + 29.5001) / 29.5)
    If $iIM = 13 Then
        $iIM = 12
    EndIf
    $iID = $iZ - Floor((29.5001 * $iIM) - 29)
#cs
    var myRes = new Array(8);

    myRes[0] = day; //calculated day (CE)
    myRes[1] = month-1; //calculated month (CE)
    myRes[2] = year; //calculated year (CE)
    myRes[3] = jd-1; //julian day number
    myRes[4] = wd-1; //weekday number
    myRes[5] = id; //islamic date
    myRes[6] = im-1; //islamic month
    myRes[7] = iy; //islamic year

    return myRes;
#ce
    ConsoleWrite("CEDay: " & $iDAY & @CRLF)
    ConsoleWrite("CEMon: " & $iMONTH - 1 & @CRLF)
    ConsoleWrite("CEYear: " & $iYEAR & @CRLF)
    ConsoleWrite("JulDay: " & $iJD - 1 & @CRLF)
    ;ConsoleWrite("WDayNum: " & $iWD - 1 & @CRLF)
    ConsoleWrite("IsDay: " & $iID & @CRLF)
    ConsoleWrite("IsMon: " & $iIM & @CRLF)
    ConsoleWrite("IsYear: " & $iIY & @CRLF)

EndFunc

It also gives nonsense results:

CEDay: 8
CEMon: 6
CEYear: 2018
JulDay: 2458307
IsDay: 5
IsMin: 17
IsYear: 1415

Anyway, enough of this - good old Gregorian is good enough for me!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Why not simply use a dedicated API ?

$greg = @MDay & "-" & @MON & "-" & @YEAR

$oHTTP = ObjCreate("Microsoft.XMLHTTP")
$oHTTP.Open("GET", "http://api.aladhan.com/gToH?date=" & $greg, False)
$oHTTP.Send() 
$res = $oHTTP.ResponseText
$oHTTP = 0
$hijri = StringRegExpReplace($res, '.*?date":"([^"]+).*', "$1")
Msgbox(0,"", "Gregorian = " & $greg & @crlf & "Hijri = " & $hijri)

 

Link to comment
Share on other sites

Is this any use?

#include <WinAPILocale.au3>
#include <Date.au3>

MsgBox(0, "Today's Date", ArabicDate(@YEAR, @MON, @MDAY))

Func ArabicDate($iYYYY, $iMM, $iDD)
    Local $iLangCID = 1025 ; Arabic - Saudi Arabia
    Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME)
    DllStructSetData($tSYSTEMTIME, "Year", $iYYYY)
    DllStructSetData($tSYSTEMTIME, "Month", $iMM)
    DllStructSetData($tSYSTEMTIME, "Day", $iDD)
    Return _WinAPI_GetDateFormat($iLangCID, $tSYSTEMTIME, 0, "yyyy/MM/dd")
EndFunc

 

Edited by czardas
Link to comment
Share on other sites

47 minutes ago, AutoBert said:

With Date.au3 included the result is 1439/09/25 and this seems correct.

You don't need to include Date.au3 to run the code I posted. It only goes back as far as the year 1318 (~118 years).

MsgBox(0, "Earliest Available Date", ArabicDate(1900, 04, 30))

 

Link to comment
Share on other sites

2 minutes ago, czardas said:

You don't need to include Date.au3 to run the code I posted. It only goes back as far as the year 1318 (~118 years).

MsgBox(0, "Earliest Available Date", ArabicDate(1900, 04, 30))

 

without i got error:

>Running AU3Check (3.3.14.5)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Temp\a.au3
"C:\Users\Bert\AutoIt3.My\Temp\a.au3"(8,56) : warning: $tagSYSTEMTIME: possibly used before declaration.
    Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\a.au3"(8,56) : error: $tagSYSTEMTIME: undeclared global variable.
    Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME)

 

Link to comment
Share on other sites

10 minutes ago, AutoBert said:

without i got error:

Hmm! Perhaps $tagSYSTEMTIME was moved. The code works fine with AutoIt version 3.3.14.2. The constant was previously defined in StructureConstants.au3 which was included in WinAPIInternals.au3. I will have to look at the latest release notes to see if this was a script breaking change.

Link to comment
Share on other sites

8 hours ago, AutoBert said:

and this was yesterday, so mustn't 1439/09/26 today?

Depending of the countries, there may be a difference up to 4 days in the corresponding calendars 
You only have to choose your flavor  :)

Link to comment
Share on other sites

That's the beauty behind hijri: sooo many variants to chose from and subsequent disputes to expect (I' relying on computational ... but mine is observational).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

This is odd: I tried a few other Arabic LCID numbers - found here: https://www.science.co.il/language/Locale-codes.php - and they seem to return the Western date, but Saudi returns the Hijri date. I wonder why?

Edit - I'm guessing that those countries might use multiple calendar systems (variants of Hijri etc...) and that Windows defaults to the Western date. I don't fully understand this. I can't see anything wrong with the code.

Edited by czardas
Link to comment
Share on other sites

  • 2 weeks later...

Hello
Thank you very much, my dear ones
I apologize for delaying the response, but we were in the days of Eid
Once again Thank you
The code that worked with me is

#include <WinAPILocale.au3>
#include <Date.au3>
MsgBox(0, "Today's Date", ArabicDate(@YEAR, @MON, @MDAY))
    Func ArabicDate($iYYYY, $iMM, $iDD)
    Local $iLangCID = 1025 ; Arabic - Saudi Arabia
Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME)
DllStructSetData($tSYSTEMTIME, "Year", $iYYYY)
DllStructSetData($tSYSTEMTIME, "Month", $iMM)
DllStructSetData($tSYSTEMTIME, "Day", $iDD)
Return _WinAPI_GetDateFormat($iLangCID, $tSYSTEMTIME, 0, "yyyy/MM/dd")
EndFunc


I want to thank everyone who interacted with this topic or read it
Regards to all of you: management, members, supervisors, and visitors.
Thank you so much
good Bye

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...