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

samborabora

Quote from: vbgamer45 on June 15, 2014, 01:08:32 PM
No rewrite planned.

How is the mod structured? Just wondering how it's been designed in such a way that further lengths of date couldn't be added simply by extending the mod to replace > a month/ > a year with friendly text?

vbgamer45

Check the code easy to see
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

samborabora

Quote from: vbgamer45 on June 15, 2014, 02:23:36 PM
Check the code easy to see
Can you be more descriptive/helpful, please?

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Hj Ahmad Rasyid Hj Ismail

Quote from: samborabora on June 13, 2014, 02:37:20 PM
Love this mod, but can we have it so that it has things like "about a month ago" and "about a a year ago" rather than defaulting to, say, June 12, 2014, 10:52:15 AM if there isn't anything within a recent timeframe? Or can I add this myself somehow?

I already wrote a similar mod which is pending approval. You can have a try from my github repository https://github.com/ahrasis/Improved-Displayed-Times-Mod.

samborabora

Quote from: ahrasis on July 13, 2014, 09:37:09 PM
Quote from: samborabora on June 13, 2014, 02:37:20 PM
Love this mod, but can we have it so that it has things like "about a month ago" and "about a a year ago" rather than defaulting to, say, June 12, 2014, 10:52:15 AM if there isn't anything within a recent timeframe? Or can I add this myself somehow?

I already wrote a similar mod which is pending approval. You can have a try from my github repository https://github.com/ahrasis/Improved-Displayed-Times-Mod.

This works really well so far, I can't believe this happened, I'm so impressed! One question, when I return to the forum after making a test post, it shows non-relative times, is this a cache issue? Also, topics and posts made before I uninstalled the old relative times and installed your new one say things like "5 days ago at 06:43:29 PM", is it supposed to have the "at 06:43:29 PM" part, or is this because they were posted without your mod installed? Is there a way of changing this so all posts show your relative times?

margarett

Please don't discuss this here. This topic is for discussion of vbgamer's MOD.

ahrasis's MOD is being reviewed and, when finished, it will have its own support topic. If you wish to discuss it now, please use Github's issues tracker.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Hj Ahmad Rasyid Hj Ismail

I am opening another topic in Coding Discussion pending the approval of my Improved Displayed Times Mod. Interested parties can go here: http://www.simplemachines.org/community/index.php?topic=525151.new#new.

live627

Quotevbgamer's MOD
Actually, I wrote it, gave it to Runic who then "sold" it to vb, who went quiet after I told him that I wanted it back.

Hj Ahmad Rasyid Hj Ismail

May be you should have it back. After all, there are already requests for it to be updated / rewritten.

confuseamuse

Is this mod still under development? Possibility for a 2.1 version after beta?

Wellwisher

Fantastic mod. I tested it and it works for the most part but doesn't convert the older dates to the more "Relative dates" as shown in this picture.

Is there a way to convert older dates to the new format?

vbgamer45

What would you want the date to show?
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Wellwisher

Quote from: vbgamer45 on January 25, 2021, 10:52:11 PM
What would you want the date to show?

"X Years ago"  ::)

Would be nice too see a further break down of timestamps such as:

X Days ago
X Weeks ago
X Months ago
X Years ago

It would be epic to have this on 2.1 too!   8)

live627

I wrote it in a specific way to only handle today and (I think) yesterday. That said, making it cover more general dates shouldn't be too hard. Mostly moving it outside of a check to find today.

It needs rewritten anyway to support better i18n.

Wellwisher

Quote from: live627 on January 26, 2021, 04:41:02 PM
I wrote it in a specific way to only handle today and (I think) yesterday. That said, making it cover more general dates shouldn't be too hard. Mostly moving it outside of a check to find today.

It needs rewritten anyway to support better i18n.

It might be worth looking into a text only 'tool tip' hover too. For example, if a user hovers overs the shortened time, it reveals the full date & time. It looks kinda cool, great for mobile devices and it declutters the screen. This mod would appeal to more people. For example:


Kindred

#76
You 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)
Сл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."

vbgamer45

Interesting I don't understand the months calculation says 4.35
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Kindred

on average 4.35 weeks per month?


edit... yup
Quote
The average number of weeks in a month is 4.345. Each month has at least 4 full weeks. But as we all know, some months have 1, 2, or 3 days extra.
Сл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."

vbgamer45

Interesting learn something new.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Advertisement: