Ameer Hassan
May 31, 2016, 12:22 PM
Hi Everyone,
I Have made Time Date For 2 language English and Arabic and Want to Share with You Here :)
Here Are The Steps:-
1.Go To ----> public_html/libs/smarty/plugins
And Create file called >>modifier.timeAgo.php<< "note: you can create another one for other language as i did >>modifier.timeAgo-ar.php <<
Then edit file and paste this code inside it :-
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty date modifier plugin
* Purpose: converts unix timestamps or datetime strings to words
* Type: modifier<br>
* Name: timeAgo<br>
* @author Stephan Otto
* @param string
* @return string
*/
function smarty_modifier_timeAgo( $date)
{
// for using it with preceding 'vor' index
$timeStrings = array( 'recently', // 0 <- now or future posts :-)
'second', 'second', // 1,1
'Minute','Minute', // 3,3
'hour', 'hour', // 5,5
'day', 'day', // 7,7
'week', 'week', // 9,9
'month', 'month', // 11,12
'year','year'); // 13,14
$debug = false;
$sec = time() - (( strtotime($date)) ? strtotime($date) : $date);
if ( $sec <= 0) return $timeStrings[0];
if ( $sec < 2) return $sec." ".$timeStrings[1];
if ( $sec < 60) return $sec." ".$timeStrings[2];
$min = $sec / 60;
if ( floor($min+0.5) < 2) return floor($min+0.5)." ".$timeStrings[3];
if ( $min < 60) return floor($min+0.5)." ".$timeStrings[4];
$hrs = $min / 60;
echo ($debug == true) ? "hours: ".floor($hrs+0.5)."<br />" : '';
if ( floor($hrs+0.5) < 2) return floor($hrs+0.5)." ".$timeStrings[5];
if ( $hrs < 24) return floor($hrs+0.5)." ".$timeStrings[6];
$days = $hrs / 24;
echo ($debug == true) ? "days: ".floor($days+0.5)."<br />" : '';
if ( floor($days+0.5) < 2) return floor($days+0.5)." ".$timeStrings[7];
if ( $days < 7) return floor($days+0.5)." ".$timeStrings[8];
$weeks = $days / 7;
echo ($debug == true) ? "weeks: ".floor($weeks+0.5)."<br />" : '';
if ( floor($weeks+0.5) < 2) return floor($weeks+0.5)." ".$timeStrings[9];
if ( $weeks < 4) return floor($weeks+0.5)." ".$timeStrings[10];
$months = $weeks / 4;
if ( floor($months+0.5) < 2) return floor($months+0.5)." ".$timeStrings[11];
if ( $months < 12) return floor($months+0.5)." ".$timeStrings[12];
$years = $weeks / 51;
if ( floor($years+0.5) < 2) return floor($years+0.5)." ".$timeStrings[13];
return floor($years+0.5)." ".$timeStrings[14];
}
?>
2.Now go to Use This to call the listing date in tpl file --> to Get Full Time use this
{$listing_data.Date|date_format:$smarty.const.RL_D ATE_FORMAT} - {$listing_data.Date|timeAgo} ago
And if you want just Time Ago from posting ad use this only:-
{$listing_data.Date|timeAgo} ago
3.This one used in listing detail block for category listing block or listing.tpl just use this:
Added: {$listing.Date|timeAgo} ago
Hope everyone be happy :)
My Regards
Ameer
I Have made Time Date For 2 language English and Arabic and Want to Share with You Here :)
Here Are The Steps:-
1.Go To ----> public_html/libs/smarty/plugins
And Create file called >>modifier.timeAgo.php<< "note: you can create another one for other language as i did >>modifier.timeAgo-ar.php <<
Then edit file and paste this code inside it :-
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty date modifier plugin
* Purpose: converts unix timestamps or datetime strings to words
* Type: modifier<br>
* Name: timeAgo<br>
* @author Stephan Otto
* @param string
* @return string
*/
function smarty_modifier_timeAgo( $date)
{
// for using it with preceding 'vor' index
$timeStrings = array( 'recently', // 0 <- now or future posts :-)
'second', 'second', // 1,1
'Minute','Minute', // 3,3
'hour', 'hour', // 5,5
'day', 'day', // 7,7
'week', 'week', // 9,9
'month', 'month', // 11,12
'year','year'); // 13,14
$debug = false;
$sec = time() - (( strtotime($date)) ? strtotime($date) : $date);
if ( $sec <= 0) return $timeStrings[0];
if ( $sec < 2) return $sec." ".$timeStrings[1];
if ( $sec < 60) return $sec." ".$timeStrings[2];
$min = $sec / 60;
if ( floor($min+0.5) < 2) return floor($min+0.5)." ".$timeStrings[3];
if ( $min < 60) return floor($min+0.5)." ".$timeStrings[4];
$hrs = $min / 60;
echo ($debug == true) ? "hours: ".floor($hrs+0.5)."<br />" : '';
if ( floor($hrs+0.5) < 2) return floor($hrs+0.5)." ".$timeStrings[5];
if ( $hrs < 24) return floor($hrs+0.5)." ".$timeStrings[6];
$days = $hrs / 24;
echo ($debug == true) ? "days: ".floor($days+0.5)."<br />" : '';
if ( floor($days+0.5) < 2) return floor($days+0.5)." ".$timeStrings[7];
if ( $days < 7) return floor($days+0.5)." ".$timeStrings[8];
$weeks = $days / 7;
echo ($debug == true) ? "weeks: ".floor($weeks+0.5)."<br />" : '';
if ( floor($weeks+0.5) < 2) return floor($weeks+0.5)." ".$timeStrings[9];
if ( $weeks < 4) return floor($weeks+0.5)." ".$timeStrings[10];
$months = $weeks / 4;
if ( floor($months+0.5) < 2) return floor($months+0.5)." ".$timeStrings[11];
if ( $months < 12) return floor($months+0.5)." ".$timeStrings[12];
$years = $weeks / 51;
if ( floor($years+0.5) < 2) return floor($years+0.5)." ".$timeStrings[13];
return floor($years+0.5)." ".$timeStrings[14];
}
?>
2.Now go to Use This to call the listing date in tpl file --> to Get Full Time use this
{$listing_data.Date|date_format:$smarty.const.RL_D ATE_FORMAT} - {$listing_data.Date|timeAgo} ago
And if you want just Time Ago from posting ad use this only:-
{$listing_data.Date|timeAgo} ago
3.This one used in listing detail block for category listing block or listing.tpl just use this:
Added: {$listing.Date|timeAgo} ago
Hope everyone be happy :)
My Regards
Ameer