Hijri Calendar Source Code

What You Need

First of all. This is ONLY for Linux systems. If you are using a Windows system and not familiar with Linux this source won't work for you.

You further will need.

  • A linux system
  • gcc
  • PHP 8+ and php development files. You have to compile the C code into php extension and then can call the functions.

Good? Download here.

Download the ZIP source from here

https://code.habibur.com/hijri.zip

And then extract into any folder.

Installing and using it

Compile the PHP extension first.

cd astro/
phpize
./configure
make
sudo make install


Run the above commands and the extension will get built and installed on your system path. Note that code for the extension is in ./astro/ sub directory.

Enable the PHP extension

Edit /etc/php.ini and add the following line at the end of it

extension=astro

Calling

From PHP include astro.inc.php and then call any function

< ?php
include "astro.inc.php";
print HijriDate(to_jd("2023-02-23 06:23:45",6),6);


The number 6 above is timezone in hours + GMT/UTC. Positive on East side.

There are many other handy functions to find days in month, start date of a hijri month and more. Check the file astro.inc.php for details.

astro.inc.php

This one is written in a functional style therefore you don't need to build any object to send to function calls. Just a big list of parameters to each functions as you can find in function declaration.

Fix the cache

For speedup, dates for every month's newmoon are stored in two cache files called en.hijri.cache and bd.hijri.cache. You need to open astro.inc.php and fix the path of these two files where you store them. These two files are added in the zip file you downloaded above in directory data/

FAQ

What are **BD() function calls?
Hijri dates are separately calculated for
1. The middle east and the world and
2. For India and Bangladesh.
The **BD() functions handle the later case.

I can't compile and run the source, is there a way to view what you are doing?
Sure. Check file astro/astro.c and astro.inc.php. All of the algorithm are in these two files. The rest of all are boilerplate code.
Published
27-Feb-2023
Updated
9-Nov-2023