Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • nexusict Friend
    #1075185

    I would like to display the time elapsed since and article was posted by subtracting it from the current time. Any suggesstion?

    Saguaros Moderator
    #1075354

    Any sample of date format that you’re mentioning?

    nexusict Friend
    #1075359

    Hello, thank you for fast reply. Elapsed time from publish article time. If article was published 2 hours ago, I need that time to visible (hours, minutes)

    Saguaros Moderator
    #1075556

    Hi,

    You will need some customization to achieve that. Here is my tweak:
    1) Go to file: [root]/templates/ja_teline_v/helper.php

    Add a new function called relTime:

    public static function relTime($timespan, $granularity = 1) {
        static $units = array(
          'YEAR' => 31536000,
          'MONTH' => 2592000,
          'WEEK' => 604800,
          'DAY' => 86400,
          'HOUR' => 3600,
          'MIN' => 60,
          'SEC' => 1,
        );
    
        $output = '';
        if(!ctype_digit($timespan)){
          $timespan = strtotime($timespan);
        }
    
          $interval = time() - $timespan;
    
          $future = $interval < 0;
          if($future){
            $interval = abs($interval);
          }
    
        foreach ($units as $key => $value) {
          if ($interval >= $value) {
            $output .= ($output ? ' ' : '') . JText::sprintf('TPL_RT_' . $key . (floor($interval / $value) != 1 ? 'S' : ''), floor($interval / $value));
            $interval %= $value;
            $granularity--;
          }
    
          if ($granularity == 0) {
            break;
          }
        }
    
        return $output ? JText::sprintf($future ? 'TPL_RT_FUTURE' : 'TPL_RT_PAST', $output) : JText::_('TPL_RT_NOW');
        }

    It looks like this: http://prntscr.com/hd59dh

    2) Open the file: [root]/templates/ja_teline_v/html/layouts/joomla/content/info_block/publish_date.php

    Under the time tag, change it to:

    <time datetime="<?php echo JHtml::_('date', $displayData['item']->publish_up, 'c'); ?>" itemprop="datePublished">
        <?php echo JATemplateHelper::relTime($displayData['item']->publish_up); ?>
        <?php echo $displayData['item']->publish_up ?>
    </time>

    http://prntscr.com/hd5a3b

    3) Go to language file of template: [root]/language/en-GB/en-GB.tpl_ja_teline_v.ini

    Add these language text:

    TPL_RT_FUTURE     ="in %s"
    TPL_RT_PAST       ="%s ago"
    TPL_RT_NOW        ="just now"
    TPL_RT_YEAR       ="1 year"
    TPL_RT_YEARS      ="%d years"
    TPL_RT_MONTH      ="1 month"
    TPL_RT_MONTHS     ="%d months"
    TPL_RT_WEEK       ="1 week"
    TPL_RT_WEEKS      ="%d weeks"
    TPL_RT_DAY        ="1 day"
    TPL_RT_DAYS       ="%d days"
    TPL_RT_HOUR       ="1 hour"
    TPL_RT_HOURS      ="%d hours"
    TPL_RT_MIN        ="1 min"
    TPL_RT_MINS       ="%d mins"
    TPL_RT_SEC        ="1 sec"
    TPL_RT_SECS       ="%d secs"

    http://prntscr.com/hd5a7i

Viewing 4 posts - 1 through 4 (of 4 total)

This topic contains 3 replies, has 2 voices, and was last updated by  Saguaros 6 years, 12 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum