Learn the Rules, Break The Rules, and Create the New Ones...

Hi... My name is Rizky Prihanto. You can call me RQ, or Rizky either. I am currently living on Bandung, Indonesia. Had a lot of works and research about Enterprise Information Systems (majoring on education and e-governments). I have bunch of interests (some friends call it 'freakz') about MySQL Opensource Database and now I am one of the administrator of MySQL Indonesia User Group - the opensource community initialized by Sun Microsystems Indonesia.

My Company PT Cinox Media Insani, Bandung, Indonesia. I work here since 2008 and I take responsibility as Chief of Software Architect. My job is about planning, imaginating, fantasy-ing, concepting, and build the infrastructure of the new information systems (or app engines) which going to be implemented.

This blog This is my blog that represent my current opinion, research and experiences about anything in Software Engineering. Written since 2007 (actually) and has been vaccum for a lot of while. And now I wanna ressurrect this blog (optimistically) from the long-long-hibernation with something fresh and new ideas -- still about MySQL, software engineering, development, and may be something managerial here.

About the tagline I've learned the statement above from some paper written by Kent Beck about Extreme Programming (XP) methodology -- some sort of practical software development methods which have no boundaries. That's very inspiring me a lot. I have written some article on this blog that tell my interpretation about that statement here.

My Another Blogs I have classifying my blogs into some sort of genre. The blog that you read here right now is my primary blog that tell you (majoring) about IT stuff. But if you wanna look another side of me, you can visit here, here, here,or here. Hope it'll be interesting for some of you.

Credits I would thanks to Blogger for this great blog platform. Skinpress who designed this Wordpress template (which is bloggerized by Free Blogger Templates). My appreciate is also going to you who give your generously time for visiting my blog.

Menghitung Waktu Sholat

rencananya sih, *awalnya* mo usulin fitur jadwal sholat online utk di-embedd di aplikasi
*aslinya* sih mo cari RSS Feed google gadget yg udah nyedia-in itu jadi pengennya sih tinggal ambil doank...
*eh ketemunya* dokumen ttg algoritma waktu sholat (donlot di sini)
*penasaran mode = on*
*iseng mode = on*
*suntuk mode = on* - habis debat ama "mamanya anak2" (hiks...)

rancang2 tabel dulu :
+----+------+----------+-----------+----------+------------+
| ID | kota | Latitude | Longitude | timezone | ketinggian |
+----+------+----------+-----------+----------+------------+

DDL nya :

CREATE TABLE `tbl_city_coordinate` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`kota` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`latitude` float NOT NULL,
`longitude` float NOT NULL,
`timezone` float NOT NULL,
`ketinggian` float NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

*googling tentang koordinat astronomis kota jakarta*
*isi-isi data dulu*

INSERT INTO `tbl_city_coordinate` VALUES ('1', 'JAKARTA', '-6.21522', '106.818', '7', '100');


trus bikin stored function nya, ngikutin pedoman algoritma :


CREATE DEFINER=`root`@`localhost` FUNCTION `sf_waktusholat`(vKodeCity int, vTanggal date, idxwaktusholat tinyint) RETURNS varchar(20) CHARSET utf8
BEGIN
declare B float;
declare L float;
declare R float;
declare H float;
declare J int;
declare beta float;
declare D float;
declare T float;
declare Gd float;
declare Gn float;
declare Z float;
declare U float;
declare Vd float;
declare Vn float;
declare W float;
declare hasil float;
declare jam varchar(20);

set j = dayofyear(vTanggal);
set Gd = 19;
set Gn = 19;

SELECT 2 * pi() * J / dayofyear(CONCAT(year(now()),'-12-31')) INTO beta;
SELECT (180/pi()) * (0.006918 - (0.399912 * cos(beta))+(0.070257 * sin(beta))-(0.006758 * cos(2*beta))+(0.000907*sin(2*beta))-(0.002697*cos(3*beta))+(0.001480*sin(3*beta))) INTO D;

SELECT 229.18*(0.000075+(0.001868*cos(beta))-(0.032077*sin(beta))-(0.014615*cos(2*beta))-(0.040849*sin(2*beta))) INTO T;

SELECT latitude, longitude, (timezone) * 15, ketinggian
INTO B,L,R,H
FROM tbl_city_coordinate
WHERE id = vKodeCity;

SET Z = 12 + ((R-L)/15) - (T/60);
SET U = (180/(15*pi())) * ACOS((SIN((-0.8333-(0.0347 * SIGN(H) * SQRT(ABS(H))))*pi()/180)- SIN(D * pi() / 180) * SIN(B * pi() / 180) )/(COS(D * pi()/180) * COS(B * pi()/180)));
SET Vd = (180/(15*pi())) * ACOS((-1 * SIN(Gd * pi()/180) - SIN(D * pi()/180) * SIN(B * pi()/180))/(COS(D * pi()/180) * COS(B * pi()/180)));
SET Vn = (180/(15*pi())) * ACOS((-1 * SIN(Gn * pi()/180) - SIN(D * pi()/180) * SIN(B * pi()/180))/(COS(D * pi()/180) * COS(B * pi()/180)));
SET W = (180/(15*pi())) * ACOS((SIN(ATAN(1/(1 + TAN(ABS(B-D) * pi()/180)))) - SIN(D * pi()/180) * SIN(B * pi()/180))/(COS(D * pi()/180) * COS(B * pi()/180)));

case idxwaktusholat
when 0 then SET hasil = (z - Vd) - 0.134; /*imsyak*/
when 1 then SET hasil = Z - Vd - 0.033 ; /*subuh*/
when 2 then SET hasil = Z - U; /*matahari terbit*/
when 3 then SET hasil = Z + 0.05; /*zuhur*/
when 4 then SET hasil = Z + W + 0.033; /*ashar*/
when 5 then SET hasil = Z + U + 0.033; /*maghrib*/
when 6 then SET hasil = Z + Vn - 0.0167; /*isya*/
end case;

SET Jam = SEC_TO_TIME(hasil*3600);
RETURN jam;
END;


coba bikin stored procedure utk nampilin waktu sholat :

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_waktusholat_tampil`(vIDKota int, tanggal date)
BEGIN
IF vIDKota <= 0 THEN
SELECT Kota, sf_waktusholat(id, date(tanggal), 1) as `Subuh`,
sf_waktusholat(id, date(tanggal), 3) as `Dhuhur`,
sf_waktusholat(id, date(tanggal), 4) as `Ashar`,
sf_waktusholat(id, date(tanggal), 5) as `Maghrib`,
sf_waktusholat(id, date(tanggal), 6) as `Isya`
FROM tbl_city_coordinate
ORDER BY Kota ASC;
ELSE
SELECT Kota, sf_waktusholat(id, date(tanggal), 1) as `Subuh`,
sf_waktusholat(id, date(tanggal), 3) as `Dhuhur`,
sf_waktusholat(id, date(tanggal), 4) as `Ashar`,
sf_waktusholat(id, date(tanggal), 5) as `Maghrib`,
sf_waktusholat(id, date(tanggal), 6) as `Isya`
FROM tbl_city_coordinate
WHERE id = vIDKota;
END IF;
END;

*coba dieksekusi tu SP :
call sp_waktusholat_tampil(1,'2008-04-01');

*hasilnya :
+---------+----------+----------+----------+----------+----------+
| Kota | Subuh | Dhuhur | Ashar | Maghrib | Isya |
+---------+----------+----------+----------+----------+----------+
| JAKARTA | 04:40:05 | 11:59:33 | 15:14:20 | 18:01:09 | 19:10:03 |
+---------+----------+----------+----------+----------+----------+

... cukup memuaskan ...
*kurang lebih lah dengan jadwal sholat utk wilayah Jakarta yg sekarang nampang di republika-online

script lengkap bisa didonlot di sini...

TIDUR AAAH...



5 comments:

Anonim mengatakan...

tengkiu mass, buat nambah nambah koleksi source code. :D

danker annawawi mengatakan...

makasih mas atas ilmunya :D

Anonim mengatakan...

ijin download ya mas...

Cecep mengatakan...

Terima Kasih Mas ... sangat membantu sekali buat jadwal sholat

- mengatakan...

mas ini source code untuk aplikasi berbasis web atau berbasis desktop?

Posting Komentar