Moderators Melba23 Posted June 8, 2018 Moderators Posted June 8, 2018 nacerbaaziz, Here is my version of a javaScript algorithm that I found: expandcollapse popup_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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
AutoBert Posted June 8, 2018 Posted June 8, 2018 4 hours ago, Melba23 said: Corrected (I think) for the Int typing - now gives: 1462/3273/26 Which is still wrong, but closer to what online convertors give as 1439/09/25 Maybe the algorithm @nacerbaaziz posted is wrong.
mikell Posted June 8, 2018 Posted June 8, 2018 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)
czardas Posted June 8, 2018 Posted June 8, 2018 (edited) 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 June 9, 2018 by czardas Melba23 1 operator64 ArrayWorkshop
AutoBert Posted June 8, 2018 Posted June 8, 2018 @czardas: With Date.au3 included the result is 1439/09/25 and this seems correct. @mikell: http://api.aladhan.com returns 24-09-1439, seems also correct. But 12 hours ago, Melba23 said: 1439/09/25 and this was yesterday, so mustn't 1439/09/26 today? @Melba23
czardas Posted June 9, 2018 Posted June 9, 2018 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)) operator64 ArrayWorkshop
AutoBert Posted June 9, 2018 Posted June 9, 2018 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)
czardas Posted June 9, 2018 Posted June 9, 2018 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. operator64 ArrayWorkshop
czardas Posted June 9, 2018 Posted June 9, 2018 (edited) I can't find any mention of such a change in the release notes. I'm sure you are right, but it should have been documented. CODE UPDATED! Edited June 9, 2018 by czardas operator64 ArrayWorkshop
mikell Posted June 9, 2018 Posted June 9, 2018 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
jchd Posted June 9, 2018 Posted June 9, 2018 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 hereRegExp tutorial: enough to get startedPCRE 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)
czardas Posted June 9, 2018 Posted June 9, 2018 (edited) 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 June 9, 2018 by czardas operator64 ArrayWorkshop
nacerbaaziz Posted June 17, 2018 Author Posted June 17, 2018 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 czardas 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now