Search code examples
phpzend-frameworkmagentozend-datepersian

Zend Jalali Date


Does Zend support jalali date and calendar?
And How can i get that ?
I tried this:

    $locale = new Zend_Locale('fa_IR');
    $date = new Zend_Date();
    $new_date=  Zend_Locale_Format::getDate($date,
        array(
            'date_format' =>Zend_Locale_Format::getDateFormat('fa_IR'),
            'locale' => $locale,
            'fix_date' =>true
            )
        ); 

will not work as I want for me.


Solution

  • Zend_Date supports fa_IR dates, but I don't believe it will do calendar conversions from Gregorian to Jalali. You will have to set date manually. However, here is how you use Zend_Locale with Zend_Date for fa_IR

    // Manual conversion from Gregorian date 7/7/2011 to Jalali date 1390/4/16
    $date   = new Zend_Date('1390/4/16');  
    $date->setLocale('fa_IR');
    echo $date->toString('F j, Y, g:i a');
    // prints آوریل 16, 1390, 12:00 قبل از ظهر
    

    Edit

    I forgot to mention. I have Zend_Date format_type set to php as default format

    Zend_Date::setOptions(array('format_type' => 'php'));