Closed hooman-mirghasemi closed 8 years ago
Have you tried setting formatter's $locale
to fa_IR@calendar= persian
?
yes I test it. it is only done: feb 2015 to: فبریوری 2015 all thing it's done is only translating mount name and change number formatting, not real change calender if it realy change calender should change that example to: اردیبهشت 1394
I have an repo for jalali ext based on jdf it's: https://github.com/hooman-pro/yii2-jdf
and my mean is done some work on the base of framework for have this ability on core
I done it in my project by extenting formmatter like down:
<?php namespace common\component;
use Yii; use hoomanMirghasemi\jdf\Jdf;
class MyFormatter extends \yii\i18n\Formatter {
const DATE_TYPE__GREGORIAN = 'gregorian';
const DATE_TYPE__JALALI = 'jalali';
public $dateFormatJalali = 'Y F d';
public $timeFormatJalali = 'Y F d H:i:s';
public $dateType = 'gregorian';
public function asDate($value, $format = null, $jalaliFormat = null){
if($this->dateType == self::DATE_TYPE__GREGORIAN){
if ($format === null) {
$format = $this->dateFormat;
}
return parent::asDate($value,$format);
}elseif($this->dateType == self::DATE_TYPE__JALALI){
if ($jalaliFormat === null) {
$jalaliFormat = $this->dateFormatJalali;
}
return Jdf::jdate($jalaliFormat,$value);
}
}
public function asDatetime($value, $format = null, $jalaliFormat = null){
if($this->dateType == self::DATE_TYPE__GREGORIAN){
if ($format === null) {
$format = $this->datetimeFormat;
}
return parent::asDatetime($value,$format);
}elseif($this->dateType == self::DATE_TYPE__JALALI){
if ($jalaliFormat === null) {
$jalaliFormat = $this->timeFormatJalali;
}
return Jdf::jdate($jalaliFormat,$value);
}
}
}
and in my config -> components I can use it like: 'formatter' => [ 'class' => 'common\component\CoreFormatter', 'dateType'=>'gregorian', 'nullDisplay' => '(not set)', 'dateFormat' => 'medium', 'dateFormatJalali' => 'Y F d', 'timeFormatJalali' => 'Y F d H:i:s', 'datetimeFormat' => 'medium', 'booleanFormat' => [ '', '' ]
],
Do You want to I done it, in forrmatter class and send by pull request?
what is Jdf::jdate
?
yes, you can send a pull request.
jdf means : jalali date format all functions that are in php for date are changed in jdf with j prefix, like: jdate for date and jmktime for mktime, for done it I should add jdf class and some changes on yii/i18/formmater.
a question: where is the best palce for jdf class in yii folders and namespace?
can you show how the jdf class looks like?
yes this is hear: https://github.com/hooman-pro/yii2-jdf/edit/master/Jdf.php a static class have all date fuontinality for jalali calendar
excuse me link is: https://github.com/hooman-pro/yii2-jdf/blob/master/Jdf.php
do you see it? where is the best place and namespace?
I don it. how is it?
As a reference another one https://github.com/sallar/jDateTime
Hmm... need to confirm that it's not possible using intl before adding more classes.
@samdark : i can't understand your means, more description please.
@armpogart : Jdf is the best jalali date library and it tested many many time. I choose it for that's trust between iranian and pepole use jalali calendar
There's http://php.net/manual/en/book.intl.php which we rely on and if it can handle jalali calendar, I'd prefer it to any library written in PHP.
ICU seems to have support for "@calendar=persian"
, not sure if there is anything needed by the intl extension to enable it.
for reference:
I could not. set it by intl class. all calendar i test theme in formatter local, and call asDate(time()); as down: @calendar=taiwan 2015 Month6 9 @calendar=persian ۹ ژوئن ۲۰۱۵ م. @calendar=islamic ٩ يونيو، ٢٠١٥ م
. . . and so on. but now in jalali is: 1393/06/09 in islamic or ghamari calendar is: الثلاثاء - ٢١ شعبان ١٤٣٦
have good job.
hi i have same problem we can use intl for solve problem ( use @calendar=persian for locale param ) but we have small fraction in IntlDateFormatter class define in formatDateTimeValue function we need define calender argument for example :
$formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE, $timeZone, IntlDateFormatter::TRADITIONAL, $format);
@z-avanes thanks for the hint! I have added a calendar property to the formatter, see #10517. could you check the test and verify it works as expected? I'd also love to include more locales in the test so please provide information on calendars you know.
if it's possible for you add an ablility to framework, to have jalali date format and when we set some property in config, like (dateType => 'jalali',) or (dateType => 'gregorian ') by depending on this property in config, formatter works.
hear is the best jalalidate vendor in php that tested in all iranian app and it's working currectly: http://jdf.scr.ir/