Last active
December 16, 2015 16:58
-
-
Save abo-elleef/5466585 to your computer and use it in GitHub Desktop.
it is a ruby converter from Gregorian to Hijure date format ,
Hijure date in the formal date in many Arabic and Islamic countries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# you can change the variable given_date to the date you want to be converted or run it directory form terminal like so | |
#ruby filename.rb year month day | |
#duby filename.rb 2000 1 1 | |
require "date" | |
arabic_months = { | |
1 => "Muharam", | |
2 => "Safer", | |
3 => "Rabeea awal", | |
4 => "Rabeea akher", | |
5 => "Gamada awal", | |
6 => "Gamada akher", | |
7 => "Ragb", | |
8 => "Shaaban", | |
9 => "Ramadan", | |
10 => "Shawal", | |
11 => "zo elqaada", | |
12 => "zo Elhagea" | |
} | |
def intpart(fnum) | |
if fnum < -0.0000001 | |
return (fnum - 0.0000001).ceil | |
else | |
return (fnum + 0.0000001).floor | |
end | |
end | |
def formg2h(date) | |
day = date.day | |
month = date.month | |
year = date.year | |
if ((year > 1582) or ((year == 1582) and (month > 10)) or ((year == 1582) and (month == 10) and (day > 14))) | |
jd1 = intpart((1461 * (year + 4800 + intpart((month - 14) / 12.0))) / 4) | |
jd2 = intpart((367 * (month - 2 - 12 * (intpart((month - 14) / 12.0)))) / 12) | |
jd3 = intpart((3 * (intpart((year + 4900 + intpart((month - 14) / 12.0)) / 100))) / 4) | |
jd = jd1 + jd2 - jd3 + day - 32075 | |
else | |
jd1 = intpart((7 * (year + 5001 + intpart((month - 9) / 7.0))) / 4) | |
jd2 = intpart((275 * month) / 9.0) | |
jd = 367 * year - jd1 + jd2 + day + 1729777 | |
end | |
l = jd - 1948440 + 10632 | |
n = intpart((l - 1) /10631.0) | |
l = l - 10631 * n + 354 | |
j1 = (intpart((10985 - l) / 5316.0)) * (intpart((50 * l) / 17719.0)) | |
j2 = (intpart(l / 5670.0)) * (intpart((43 * l) / 15238.0)) | |
j = j1 + j2 | |
l1 = (intpart((30 - j) / 15.0)) * (intpart((17719 * j) / 50.0)) | |
l2 = (intpart(j / 16.0)) * (intpart((15238 * j) / 43.0)) | |
l = l - l1 - l2 + 29 | |
m = intpart((24 * l) / 709.0) | |
d = l - intpart((709 * m) / 24.0) +1 #modifies | |
y = 30 * n + j - 30 | |
return Date.new(y, m,d) | |
end | |
given_date = Date.new(ARGV[0].to_i,ARGV[1].to_i,ARGV[2].to_i) | |
date = formg2h(given_date) | |
p date.day | |
p arabic_months[date.month] | |
p date.year | |
p date.strftime("%A %e #{arabic_months[date.month]} %Y ") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment