I've found a way to show the weekday and month in Arabic script without going online and was working on a moon-phase background (which seems appropriate for a Hijri calendar) when I noticed that the javascript used as a basis for the lua script had problems around the new moon dates. It sets the date as '0' when it should be '1' and the problem will next occur on 19th July at the beginning of Ramadan. Sorry about that.
Anyway, here is bettter Lua script using parts of the javascript from
http://www.muslimphilosophy.com/ip/hijri.htm. I suggest you use it to update the skin you posted on Deviant Art ASAP.
HijriCalendar.lua
Code: Select all
--[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]][][][][]
-- Revised script 'translated' from the JavaScript on http://www.muslimphilosophy.com/ip/hijri.htm
function Update()
today = os.date('!*t')
day = today.day
month = today.month
year = today.year
--[ the following can be used for testing ]
-- day =19
-- month =7
-- year = 2012
-- --------------------------------
SKIN:Bang('!SetOption', 'MtShowYear', 'Text', WriteHijriDate( day-1 , month , year, 'Hyear') )
SKIN:Bang('!SetOption', 'MtShowMonth', 'Text', WriteHijriDate( day-1 , month , year, 'Hmonth') )
SKIN:Bang('!SetOption', 'MtShowDate', 'Text', WriteHijriDate( day-1 , month , year, 'Hdate') )
SKIN:Bang('!SetOption', 'MtShowDay', 'Text', WriteHijriDate( day-1 , month , year, 'Hdayname') )
return 'dates set...'
end -- function Update
function intPart(floatNum)
if (floatNum< -0.0000001)
then return math.ceil(floatNum-0.0000001)
else return math.floor(floatNum+0.0000001)
end
end --- function intPart
function CalcHijriDate( d , m , y)
if ((y>1582) or ((y==1582) and (m>10)) or ((y==1582) and (m==10) and (d>14)))
then jd=intPart((1461*(y+4800+intPart((m-14)/12)))/4)+intPart((367*(m-2-12*(intPart((m-14)/12))))/12)-
intPart( (3* (intPart( (y+4900+ intPart( (m-14)/12) )/100) ) ) /4)+d-32075
else jd = 367*y-intPart((7*(y+5001+intPart((m-9)/7)))/4)+intPart((275*m)/9)+d+1729777
end
jd = jd + 1
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
m=intPart((24*l)/709)
d=l-intPart((709*m)/24)
wd =( ((jd+1%7)+7)%7)+1
y=30*n+j-30
Hdate = {}
Hdate[0] = jd -- julian day number
Hdate[1] = wd -- weekday number
Hdate[2] = d -- date
Hdate[3] = m -- month
Hdate[4] = y -- year
return Hdate
end--- function CalcHijriDate
function WriteHijriDate( Gd, Gm, Gy, ReturnValue)
local iwdNames = {"al-Ahad","al-Ithnayn","ath-Thalaathaa","al-Arba‘aa’","al-Khamis","al-Jumu‘ah","as-Sabt"}
local iMonthNames = {"Muharam","Safar","Rabi'ul Awal","Rabiul Akhir","Jamadil Awal","Jamadil Akhir","Rajab","Sha'ban","Ramadhan","Shawwal","Dhulka'edah","Dzulhijjah"}
local iDate = CalcHijriDate( Gd , Gm , Gy)
if ReturnValue == 'Hyear' then
HijriDatePart = (" "..iDate[4].." Hijrah")
elseif ReturnValue == 'Hmonth' then
HijriDatePart = (" "..iMonthNames[iDate[3]].." ")
elseif ReturnValue == 'Hdate' then
HijriDatePart = (" "..iDate[2].." ")
elseif ReturnValue == 'Hdayname' then
HijriDatePart = (" "..iwdNames[iDate[1]].." ")
end
return HijriDatePart
end -- of writeHijriDate