function hijri in Hijri 8
Same name and namespace in other branches
- 7 hijri.module \hijri()
Retrive Hijri date from given format and timestamp.
2 calls to hijri()
- hijri_format_date in ./
hijri.module - @file hijri.inc Retrive Hijri date like Drupal format_date function.
- SettingsController::buildForm in src/
Form/ SettingsController.php - Form constructor.
6 string references to 'hijri'
- hijri.info.yml in ./
hijri.info.yml - hijri.info.yml
- HijriTestCase::setUp in tests/
hijri.test - Implements setUp().
- hijri_block_view in ./
_hijri.module - Implements hook_block_view().
- hijri_theme in ./
_hijri.module - Implements hook_theme().
- hijri_views_api in ./
_hijri.module - Implements hook_views_api().
File
- ./
hijri.module, line 22 - hijri.module This module convert to Hijri date in nodes,comments and a block.
Code
function hijri($format, $timestamp = NULL, $correction = 0) {
$timestamp = $timestamp == NULL ? time() : $timestamp;
$hijri_month_name = hijri_month_names();
$hijri_day_name = hijri_day_names();
// 0. Preparing timestamp if there is increments?
if ($correction != 0) {
$timestamp = $timestamp + 60 * 60 * 24 * $correction;
}
// 1. $calc_hijri_date to retrive Hijri Year, Hijri Month and Hijri day in numbers.
$year = format_date($timestamp, 'custom', 'Y');
$month = format_date($timestamp, 'custom', 'n');
$day = format_date($timestamp, 'custom', 'j');
$calc_hijri_date = hijri_calc($year, $month, $day);
// 2. Reserve constants that able to convert to Hijri.
$replacements = array(
'x01',
'x02',
'x03',
'x04',
'x05',
'x06',
'x07',
'x08',
'x09',
'x10',
'x11',
);
$patterns = array(
'Y',
'y',
'M',
'F',
'm',
'n',
'L',
'l',
'D',
'd',
'j',
);
$format = str_replace($patterns, $replacements, $format);
// 3. Converting user given date.
$date_result = format_date($timestamp, 'custom', $format);
// 4. Replacing reserved constants with Hijri results.
$patterns = $replacements = array();
// Y
$patterns[] = 'x01';
$replacements[] = $calc_hijri_date[0];
// y
$patterns[] = 'x02';
$replacements[] = substr($calc_hijri_date[0], -2);
// M .. There is no shortname in Hijri month names.
$patterns[] = 'x03';
$replacements[] = $hijri_month_name[$calc_hijri_date[1]];
// F
$patterns[] = 'x04';
$replacements[] = $hijri_month_name[$calc_hijri_date[1]];
// m
$patterns[] = 'x05';
$replacements[] = sprintf('%02d', $calc_hijri_date[1]);
// n
$patterns[] = 'x06';
$replacements[] = $calc_hijri_date[1];
// L
$patterns[] = 'x07';
$replacements[] = $hijri_day_name[format_date($timestamp, 'custom', 'N')];
// l .. There is no lowercase in Arabic day names.
$patterns[] = 'x08';
$replacements[] = $hijri_day_name[format_date($timestamp, 'custom', 'N')];
// D .. There is no shortnames in Arabic day names.
$patterns[] = 'x09';
$replacements[] = $hijri_day_name[format_date($timestamp, 'custom', 'N')];
// d
$patterns[] = 'x10';
$replacements[] = sprintf('%02d', $calc_hijri_date[2]);
// j
$patterns[] = 'x11';
$replacements[] = $calc_hijri_date[2];
return str_replace($patterns, $replacements, $date_result);
}