Advertisement:

Author Topic: Relative Dates  (Read 32806 times)

Offline samborabora

  • Full Member
  • ***
  • Posts: 517
Re: Relative Dates
« Reply #60 on: June 15, 2014, 02:00:17 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?

Online vbgamer45

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 23,475
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Relative Dates
« Reply #61 on: June 15, 2014, 02:23:36 PM »
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

Offline samborabora

  • Full Member
  • ***
  • Posts: 517
Re: Relative Dates
« Reply #62 on: June 15, 2014, 04:40:52 PM »
Check the code easy to see
Can you be more descriptive/helpful, please?

Online vbgamer45

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 23,475
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Relative Dates
« Reply #63 on: June 15, 2014, 11:38:48 PM »
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

Offline Hj Ahmad Rasyid Hj Ismail

  • SMF Hero
  • ******
  • Posts: 4,905
  • Gender: Male
  • Busy mode is on.
    • ahmad.rasyid.ismail on Facebook
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • @ahrasis on Twitter
    • ElkArte Malaysia
Re: Relative Dates
« Reply #64 on: July 13, 2014, 09:37:09 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.

Offline samborabora

  • Full Member
  • ***
  • Posts: 517
Re: Relative Dates
« Reply #65 on: July 14, 2014, 02:57:58 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?

Offline margarett

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,759
  • Gender: Male
Re: Relative Dates
« Reply #66 on: July 14, 2014, 03:00:28 PM »
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

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

Offline Hj Ahmad Rasyid Hj Ismail

  • SMF Hero
  • ******
  • Posts: 4,905
  • Gender: Male
  • Busy mode is on.
    • ahmad.rasyid.ismail on Facebook
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • @ahrasis on Twitter
    • ElkArte Malaysia
Re: Relative Dates
« Reply #67 on: July 14, 2014, 07:21:14 PM »
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.

Offline live627

  • Developer
  • SMF Hero
  • *
  • Posts: 5,918
  • Gender: Male
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Relative Dates
« Reply #68 on: July 14, 2014, 09:26:45 PM »
Quote
vbgamer'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.

Offline Hj Ahmad Rasyid Hj Ismail

  • SMF Hero
  • ******
  • Posts: 4,905
  • Gender: Male
  • Busy mode is on.
    • ahmad.rasyid.ismail on Facebook
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • @ahrasis on Twitter
    • ElkArte Malaysia
Re: Relative Dates
« Reply #69 on: July 14, 2014, 09:42:32 PM »
May be you should have it back. After all, there are already requests for it to be updated / rewritten.

Offline confuseamuse

  • Jr. Member
  • **
  • Posts: 145
Re: Relative Dates
« Reply #70 on: July 18, 2018, 06:38:27 AM »
Is this mod still under development? Possibility for a 2.1 version after beta?

Offline Wellwisher

  • Full Member
  • ***
  • Posts: 448
  • Gender: Male
Re: Relative Dates
« Reply #71 on: January 25, 2021, 10:45:31 PM »
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?

Online vbgamer45

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 23,475
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Relative Dates
« Reply #72 on: January 25, 2021, 10:52:11 PM »
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

Offline Wellwisher

  • Full Member
  • ***
  • Posts: 448
  • Gender: Male
Re: Relative Dates
« Reply #73 on: January 25, 2021, 11:11:42 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)

Offline live627

  • Developer
  • SMF Hero
  • *
  • Posts: 5,918
  • Gender: Male
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Relative Dates
« Reply #74 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.

Offline Wellwisher

  • Full Member
  • ***
  • Posts: 448
  • Gender: Male
Re: Relative Dates
« Reply #75 on: January 27, 2021, 01:22:08 AM »
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:


Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 60,218
  • Gender: Male
    • Kindred-999 on GitHub
Re: Relative Dates
« Reply #76 on: January 27, 2021, 03:24:47 PM »
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)
« Last Edit: February 25, 2021, 04:17:47 PM by Kindred »
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."

Online vbgamer45

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 23,475
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Relative Dates
« Reply #77 on: January 27, 2021, 03:34:25 PM »
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

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 60,218
  • Gender: Male
    • Kindred-999 on GitHub
Re: Relative Dates
« Reply #78 on: January 27, 2021, 03:37:00 PM »
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.
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."

Online vbgamer45

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 23,475
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Relative Dates
« Reply #79 on: January 27, 2021, 03:49:19 PM »
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