Fork me on GitHub
 

What is this extended date function ?


Extended date function is a function made to make a possibility for countries who uses another calendar instead of Gregorian calendar, to use their own calendar on ImpressCMS.


General Configuration


To use this function, you'll need to write a script to convert Gregorian calendar to your local calendar. You have to make php file for it, name it to: "local.date.php" and also name the converter function : "local_date" and place it in your local language folder directory. So this is the path to you script file:




ICMS_ROOT_PATH/language/your_local_language/local.date.php




To have an example of how this script should look like, I bring an example of what we have in the core:


/** * This function is to convert date() function outputs into local values * * @copyright http://www.impresscms.org/ The ImpressCMS Project * @since 1.1.1 * @author Sina Asghari (aka stranger) */ function ext_date($type,$maket="now") { global $xoopsConfig; icms_loadLanguageFile('core', 'calendar'); $result=""; if($maket=="now"){ $year=date("Y"); $month=date("m"); $day=date("d"); $maket=mktime(date("H"), date("i"), date("s"), $month, $day, $year);; }else{ $date=date("Y-m-d",$maket); list( $year, $month, $day ) = preg_split ( '/-/', $date ); } $need= $maket; $year=date("Y",$need); $month=date("n",$need); $day=date("j",$need); $i=0; while($i<10) $result1="0".$day; else $result1=$day; $result.=$result1; break; case "D": $result1=date("D",$need); if($result1=="Sat") $result1=_CAL_SAT; else if($result1=="Sun") $result1=_CAL_SUN; else if($result1=="Mon") $result1=_CAL_MON; else if($result1=="Tue") $result1=_CAL_TUE; else if($result1=="Wed") $result1=_CAL_WED; else if($result1=="Thu") $result1=_CAL_THU; else if($result1=="Fri") $result1=_CAL_FRI; $result.=$result1; break; case"F": $result.=Icms_getMonthNameById($month); break; case "g": $result.=date("g",$need); break; case "G": $result.=date("G",$need); break; case "h": $result.=date("h",$need); break; case "H": $result.=date("H",$need); break; case "i": $result.=date("i",$need); break; case "j": $result.=$day; break; case "l": $result1=date("l",$need); if($result1=="Saturday") $result1=_CAL_SATURDAY; else if($result1=="Sunday") $result1=_CAL_SUNDAY; else if($result1=="Monday") $result1=_CAL_MONDAY; else if($result1=="Tuesday") $result1=_CAL_TUESDAY; else if($result1=="Wednesday") $result1=_CAL_WEDNESDAY; else if($result1=="Thursday") $result1=_CAL_THURSDAY; else if($result1=="Friday") $result1=_CAL_FRIDAY; $result.=$result1; break; case "m": if($month<10) $result1="0".$month; else $result1=$month; $result.=$result1; break; case "M": $result.=Icms_getMonthNameById($month); break; case "n": $result.= $month; break; case "s": $result.=date("s",$need); break; case "S": $result.=_CAL_SUFFIX; break; case "t": $result.=date("t",$need); break; case "w": $result.=date("w",$need); break; case "y": $result.=substr($year,2,4); break; case "Y": $result.=$year; break; default: $result.=$subtype; } $i++; } return $result; } This is basic function to convert some of outputs to local synonyms! another example can be what we are using for Jalali calendar: function jdate($type,$maket="now") { global $xoopsConfig; icms_loadLanguageFile('core', 'calendar'); $result=""; if($maket=="now"){ $year=date("Y"); $month=date("m"); $day=date("d"); list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day); $maket=jmaketime(date("h"),date("i"),date("s"),$jmonth,$jday,$jyear); }else{ $date=date("Y-m-d",$maket); list( $year, $month, $day ) = preg_split ( '/-/', $date ); list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day); } $need= $maket; $year=date("Y",$need); $month=date("m",$need); $day=date("d",$need); $i=0; while($i<10)$result1="0".$jday; else $result1=$jday; $result.=$result1; break; case "D": $result1=date("D",$need); if($result1=="Sat") $result1=_CAL_SAT; else if($result1=="Sun") $result1=_CAL_SUN; else if($result1=="Mon") $result1=_CAL_MON; else if($result1=="Tue") $result1=_CAL_TUE; else if($result1=="Wed") $result1=_CAL_WED; else if($result1=="Thu") $result1=_CAL_THU; else if($result1=="Fri") $result1=_CAL_FRI; $result.=$result1; break; case"F": list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day); $result.=Icms_getMonthNameById($jmonth); break; case "g": $result.=date("g",$need); break; case "G": $result.=date("G",$need); break; case "h": $result.=date("h",$need); break; case "H": $result.=date("H",$need); break; case "i": $result.=date("i",$need); break; case "j": list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day); $result.=$jday; break; case "l": $result1=date("l",$need); if($result1=="Saturday") $result1=_CAL_SATURDAY; else if($result1=="Sunday") $result1=_CAL_SUNDAY; else if($result1=="Monday") $result1=_CAL_MONDAY; else if($result1=="Tuesday") $result1=_CAL_TUESDAY; else if($result1=="Wednesday") $result1=_CAL_WEDNESDAY; else if($result1=="Thursday") $result1=_CAL_THURSDAY; else if($result1=="Friday") $result1=_CAL_FRIDAY; $result.=$result1; break; case "m": list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day); if($jmonth<10) $result1="0".$jmonth; else $result1=$jmonth; $result.=$result1; break; case "M": list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day); $result.=Icms_getMonthNameById($jmonth); break; case "n": list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day); $result.=$jmonth; break; case "s": $result.=date("s",$need); break; case "S": $result.=_CAL_SUFFIX; break; case "t": $result.=lastday ($month,$day,$year); break; case "w": $result.=date("w",$need); break; case "y": list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day); $result.=substr($jyear,2,4); break; case "Y": list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day); $result.=$jyear; break; default: $result.=$subtype; } $i++; } return $result; }


Preferences


In order to define this, after making the script and moving it to the right place, you have to go in administrator panel --> preferences --> General Settings and change "Do you want to use an extended/local calendar set?" to YES.


Appearings


By going these steps, your calendar&date function will change from Gregorian to your native calendar. Please note: if you want to use this on a multi-language website, you'll need to copy "ext_date_function.php" under any running language on your site. If any of these steps is going wrong, you'll just receive the Gregorian calendar back.

Last modified on 2010/11/13 by Anonymous
Comments
The comments are owned by the poster. We aren't responsible for their content.