PHP Classes

PHP Hijri Date Calendar: Convert and manipulate Hijri dates

Recommend this page to a friend!
  Info   View files Example   View files View files (74)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-12-03 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 737 All time: 4,524 This week: 94Up
Version Licenses PHP version Categories
hijri-date 2.3.4GNU General Publi...5.3PHP 5, Time and Date
Description 

Author

This package is specific mainly for applications used in Saudi Arabia Saudi Arabia .

This package can convert and manipulate Hijri dates.

It can perform several types of operations with dates in the Hijri calendar. Currently it can:

- Convert an Hijri date to a DateTime object
- Format Hijri dates
- Initialize a calendar class object to a given Hijri date
- Load Hum Al-Qura and apply adjustments
- Convert a Julian or Gregorian date to an Hijri date and vice-versa
- Return the month names in Arabic
- Check if it is a leap year
- Validate a Hijri date
- Etc..

Picture of Saeed Hubaishan
Name: Saeed Hubaishan <contact>
Classes: 2 packages by
Country: Yemen Yemen

 

Example

<?php

/*
 * example for Hijri Date Lib
 * by Saeed Hubaishan
 */
require_once '../hijri.class.php';
date_default_timezone_set('Asia/Aden');

function
buildMonthCal($month, $year, $outmonth = FALSE)
{
   
$c = new hijri\Calendar();
   
$d = new hijri\datetime('now', null, 'ar', $c);
    list(
$cday, $cmonth, $cyear) = explode('-', $d->format('_j-_n-_Y'));
   
   
$d->setDateHijri($year, $month + 1, 0);
    list(
$gm2, $gy2) = explode('-', $d->format("M-Y"));
   
$d->setDateHijri($year, $month, 1);
    list(
$start_wd, $month_name, $gm1, $gy1) = explode('-', $d->format("w-_M-M-Y"));
   
$title = $month_name . " " . $year . "?? (" . $gm1 . (($gy2 != $gy1) ? " " . $gy1 : '') . (($gm2 != $gm1) ? "-" . $gm2 : '') . " " . $gy2 . "?)";
   
   
$wd = array(0 => 1, 2, 3, 4, 5, 6, 0);
   
$month_length = $c->days_in_month($month, $year);
   
$b_month = $month - 1;
   
$b_year = $year;
    if (
$b_month == 0) {
       
$b_month = 12;
       
$b_year--;
    }
   
$a_month = $month + 1;
   
$a_year = $year;
    if (
$a_month == 13) {
       
$a_month = 1;
       
$a_year++;
    }
    echo
'<div class="navigation"><a class="prev" href="monthCalendar.php?month=' . $b_month . '&year=' . $b_year . '">&lt;</a>' . '<div class="title" >' . $title . '<a class= "next" href="monthCalendar.php?month=' . $a_month . '&year=' . $a_year . '">&gt;</a>' . '</div>
</div>'
;
    if (
$wd[$start_wd] > 0) {
       
$d->modify("-" . $wd[$start_wd] . " day");
    }
    echo
'<table>
    <tr>
        <th class="weekday">?????</th>
        <th class="weekday">?????</th>
        <th class="weekday">???????</th>
        <th class="weekday">????????</th>
        <th class="weekday">????????</th>
        <th class="weekday">??????</th>
        <th class="weekday">??????</th>
    </tr>'
;
   
$dayw = 0;
    do {
        list(
$hd, $hm, $hy, $gd, $gm, $gy) = explode('-', $d->format("_j-_n-_Y-j-n-Y"));
        if (
$dayw == 0) {
            echo
"<tr>";
        }
       
$class = '';
        if (
$cday == $hd && $cmonth == $hm && $cyear == $hy) {
           
$class = "today";
        } elseif (
$hm == $month) {
           
$class = "current";
        }
        echo
"<td class='$class'><a href='javascript: void(0)'>$hd<br/>&nbsp;<span class='gre'>$gd</span></a></td>";
        if (
$dayw == 6) {
            echo
"</tr>";
           
$dayw = 0;
            if ((
$hm > $month) || ($hy > $year) || ($hm == $month && $hd == $month_length)) {
                break;
            }
        } else {
           
$dayw++;
        }
       
$d->modify("+1 day");
    } while (
TRUE);
    echo
'</td></tr></table>';
}
$d = new hijri\datetime();
list(
$year, $month) = explode(' ', $d->format('_Y _n'));
// echo is_integer($_REQUEST['month'])).$_REQUEST['year'];
if (isset($_REQUEST['month']) && isset($_REQUEST['year'])) {
   
$tmonth = (int) $_REQUEST['month'];
   
$tyear = (int) $_REQUEST['year'];
   
    if (
$tmonth > 0 && $tmonth < 13) {
       
$year = $tyear;
       
$month = $tmonth;
    }
}
?>
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="utf-8" />
<meta name="viewport"
    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title>??????? ?????? ??????</title>
<!-- add styles and scripts -->
<style>
/* calendar styles */
#calendar {
    -moz-user-select: none;
    border: 1px solid #EEEEEE;
    border-radius: 6px 6px 6px 6px;
    color: #333333;
    font-family: Arial, sans-serif;
    font-size: 1.1em;
    margin: 10px auto;
    padding: 0.4em;
    width: 90%;
    direction: rtl;
}

#calendar .navigation {
    background-color: #CC0000;
    border: 1px solid #E3A1A1;
    border-radius: 6px 6px 6px 6px;
    color: #FFFFFF;
    font-weight: bold;
    padding: 1px;
    position: relative;
}

#calendar .navigation .title {
    background: none repeat scroll 0 0 transparent;
    border-color: rgba(0, 0, 0, 0);
    color: inherit;
    line-height: 1.8em;
    margin: 0 2.3em;
    text-align: center;
}

#calendar .navigation .prev, #calendar .navigation .next {
    text-decoration: none;
    color: #FFFFFF;
    height: 24px;
    opacity: 0.9;
    position: absolute;
    top: 4px;
    width: 24px;
}

#calendar .navigation .prev {
    background-position: 0 0;
    right: 4px;
}

#calendar .navigation .next {
    background-position: -24px 0;
    left: 4px;
}

#calendar .navigation .prev:hover, #calendar .navigation .next:hover {
    opacity: 1;
}

#calendar table {
    border-collapse: collapse;
    font-size: 0.9em;
    table-layout: fixed;
    width: 100%;
}

#calendar table th {
    border: 0 none;
    font-weight: bold;
    padding: 0.7em 0.3em;
    text-align: center;
}

#calendar table td {
    border: 0 none;
    padding: 1px;
}

#calendar table td a {
    background-color: #EEEEEE;
    border: 1px solid #D8DCDF;
    color: #004276;
    display: block;
    font-weight: normal;
    opacity: 0.7;
    padding: 0.2em;
    text-align: right;
    text-decoration: none;
}

#calendar table td a:hover {
    background-color: #F6F6F6;
    border: 1px solid #CDD5DA;
    color: #111111;
}

#calendar table td.current a {
    font-weight: bold;
    opacity: 1;
}

#calendar table td.today a {
    background-color: #FBF8EE;
    border: 1px solid #FCD3A1;
    color: #444444;
    font-weight: bold;
    opacity: 1;
}

#calendar span.gre {
    text-align: left;
    direction: ltr;
    color: #0080CC;
    float: left;
}
</style>
</head>
<body>
    <div id="calendar">
<?php
buildMonthCal
($month, $year)?>
</div>
</body>
</html>


Details

HijriDateLib

php classes to view and manage Hijri Calendar.

the lib has two algorithms to calculte Hijri Date:

1-Hijri Tabular algorithm

2- Um Al-Qura algoritm

Lib Features

  1. Two algorithms to calculte Hijri Date: Hijri Tabular algorithm, Um Al-Qura algorithm.
  2. The lib allows you to adjust the Hijri Um Al-Qura algorithm and save the adjustment.
  3. The lib has a full feature class to manage the adjustments of Um Al-Qura Calendar.
  4. The Lib has a datetime class extends the real php datetime class, and allows you to return Hijri Calendar with the Gregorian Calendar in one format and one command.
  5. The Hijri datetime class have all real php class Gregorian Calendar Functions plus main functions for Hijri Calendar.
  6. The Lib returns the Hijri Calendar months in 20 international Languages.
  7. The Um Al-Qura algorithm works from 1318 A.H to 1500 A.H. and Tabular Algorithm work from year 5499 before Hijra to 1,500,000 A.H, If Um Al-Qura algorithm selected and the date out of range the uses Tabular Algorithm instead.
  8. The has full api documents.

Requirments

The HijriDatLib requires at php version 5.3 at least. It is compatible up to php 8.1 .


  Files folder image Files  
File Role Description
Files folder imagedocs (1 file, 1 directory)
Files folder imageexamples (4 files)
Plain text file hijri.class.php Class Class source
Accessible without login Plain text file README.md Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:737
This week:0
All time:4,524
This week:94Up