GREGORIAN TO HIJRI

//Taken from : http://www.bukisa.com/articles/81917_hijri-date-converter-delphi-source-code#ixzz19fQ6xQH8

// Created by Irwan A.
// irwan.a@gmail.com
//
// adapted from a Javascript source code that

// i found somewhere on the net.
// but i lost the URL. hope the author doesn’t mind :)
// Month & day names are taken from
// http://en.wikipedia.org/wiki/Islamic_calendar
// thanks to @bu @hs@n
// for pointing this out

//comment by me (

//May be the URL of java script : http://www.islamicfinder.org/

unit Hijri;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Math;

type
THijriDate = record
HijriDate: integer;
HijriMonth: integer;
HijriYear: integer;
JulianDate: integer;
HijriDay: string;
end;

function IntPart(Num : real) : integer;
function WeekDay(Wdn : integer) : string;
function Gre2Hijri(var D, M, Y : word): THijriDate;
function HijriMonths(Mth : integer) : string;

implementation

function IntPart(Num : real) : integer;
begin
if Num < -0.0000001 then
Result := Ceil(Num – 0.0000001)
else
Result := Floor(Num + 0.0000001);
end;

function WeekDay(Wdn : integer) : string;
begin
{
case Wdn of
0: Result := ’Al-Ithnayn’;
1: Result := ’Ath-Thalatha’;
2: Result := ’Al-Arba`a’;
3: Result := ’Al-Khomis’;
4: Result := ’Al-Jum`a’;
5: Result := ’As-Sabt’;
6: Result := ’Al-Ahad’;
end;
}

//My Editing for Indonesian

case Wdn of
0: Result := ’Senin’;
1: Result := ’Selasa’;
2: Result := ’Rabu’;
3: Result := ’Kamis’;
4: Result := ’Jum`at’;
5: Result := ’Sabtu’;
6: Result := ’Ahad’;
end;

end;

function Gre2Hijri(var D, M, Y : word): THijriDate;
var
jd, l, n, j : integer;
begin
if ((Y > 1582) or ((Y = 582) and (M > 10))
or ((Y = 1582) and (M = 10) and (D>14))) then
begin
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;
end
else
begin
jd := 367 * Y – IntPart((7 * (Y + 5001 +
IntPart((M – 9)/7)))/4) + IntPart((275 * M)/9)
+ D + 1729777;
end;

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);
y := 30 * n + j – 30;

Result.HijriDate := d;
Result.HijriMonth := m;
Result.HijriYear := y;
Result.JulianDate := jd;
Result.HijriDay := WeekDay(jd mod 7);

end;

function HijriMonths(Mth : integer) : string;
begin
{
case Mth of
1: Result := ’Muharram’;
2: Result := ’Safar’;
3: Result := ’Rabi’’ al-awwal’;
4: Result := ’Rabi’’ al-thani’;
5: Result := ’Jumada al-awwal’;
6: Result := ’Jumada al-thani’;
7: Result := ’Rajab’;
8: Result := ’Sha’’ban’;
9: Result := ’Ramadan’;
10: Result := ’Shawwal’;
11: Result := ’Dhu al-Qi’’dah’;
12: Result := ’Dhu al-Hijjah’;
end;
}

//My Editing for Indonesian

case Mth of
1: Result := ’Muharram’;
2: Result := ’Safar’;
3: Result := ’Rabiulawwal’;
4: Result := ’Rabiutsaani’;
5: Result := ’Jumadilawwal’;
6: Result := ’Jumadatsaani’;
7: Result := ’Rajab’;
8: Result := ’Sya’’ban’;
9: Result := ’Ramadhan’;
10: Result := ’Syawal’;
11: Result := ’Dzulqoidah’;
12: Result := ’Dzulhijjah’;
end;
end;

end.

Sumber Asli dengan sedikit tambahan komentar dan konversi :

http://www.bukisa.com/articles/81917_hijri-date-converter-delphi-source-code#ixzz19fQ6xQH8

Posted Mei 18, 2011 by ridwan mustofa in MasihBelajar

Ikuti

Get every new post delivered to your Inbox.