diff --git a/README.md b/README.md index 7e28561..9c0211c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ #jDateTime PHP class to convert dates from Gregorian calendar system to Jalali calendar system and vice versa. Supports dates beyond 2038. -Jalali, also known as Shamsi or Hijri Shamsi is the Iranian calendar system. +Jalali, also known as Shamsi or Hijri Shamsi is the Iranian calendar system. +It is also support Falaki month names. [![Build Status](https://travis-ci.org/sallar/jDateTime.png?branch=master)](https://travis-ci.org/sallar/jDateTime) #About v2.2.0 @@ -53,6 +54,7 @@ Please see [examples.php](examples.php) and [example-static.php](examples-static - [Afshin Mehrabani](http://afshinm.name) - [Amir Latifi](http://amiir.me) - [Ruhollah Namjoo](https://github.com/namjoo) +- [Morteza Rajabi](https://github.com/mortezarajabi) ##License jDateTime was created by [Sallar Kaboli](http://sallar.me) and released under the [MIT License](http://opensource.org/licenses/mit-license.php). diff --git a/examples-static.php b/examples-static.php index 7844e78..03d6b41 100644 --- a/examples-static.php +++ b/examples-static.php @@ -12,12 +12,14 @@ date_default_timezone_set('Asia/Tehran'); +jDateTime::setMonthNameType('falaki'); echo jDateTime::date('l j F Y H:i'); echo "
"; echo jDateTime::date('Y-m-d', false, false); echo "
"; echo jDateTime::date('Y-m-d', false, false, false); echo "
"; +jDateTime::setMonthNameType('jalali'); echo jDateTime::date("l j F Y H:i T", false, null, null, 'America/New_York'); //Just adding routine html tags. diff --git a/examples.php b/examples.php index 693c1bc..208ec42 100644 --- a/examples.php +++ b/examples.php @@ -12,15 +12,18 @@ //Init $date = new jDateTime(true, true, 'Asia/Tehran'); - echo $date->date("l j F Y H:i"); // Outputs: پنجشنبه ۱۵ اردیبهشت ۱۳۹۰ ۰۰:۰۰ echo "
\n"; +$date->setMonthNameType('falaki');// jalali or falaki +echo $date->date("l j F Y H:i"); // Outputs: پنجشنبه ۱۵ ثور ۱۳۹۰ ۰۰:۰۰ +echo "
\n"; echo $date->date("Y-m-d", false, false); // Outputs: 1390-02-15 echo "
\n"; echo $date->date("Y-m-d", false, false, false); //Outputs: 2011-05-05 //Or you could just use: $date->gDate("Y-m-d"); //Same as above echo "
\n"; +$date->setMonthNameType('jalali'); echo $date->date("l j F Y H:i T", false, null, null, 'America/New_York'); //چهارشنبه ۱۴ اردیبهشت ۱۳۹۰ ۱۵:۳۰ EDT echo "
\n"; diff --git a/jdatetime.class.php b/jdatetime.class.php index 19e3bc5..58d7039 100644 --- a/jdatetime.class.php +++ b/jdatetime.class.php @@ -51,6 +51,8 @@ class jDateTime private static $convert = true; //Convert numbers to Farsi characters in utf-8 private static $timezone = null; //Timezone String e.g Asia/Tehran, Defaults to Server Timezone Settings private static $temp = array(); + private static $monthNameTypes = array('jalali', 'falaki'); //Available month name types + private static $monthNameType = 'jalali'; //Default month name type /** * jDateTime::Constructor @@ -68,11 +70,25 @@ class jDateTime */ public function __construct($convert = null, $jalali = null, $timezone = null) { - if ( $jalali !== null ) self::$jalali = (bool) $jalali; if ( $convert !== null ) self::$convert = (bool) $convert; + if ( $jalali !== null ) self::$jalali = (bool) $jalali; if ( $timezone !== null ) self::$timezone = $timezone; } + /** + * jDateTime::setMonthNameType + * + * Pass jalali or falaki to change the month names + * + * @author Morteza Rajabi + * @param $type string Month name type + */ + public static function setMonthNameType($type = 'jalali') + { + if(in_array($type, self::$monthNameTypes)) + self::$monthNameType = $type; + } + /** * Convert a formatted string from Georgian Calendar to Jalali Calendar. * This will be useful to directly convert time strings coming from databases. @@ -484,9 +500,10 @@ private static function getMonthNames($month, $shorten = false, $len = 3) { // Convert $months = array( - 'فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند' + 'jalali' => ['فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'], + 'falaki' => ['حمل', 'ثور', 'جوزا', 'سرطان', 'اسد', 'سنبله', 'میزان', 'عقرب', 'قوس', 'جدی', 'دلو', 'حوت'] ); - $ret = $months[$month - 1]; + $ret = $months[self::$monthNameType][$month - 1]; // Return return ($shorten) ? self::substr($ret, 0, $len) : $ret;