Closed salarmehr closed 6 years ago
@salarmehr I have solved this for my own projects by using this package, which contains a Time
class that works the same as Carbon but can also handle calendars and locale formats when formatting the date.
@lorenzo Thanks for the link. I hope to see this feature in the carbon.
May you provide an example code from that project for converting calendars?
Yes, it looks like this:
$time = new Time('2010-01-14 13:59:28 2010');
echo $time->i18nFormat(IntlDateFormatter::FULL, null, 'ps-IR@calendar=persian');
// 'پنجشنبه د ۱۳۸۸ د مرغومی ۲۴ ۱۳:۵۹:۲۸ (GMT)';
@lorenzo Thanks, can it also get a non-Gregorian date and convert it to another type?
Also here is your code using IntlDateTime class:
$date = new IntlDateTime($time, 'Asia/Tehran');
$date->setCalendar('persian');
echo $date->format('yyyy/MM/dd HH:mm');
Its api and code coverage is very well.
Yes, there is Time::parse($nonGregorianDate, $localeOptions)
I think in Carbon, it is better if we can override toString or other similar in localization.
For example, in Thai I have to convert to BE calendar by adding 543 to year when display to user.
currently I've done this feature for jalali date. so the methods to convert georgian and jalali date to each other have been implemented. but i'm struggling with carbon to put the convertors as a facade in carbon getter & setters. you know its very hard , all the properties currently passed through getters and setters even inside carbon class. I hope it ends soon to notify you. 😃
Finally i did it. This jalali date package have carbon included. https://github.com/p3ym4n/jdate
@p3ym4n thanks . i hope this works fine ;)
To avoid mix too many responsibilities, I find it preferable that one date library should handle one calendar and so using an other library seems the right think to do rather than adding calendars in Carbon.
Similar to Cabon, IntlDateTime is an extended version of php 5 DateTime class. Additionally it supports multiple calendars and locales provided by ICU project.
Its code can be reused in Carbon and add Solar Hijri, Hebrew, Hijri and other calendar types provided by ICU your great work become applicable in the reset of world. I particularly need Solar Hijri for the countries that does not use Gregorian calendar at all.