News:

Wondering if this will always be free?  See why free is better.

Main Menu

Relative Dates

Started by vbgamer45, February 07, 2010, 11:32:08 PM

Previous topic - Next topic

Wellwisher

Quote from: Kindred on January 27, 2021, 03:24:47 PM
You want *ALL* dates to be relative?

@Kindred, this looks sexy. 8). This works for me folks. Thank you Kindred, this will help a lot of lost souls.  :laugh:

I still want to introduce the "on-hover tool tip" feature which reveals the full date & time. Anyway we can add this? I can then work out the .JS and the .CSS required to achieve it.






Kindred

that becomes more difficult --- in that the function would have to be modified to output two values (the relative and the absolute) *AND* every location which calls the timeformat function would have to be modified to accept that changed output.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Wellwisher

Quote from: Kindred on January 28, 2021, 09:46:20 AM
that becomes more difficult --- in that the function would have to be modified to output two values (the relative and the absolute) *AND* every location which calls the timeformat function would have to be modified to accept that changed output.

Thanks for heads-up Kindred, appreciate the helpful advice. I might get a freelancer to take a look into this at some point. If I do, I will share the code here or in the tips & tricks section.   8)

Kindred

Looking into this a little bit more -- my changes above will also have a possibly unintended side-effect -- it will also affect the display of the event in messages with linked calendar events as well as Polls and "edited by" notations...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Wellwisher

Quote from: Kindred on January 28, 2021, 12:28:23 PM
Looking into this a little bit more -- my changes above will also have a possibly unintended side-effect -- it will also affect the display of the event in messages with linked calendar events as well as Polls and "edited by" notations...


No worries, thanks for letting me know Kindred.

Senkusha

Quote from: Kindred on January 27, 2021, 03:24:47 PMYou want *ALL* dates to be relative?



Instead of doing the Subs.php and modifications.english.php edits that this mod originally suggested...
comment out or delete these lines.

Code ("find this in Subs.php") Select
// Today and Yesterday?
if ($modSettings['todayMod'] >= 1 && $show_today === true)
{
// Get the current time.
$nowtime = forum_time();

$then = @getdate($time);
$now = @getdate($nowtime);

// Try to make something of a time format string...
$s = strpos($user_info['time_format'], '%S') === false ? '' : ':%S';
if (strpos($user_info['time_format'], '%H') === false && strpos($user_info['time_format'], '%T') === false)
{
$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
$today_fmt = $h . ':%M' . $s . ' %p';
}
else
$today_fmt = '%H:%M' . $s;

// Same day of the year, same year.... Today!
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);

// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
}

Code ("replace the above code with this") Select
$nowtime = forum_time(); 
$retVal = time_ago($nowtime, $time);

return $retVal;

Code ("add the follow to the end of Subs.php") Select
function time_ago($now, $then)
    {
    global $txt;
 
        if(!is_numeric($then))
            $then = strtotime($then);

        $periods_sing = array($txt['rel_second'], $txt['rel_minute'], $txt['rel_hour'], $txt['rel_day'], $txt['rel_week'], $txt['rel_month'], $txt['rel_year'], $txt['rel_age']);
        $periods_plur = array($txt['rel_seconds'], $txt['rel_minutes'], $txt['rel_hours'], $txt['rel_days'], $txt['rel_weeks'], $txt['rel_months'], $txt['rel_years'], $txt['rel_ages']);
        $lengths = array("60","60","24","7","4.35","12","100");

        $difference = $now - $then;
        if ($difference <= 10 && $difference >= 0)
            return $tense = $txt['just_now'];
        elseif($difference > 0)
            $tense = $txt['ago'];
        elseif($difference < 0)
            $tense = $txt['later'];

        for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
            $difference /= $lengths[$j];
        }

        $difference = round($difference);

        if ($difference > 1)
          $period = $periods_plur[$j];
        else
          $period = $periods_sing[$j];

        return "{$difference} {$period} {$tense} ";
    }

Code ("add the following to Modifications.English.php") Select

$txt['just_now'] = 'just now';
$txt['ago'] = 'ago';
$txt['later'] = 'later';
$txt['rel_second'] = 'second';
$txt['rel_minute'] = 'minute';
$txt['rel_hour'] = 'hour';
$txt['rel_day'] = 'day';
$txt['rel_week'] = 'week';
$txt['rel_month'] = 'month';
$txt['rel_year'] = 'year';
$txt['rel_age'] = 'age';
$txt['rel_seconds'] = 'seconds';
$txt['rel_minutes'] = 'minutes';
$txt['rel_hours'] = 'hours';
$txt['rel_days'] = 'days';
$txt['rel_weeks'] = 'weeks';
$txt['rel_months'] = 'months';
$txt['rel_years'] = 'years';
$txt['rel_ages'] = 'ages';
$txt['relative_today'] = 'All times are Relative';



(Edit -- do note that my code changes above will install the relative dates/times REGARDLESS of the setting in the admin. The code I put together was a hack to REPLACE, not add an option, to the current code)

Is this the code that I would need to use to enable this MOD to work with 2.1.x?
--Senkusha
The Anime Brigade
Anime-style Role Playing Games and Discussion.
(SMF v. 2.1.4, PHP v. 8.0)

Pipke

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Senkusha

Thank you!  I don't know why this didn't come up with I tried looking for it.
--Senkusha
The Anime Brigade
Anime-style Role Playing Games and Discussion.
(SMF v. 2.1.4, PHP v. 8.0)

live627

Quote from: Senkusha on December 07, 2023, 10:14:19 AMIs this the code that I would need to use to enable this MOD to work with 2.1.x?
No. Some of this code does not exist in 2.1.

Advertisement: