function jalalidate_convert in PersianTools 7
Convert given time to Jalali calendar. Two different formats need to be handled. When using PHP's internal date conversion, the formats follow the pattern explained here: http://userguide.icu-project.org/formatparse/datetime Otherwise the date format follow this pattern: http://ir2.php.net/manual/en/function.date.php
Parameters
$time: time in the Gregorian format
Return value
jalalidate
2 calls to jalalidate_convert()
- jalalidate_nodes_preprocess_comment in jalalidate_nodes/
jalalidate_nodes.module - Implements hook_preprocess_comment().
- jalalidate_nodes_preprocess_node in jalalidate_nodes/
jalalidate_nodes.module - Implements hook_preprocess_node().
File
- includes/
jalalidate_lib.inc, line 14
Code
function jalalidate_convert($time, $format = NULL) {
$date_format = variable_get('jalalidate_nodes_format');
if (class_exists('IntlDateFormatter')) {
if ($format == NULL) {
switch ($date_format) {
case 'short':
$format = 'Y/M/d';
break;
case 'medium':
$format = 'Y/M/d - H:m';
break;
case 'long':
$format = 'EEEE Y/M/d - H:m';
break;
case 'custom':
$format = variable_get('jalalidate_nodes_custom');
break;
}
}
$fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::FULL, IntlDateFormatter::SHORT, jalalidate_default_timezone(), IntlDateFormatter::TRADITIONAL);
$fmt
->setPattern($format);
$date = $fmt
->format(intval($time));
}
else {
if ($format == NULL) {
switch ($date_format) {
case 'short':
$format = 'Y/n/j';
break;
case 'medium':
$format = 'Y/n/j - G:i';
break;
case 'long':
$format = 'l Y/n/j - G:i';
break;
case 'custom':
$format = variable_get('jalalidate_nodes_custom');
break;
}
}
module_load_include("php", "persiantools", "includes/Date");
$date = \Shamsi\date($format, $time);
}
return $date;
}