Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
biladina committed Apr 25, 2020
1 parent 4a1aa5f commit ff67648
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
43 changes: 29 additions & 14 deletions HijriDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@

use Yii;

class HijriDateTime extends \yii\base\Widget {
class HijriDateTime extends \yii\base\Widget
{

/**
* Defaults
Expand All @@ -55,9 +56,11 @@ class HijriDateTime extends \yii\base\Widget {
* To use system defaults pass null for english names
* @param $lang String language - "ar" for Arabic months name
*/
function __construct() {
function __construct()
{
parent::init();
if (!isset(Yii::$app->i18n->translations['hijri'])) {
if (!isset(Yii::$app->i18n->translations['hijri']))
{
Yii::$app->i18n->translations['hijri'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en',
Expand All @@ -66,8 +69,8 @@ function __construct() {
}
}

public function init() {
}
public function init()
{}

/**
* returns a string formatted according to the given format string using the given
Expand All @@ -80,12 +83,16 @@ public function init() {
* @return String Returns the Hijri date according to format and timestamp in Arabic/English
*
*/
function date($format, $timestamp=0) {
if ($timestamp === 0) {
function date($format, $timestamp=0)
{
if ($timestamp === 0)
{
$timestamp = time();
}

list ($d, $D, $j, $l, $S, $F, $m, $M, $n, $t, $L, $o, $Y, $y, $w, $a, $A, $H, $i, $s, $O) = explode("/", date("d/D/j/l/S/F/m/M/n/t/L/o/Y/y/w/a/A/H/i/s/O", $timestamp));
extract($this->GeToHijr($d, $m, $Y));

$j = $day;
$t = $ml;
$L = $ln;
Expand All @@ -97,8 +104,6 @@ function date($format, $timestamp=0) {
$S = substr($j, -1) == 1 ? "st" : (substr($j, -1) == 2 ? "nd" : (substr($j, -1) == 3 ? "rd" : "th"));
$F = Yii::t('hijri', 'lo.mon.' . $n);
$M = Yii::t('hijri', 'sh.mon.' . $n);


$D = Yii::t('hijri', 'sh.day.' . $w);
$l = Yii::t('hijri', 'lo.day.' . $w);
$S = "";
Expand All @@ -110,6 +115,7 @@ function date($format, $timestamp=0) {
$format = str_replace($davars, $myvars, $format);
$date = date($format, $timestamp);
$date = str_replace(array("¢", "£", "ç", "¥", "©", "ï", "â", "®"), array($D, $l, $S, $F, $M, $a, $A, $r), $date);

return $date;
}

Expand All @@ -123,19 +129,24 @@ function date($format, $timestamp=0) {
* @return Array Hijri date[int month, int day, int year, int ln, int ml]
* @see Robert Gent method maker (http://www.phys.uu.nl/~vgent/islam/ummalqura.htm)
*/
public function GeToHijr($day=20, $month=02, $year=1976) {
public function GeToHijr($day=20, $month=02, $year=1976)
{
$jd = GregorianToJD($month, $day, $year);
$mjd = $jd - 2400000;

foreach ($this->jdl as $i => $v)
if ($v > ($mjd - 1))
break;

$iln = $i + 15588; // Islamic lunation number (Births of New Moons)
$ii = floor(($i - 1) / 12);
$year = 1300 + $ii; // year
$month = $i - 12 * $ii; // month
$day = $mjd - $this->jdl[$i - 1]; //day
$ml = $this->jdl[$i] - $this->jdl[$i - 1]; // Month Length

list ($_Date["month"], $_Date["day"], $_Date["year"], $_Date["ln"], $_Date["ml"]) = array($month, $day, $year, $iln, $ml);

return ($_Date);
}

Expand All @@ -147,17 +158,21 @@ public function GeToHijr($day=20, $month=02, $year=1976) {
* @param String $sep separator
* @return String Date in Hijri as formated or like d-m-Y
*/
public function strToHijri($strDate, $format= "d-m-Y") {
if ($format == "d-m-Y") {
public function strToHijri($strDate, $format= "d-m-Y")
{
if ($format == "d-m-Y")
{
list ($d, $m, $Y) = explode("/", date("d/m/Y", strtotime($strDate)));
extract($this->GeToHijr($d, $m, $Y));
$date = "$day-$month-$year";
} else {
}
else
{
$date = $this->date($format, strtotime($strDate));
}

return $date;
}

}

?>
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
{
"name": "biladina/yii2-hijridatetime",
"description": "Hijri Date Time - Extension from Abdulrhman Alkhodiry, compatible with 'Umm al-Qura' formal calendar in Saudi Arabia and the Muslim world",
"description": "Hijri Date Time - Yii2 Extension for using Hijri date time, compatible with 'Umm al-Qura' formal calendar in Saudi Arabia and the Muslim world",
"type": "yii2-extension",
"keywords": ["yii2","extension","hijridatetime","hijri","hijriyah"],
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "Abdulrhman Alkhodiry",
"email": "[email protected]",
"homepage": "http://7in.org",
"role": "Developer"
"homepage": "http://7in.org"
},
{
"name": "Abdul-Aziz Al-Oraij",
"email": "[email protected]",
"homepage": "http://aziz.oraij.com",
"role": "Developer"
"homepage": "http://aziz.oraij.com"
},
{
"name": "Nabil Munawar",
"email": "[email protected]"
"email": "[email protected]",
"homepage": "http://nabilmunawar.wordpress.com"
}
],
"require": {
Expand Down
2 changes: 1 addition & 1 deletion messages/en/hijri.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
'sh.tm.am' => 'am',
'sh.tm.pm' => 'pm',
'lo.tm.AM' => 'AM',
'lo.tm.PM' => 'PM',
'lo.tm.PM' => 'PM',
);
2 changes: 1 addition & 1 deletion messages/fr/hijri.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
'sh.tm.am' => 'am',
'sh.tm.pm' => 'pm',
'lo.tm.AM' => 'AM',
'lo.tm.PM' => 'PM',
'lo.tm.PM' => 'PM',
);
2 changes: 1 addition & 1 deletion messages/id/hijri.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
'sh.tm.am' => 'am',
'sh.tm.pm' => 'pm',
'lo.tm.AM' => 'AM',
'lo.tm.PM' => 'PM',
'lo.tm.PM' => 'PM',
);

0 comments on commit ff67648

Please sign in to comment.