How to use traditional (national/native) dates and calendars? How can use non-Gregorian dates and calendars?

I adjust Drupal setting to my native language (fa) and native location (Asia/Theran) but month name and number of years also in Gregorian yet (however there are translated to my native language-persian).

I already use format_date() or date() in theme files, but this function is not locale-aware, which means that it always outputs English language data, such as day and month names and ordinal number suffixes.

I want to show the month names in the native language (e.g. Chinese, Islamic, Hebrew, Farsi/Persian) and use the national calendar (e.g. Irani, Shamsi, Jalali).

I want to understand is there any module or hardcoding solution in Drupal to show dates and calendars in other non-Gregorian calendars.

Any suggestions?
I'm hoping that someone else can Optimize this solution and make it better.
I'm ready to receive Any suggestion or criticism or any Other solution for this Challenge.

Features:


Does not requires any hacking or patching core /frontend solution
,display when dates are rendered
Does not change any date in database
Compatible and tested with PHP versions 5.3 and hereinafter
Supports Iranian/Persian/Shamsi/Jalali , Arabic/Hijri/Islamic, Thai, Hebrew...
Calendar systems
Better Performance becuse Doesn't outbreak the drupal core


Method 1, Using "IntelDateFormatter" Class:

First of all you must be sure that version of your php that installed is Newer than 5.3 and 'IntlDateFormatter' Extension was exist.
For use Traditional(National/Native) Date/Calender in Drupal 8 in nodes and Posted Comments with use of IntlDateFormatter class, add below codes to "THEME_NAME.theme":

For Nodes:

function THEME_NAME_preprocess_node(&amp;$variables) {
    $locale = "fa_IR@calendar=persian";
    $dateType = IntlDateFormatter::NONE;//type of date formatting.
    $timeType = IntlDateFormatter::NONE;//if time format setting to none, will give you date itself
    $timezone = 'Asia/Tehran';
    $calendar = IntlDateFormatter::TRADITIONAL;//Non-Gregorian Calendar
    $pattern = 'y/M/d';

    $fmt = new IntlDateFormatter($locale, $dateType, $timeType, $timezone, $calendar, $pattern);
    $date = $variables['node']-&gt;getCreatedTime();    
    $variables['date'] = $fmt-&gt;format($date);
}


For Comments:

function THEME_NAME_preprocess_comment(&amp;$variables) {
    $fmt = new IntlDateFormatter(
    "fa_IR@calendar=persian",
    IntlDateFormatter::NONE,
    IntlDateFormatter::NONE,
    'Asia/Tehran',
    IntlDateFormatter::TRADITIONAL,
    'y/M/d'
    );

    // Getting the node creation time stamp from the comment object.
    $date = $variables['comment']-&gt;getCreatedTime();
    $variables['created'] = $fmt-&gt;format($date);
}


Information about "IntlDateFormatter" Parameters:
locale: Locale to use when formatting or parsing or NULL to use the value specified in the ini setting, Link:http://www.w3.org/International/articles/language-tags

datetype:Date type to use (NONE, FULL, LONG, MEDIUM, SHORT). This is one of the IntlDateFormatter constants.

timetype: 
Time type to use (NONE, FULL, LONG, MEDIUM, SHORT). This is one of the IntlDateFormatter constants.

timezone: 
Time zone ID, default is system default, 
Link:http://www.php.net/manual/en/timezones.php. 

calendar: 
Calendar to use for formatting or parsing; default is Gregorian. This is one of the IntlDateFormatter calendar constants.
The calendars ICU allows you to play with include:


Japanese (@calendar=japanese)
Buddhist (@calendar=buddhist)
Chinese (@calendar=chinese)
Persian (@calendar=persian)
Indian (@calendar=indian)
Islamic (@calendar=islamic)
Hebrew (@calendar=hebrew)
Coptic (@calendar=coptic)
Ethiopic (@calendar=ethiopic)


Link:http://userguide.icu-project.org/datetime/calendar

pattern: 
Optional pattern to use when formatting or parsing. Possible patterns are documented at: http://userguide.icu-project.org/formatparse/datetime



METHOD 2,Using External Functions (like "jdf" for persian language):

First download this function form: http://jdf.scr.ir/download/
and then put downloaded file to your theme folder and add this code to above of "Theme_Name.theme"

include ('jdf.php');


and then add below code to appropriate place:

function Theme_Name_preprocess_node(&amp;$variables) {
   $date = $variables['node']-&gt;getCreatedTime();
   $variables['date'] = jdate("l j F Y", strtotime($date));
}


I'm hoping that someone else can build on this and make it better.