Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: vbgamer45 on February 07, 2010, 11:32:08 PM

Title: Relative Dates
Post by: vbgamer45 on February 07, 2010, 11:32:08 PM
Link to Mod (https://custom.simplemachines.org/mods/index.php?mod=2432)

Relative Dates


Original Author:live627 (http://www.simplemachines.org/community/index.php?action=profile;u=154736)
SMF Version: 2.0.X
Mod Version: 1.3

Description:
This mod, when enabled, converts the usual date displays for posts with a relative one, such as 2 minutes ago, 7 hours ago, etc.

It isn't on by default; setting is in AdminCP => Features and Options => Layout.

Changelog
Version 1.3
! Taken over by Runic
! Updated for 2.0.x
- Removed support for 1.1

Version 1.2
! Should be 0 seconds ago, not in 0 seconds
* Commenazi
+ Silently disables itself in XML mode. To turn it back on in XML, read my post.
* Converting all line endings to LF

Version 1.1
+ Added 1.1.x support
! Fixed vanishing "ago"
! Fixed future "negative" date bug
+ Extends relativity into the future, i.e, tomorrow


Legend:
--------------------------------------------------------------------------------
! Minor change or bugfix
* Feature edit
& Known bug
+ Feature addition
- Feature removal

Why Not Visit:
http://www.smfhacks.com (http://www.smfhacks.com)
Title: Re: Relative Dates
Post by: Tanks on February 08, 2010, 02:31:03 AM
I don't think it works on my 2.0 RC2

It says: 1453 seconds ago , by Knat Simon
Title: Re: Relative Dates
Post by: live627 on February 09, 2010, 12:05:01 PM
Hmm, thanks for pointing that out. I fixed the problem and reuploaded it
Title: Re: Relative Dates
Post by: sAce on February 10, 2010, 03:03:14 AM
nice mod live, good work
Title: Re: Relative Dates
Post by: Tanks on February 10, 2010, 05:40:45 AM
That fixed it, but i still see something that i think is wrong.

1. Minutes ago is right, hours ago is right, but 1 hour ago is missing the "ago"

2. It should be bold like the today and yesterday is.

Could you fix these two things then i would love to use your mod.

Cheers, and thanks :)
Title: Re: Relative Dates
Post by: Bugo on February 10, 2010, 08:20:44 AM
What's the problem? (see attachment)
Title: Re: Relative Dates
Post by: Bugo on February 10, 2010, 08:22:05 AM
Russian translation:


$txt['hours'] = 'часов';
$txt['minutes'] = 'минут';
$txt['seconds'] = 'секунд';
$txt['hour'] = 'час';
$txt['minute'] = 'минута';
$txt['second'] = 'секунда';
$txt['ago'] = 'назад';
$txt['relative_today'] = 'Сегодня с относительным временем';
Title: Re: Relative Dates
Post by: h78509 on February 11, 2010, 05:33:30 PM
I installed this on my 2.0 RC2 Curve but unfortunately there was no option to enable it.
Title: Re: Relative Dates
Post by: live627 on February 11, 2010, 11:46:23 PM
Look at a screenshot on the mod page

It is there for anyone who can read :D
Title: Re: Relative Dates
Post by: Tanks on February 15, 2010, 01:39:46 AM
Hello Live627,

Did you look into the thing in my post above ?
Title: Re: Relative Dates
Post by: TheListener on February 16, 2010, 09:53:57 PM
Great addition Live.

Installed within seconds on the forum.

( Raven Theme)
Title: Re: Relative Dates
Post by: live627 on February 22, 2010, 12:31:41 AM
Update: 1.1 fixes all reported bugs
Title: Re: Relative Dates
Post by: TheListener on February 22, 2010, 09:15:10 PM
Did you try the settings as mentioned in the first post?
Title: Re: Relative Dates
Post by: live627 on February 22, 2010, 09:31:56 PM
Quote from: Bugo link=topic=364742.msg2495393#msg2495393 date=
Russian translation
/quote]

Is it utf8, or otherwise, or both?
Title: Re: Relative Dates
Post by: Bugo on February 23, 2010, 03:56:26 AM
Updated russian translation.
Add this files to install package :)
Title: Re: Relative Dates
Post by: live627 on February 23, 2010, 11:22:14 PM
Thank you Bugo
Title: Re: Relative Dates
Post by: Özgür on February 27, 2010, 12:31:13 PM
Turkish translation
$txt['hours'] = 'saat';
$txt['minutes'] = 'dakika';
$txt['seconds'] = 'saniye';
$txt['hour'] = 'saat';
$txt['minute'] = 'dakika';
$txt['second'] = 'saniye';
$txt['ago'] = 'önce';
$txt['in'] = 'içinde';// need to be test.
$txt['relative_today'] = 'Bugün ve göreceli zamanlar';
Title: Re: Relative Dates
Post by: rahlzel on March 10, 2010, 12:00:27 AM
Still works fine for RC3, though as a new user it was a little difficult to find. You mentioned the Features and Options > Layout section, which is where I found it, but I don't come to this section much so I assumed the default option "Only Today" means it was supposed to be "On".

I almost came here to post a bug report until I happened upon the last setting, "...with relative times", which did the trick.

Great idea for a mod, but you might want to make it a bit simpler to come across. Maybe have it automatically use this setting as soon as it's installed?

Thank you, and well done!
Title: Re: Relative Dates
Post by: Eclipse16V on March 15, 2010, 02:15:42 AM
Nice Mod

Please update it for SMF 2.0RC3  ;)

Thanks
Title: Re: Relative Dates
Post by: Afro on March 15, 2010, 05:14:23 PM
Good Mod.
Weldone.
Title: Re: Relative Dates
Post by: live627 on March 21, 2010, 08:07:39 PM
Quote from: Eclipse16V on March 15, 2010, 02:15:42 AM
Nice Mod

Please update it for SMF 2.0RC3  ;)

Thanks
works as intended in compatibility mode
Title: Re: Relative Dates
Post by: dannbass on June 02, 2010, 01:15:33 AM
There is an issue with Spanish, in order to make it work we would need "ago 15 hours" because it doesn't make that much sense "15 horas hace"
Would you help me reordering this?

// Numbers need language strings, too
            if ($seconds > 0)
            {
               if ($hours > 0 && $minutes > 59)
                  $retVal = $hours . ' ' . ($hours == 1 ? $txt['hour'] : $txt['hours']) . '  ' . $txt['ago'];
               elseif ($minutes > 0 && $seconds > 59)
                  $retVal = $minutes . ' ' . ($minutes == 1 ? $txt['minute'] : $txt['minutes']) . '  ' . $txt['ago'];
               else
                  $retVal = $seconds . ' ' . ($seconds == 1 ? $txt['second'] : $txt['seconds']) . '  ' . $txt['ago'];
            }


Thank you!!
Title: Re: Relative Dates
Post by: live627 on June 05, 2010, 12:42:40 AM
Sorry for the late reply. Here it is.

// Numbers need language strings, too
            if ($seconds > 0)
            {
               if ($hours > 0 && $minutes > 59)
                  $retVal = $txt['ago'] . '  ' . $hours . ' ' . ($hours == 1 ? $txt['hour'] : $txt['hours']);
               elseif ($minutes > 0 && $seconds > 59)
                  $retVal = $txt['ago'] . '  ' . $minutes . ' ' . ($minutes == 1 ? $txt['minute'] : $txt['minutes']);
               else
                  $retVal = $txt['ago'] . '  ' . $seconds . ' ' . ($seconds == 1 ? $txt['second'] : $txt['seconds']);
            }
Title: Re: Relative Dates
Post by: dannbass on June 05, 2010, 01:09:18 AM
Thank you!! that did it!!
Title: Re: Relative Dates
Post by: Neverhurry on June 07, 2010, 05:21:33 PM
I translate the text into Chinese, but i don't know in which file i should put them to. Pls help.
(I install it but it works only in English language) Thanks.


$txt['hours'] = '小时';
$txt['minutes'] = '分';
$txt['seconds'] = '秒';
$txt['hour'] = '小时';
$txt['minute'] = '分';
$txt['second'] = '秒';
$txt['ago'] = '以前';
$txt['in'] = '在';
$txt['relative_today'] = '今天的相对时间';
Title: Re: Relative Dates
Post by: live627 on June 07, 2010, 06:19:56 PM
Not sure, but try index.chinese.php
Title: Re: Relative Dates
Post by: ~DS~ on July 25, 2010, 08:56:15 PM
I am getting some errors in the logs if you are on different languages other than english:
8: Undefined index: ago
File: /Sources/Subs.php
Line: 789


Same line with "8: Undefined index: seconds"
Title: Re: Relative Dates
Post by: live627 on July 25, 2010, 10:15:01 PM
The strings are clearly missing. If, for example, you use Spanish, you'd need to add the respective strings into Modifications.spanish_latin.php.

/me had a first impulse of something sarcastic ::)
Title: Re: Relative Dates
Post by: WasdMan on March 13, 2011, 07:23:41 AM
Addition days: ( install20.xml )

// Same day of the year, same year.... Today!
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
{
// SMF has room for relative dates, no?
if ($modSettings['todayMod'] == 3)
{
// Deetermine the relative dates
$seconds = $nowtime - $time;
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$days = floor($days / 24);

// Numbers need language strings, too
if ($seconds > 0)
{
if ($days > 0 && $hours > 24)
$retVal = $days . ' ' . ($days == 1 ? $txt['day'] : $txt['days']) . '  ' . $txt['ago'];
if ($hours > 0 && $minutes > 59)
$retVal = $hours . ' ' . ($hours == 1 ? $txt['hour'] : $txt['hours']) . '  ' . $txt['ago'];
elseif ($minutes > 0 && $seconds > 59)
$retVal = $minutes . ' ' . ($minutes == 1 ? $txt['minute'] : $txt['minutes']) . '  ' . $txt['ago'];
else
$retVal = $seconds . ' ' . ($seconds == 1 ? $txt['second'] : $txt['seconds']) . '  ' . $txt['ago'];
}
// Time is in the future so rework :P
else
{
$seconds = $time - $nowtime;
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
if ($days > 0 && $hours > 24)
$retVal = $txt['in'] . '  ' . $days . ' ' . ($days == 1 ? $txt['day'] : $txt['days']);
if ($hours > 0 && $minutes > 59)
$retVal = $txt['in'] . '  ' . $hours . ' ' . ($hours == 1 ? $txt['hour'] : $txt['hours']);
elseif ($minutes > 0 && $seconds > 59)
$retVal = $txt['in'] . '  ' . $minutes . ' ' . ($minutes == 1 ? $txt['minute'] : $txt['minutes']);
else
$retVal = $txt['in'] . '  ' . $seconds . ' ' . ($seconds == 1 ? $txt['second'] : $txt['seconds']);
}
}
// Defaults FTW!
else
$retVal = $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);

return $retVal;
}


Addition of language: ( english.xml )


$txt['days'] = 'days';
$txt['hours'] = 'hours';
$txt['minutes'] = 'minutes';
$txt['seconds'] = 'seconds';
$txt['day'] = 'day';
$txt['hour'] = 'hour';
$txt['minute'] = 'minute';
$txt['second'] = 'second';
$txt['ago'] = 'ago';
$txt['in'] = 'in';
$txt['relative_today'] = 'Today with relative times';
Title: Re: Relative Dates
Post by: Biology Forums on May 14, 2011, 06:01:25 PM
Is there a way of including both relative dates of today and the word "yesterday" for anything older than a day but less than 48 hours?
Title: Re: Relative Dates
Post by: Biology Forums on May 14, 2011, 06:26:54 PM
Got it to work, simply:

Find
// SMF has room for relative dates, no?
if ($modSettings['todayMod'] == 3)


Replace with:
// SMF has room for relative dates, no?
if ($modSettings['todayMod'] == 2)
Title: Re: Relative Dates
Post by: WasdMan on August 10, 2011, 08:35:31 AM
I attached the Hungarian language.
Title: Re: Relative Dates
Post by: SilverKnight on March 10, 2012, 02:52:12 AM
Great Mod, just what i was searching for. Can you make it so it also takes into consideration weeks and months as well?

So 2 days ago, 2 weeks ago, 1 month ago etc.
Title: Re: Relative Dates
Post by: Jessica. on March 10, 2012, 01:34:05 PM
Quote from: SilverKnight on March 10, 2012, 02:52:12 AM
Great Mod, just what i was searching for. Can you make it so it also takes into consideration weeks and months as well?

So 2 days ago, 2 weeks ago, 1 month ago etc.

eh no I don't want that
Title: Re: Relative Dates
Post by: Biology Forums on March 10, 2012, 06:45:36 PM
Quote from: SilverKnight on March 10, 2012, 02:52:12 AM
Great Mod, just what i was searching for. Can you make it so it also takes into consideration weeks and months as well?

So 2 days ago, 2 weeks ago, 1 month ago etc.

It shouldn't be too difficult to put together, all you'd need is the mathematics formula to calculate how many seconds are in a week, month, year, etc.
Title: Re: Relative Dates
Post by: SilverKnight on March 11, 2012, 09:12:26 PM
Has anyone noticed this mod being buggy? Such as relative time randomly disappearing and being replaced by old date, so even if something was posted a few minutes ago it defaults back? It's really weird and annoying to go from minutes to date of the day.
Title: Re: Relative Dates
Post by: Biology Forums on March 11, 2012, 09:55:32 PM
Quote from: SilverKnight on March 11, 2012, 09:12:26 PM
Has anyone noticed this mod being buggy? Such as relative time randomly disappearing and being replaced by old date, so even if something was posted a few minutes ago it defaults back? It's really weird and annoying to go from minutes to date of the day.

Never happened to me :-\
Title: Re: Relative Dates
Post by: SilverKnight on March 11, 2012, 10:52:12 PM
Quote from: WasdMan on March 13, 2011, 07:23:41 AM
-snip-

Good addition.
Title: Re: Relative Dates
Post by: live627 on March 11, 2012, 10:58:41 PM
Quote from: Liam_michael on March 11, 2012, 09:55:32 PM
Quote from: SilverKnight on March 11, 2012, 09:12:26 PM
Has anyone noticed this mod being buggy? Such as relative time randomly disappearing and being replaced by old date, so even if something was posted a few minutes ago it defaults back? It's really weird and annoying to go from minutes to date of the day.

Never happened to me :-\
Me neither, and  I have ~60 mods installed.

Quote from: SilverKnight on March 11, 2012, 10:52:12 PM
Quote from: WasdMan on March 13, 2011, 07:23:41 AM-snip-

Good addition.
It won't  work, though.
Title: Re: Relative Dates
Post by: SilverKnight on March 11, 2012, 11:12:50 PM
Sadly it doesn't, just tested it, could you add a days feature to the mod that does work?

-snip- It's working properly now.
Title: Re: Relative Dates
Post by: ocmdiaz714 on August 23, 2012, 04:10:26 PM
Quote from: WasdMan on March 13, 2011, 07:23:41 AM
Addition days: ( install20.xml )

// Same day of the year, same year.... Today!
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
{
// SMF has room for relative dates, no?
if ($modSettings['todayMod'] == 3)
{
// Deetermine the relative dates
$seconds = $nowtime - $time;
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$days = floor($days / 24);

// Numbers need language strings, too
if ($seconds > 0)
{
if ($days > 0 && $hours > 24)
$retVal = $days . ' ' . ($days == 1 ? $txt['day'] : $txt['days']) . '  ' . $txt['ago'];
if ($hours > 0 && $minutes > 59)
$retVal = $hours . ' ' . ($hours == 1 ? $txt['hour'] : $txt['hours']) . '  ' . $txt['ago'];
elseif ($minutes > 0 && $seconds > 59)
$retVal = $minutes . ' ' . ($minutes == 1 ? $txt['minute'] : $txt['minutes']) . '  ' . $txt['ago'];
else
$retVal = $seconds . ' ' . ($seconds == 1 ? $txt['second'] : $txt['seconds']) . '  ' . $txt['ago'];
}
// Time is in the future so rework :P
else
{
$seconds = $time - $nowtime;
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
if ($days > 0 && $hours > 24)
$retVal = $txt['in'] . '  ' . $days . ' ' . ($days == 1 ? $txt['day'] : $txt['days']);
if ($hours > 0 && $minutes > 59)
$retVal = $txt['in'] . '  ' . $hours . ' ' . ($hours == 1 ? $txt['hour'] : $txt['hours']);
elseif ($minutes > 0 && $seconds > 59)
$retVal = $txt['in'] . '  ' . $minutes . ' ' . ($minutes == 1 ? $txt['minute'] : $txt['minutes']);
else
$retVal = $txt['in'] . '  ' . $seconds . ' ' . ($seconds == 1 ? $txt['second'] : $txt['seconds']);
}
}
// Defaults FTW!
else
$retVal = $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);

return $retVal;
}


Addition of language: ( english.xml )


$txt['days'] = 'days';
$txt['hours'] = 'hours';
$txt['minutes'] = 'minutes';
$txt['seconds'] = 'seconds';
$txt['day'] = 'day';
$txt['hour'] = 'hour';
$txt['minute'] = 'minute';
$txt['second'] = 'second';
$txt['ago'] = 'ago';
$txt['in'] = 'in';
$txt['relative_today'] = 'Today with relative times';


I went ahead and added the modified bit to my language, and subs file, but nothing. :(

Here's what I have:


// Same day of the year, same year.... Today!
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
{
// SMF has room for relative dates, no?
if ($modSettings['todayMod'] == 3)
{
// Deetermine the relative dates
$seconds = $nowtime - $time;
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$days = floor($hours / 24);

// Numbers need language strings, too
if ($seconds > 0)
{
if ($days > 0 && $hours > 24)
$retVal = $days . ' ' . ($days == 1 ? $txt['day'] : $txt['days']) . '  ' . $txt['ago'];
if ($hours > 0 && $minutes > 59)
$retVal = $hours . ' ' . ($hours == 1 ? $txt['hour'] : $txt['hours']) . '  ' . $txt['ago'];
elseif ($minutes > 0 && $seconds > 59)
$retVal = $minutes . ' ' . ($minutes == 1 ? $txt['minute'] : $txt['minutes']) . '  ' . $txt['ago'];
else
$retVal = $seconds . ' ' . ($seconds == 1 ? $txt['second'] : $txt['seconds']) . '  ' . $txt['ago'];
}
// Time is in the future so rework :P
else
{
$seconds = $time - $nowtime;
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$days = floor($hours / 24);
if ($days > 0 && $hours > 24)
$retVal = $txt['in'] . '  ' . $days . ' ' . ($days == 1 ? $txt['day'] : $txt['days']);
if ($hours > 0 && $minutes > 59)
$retVal = $txt['in'] . '  ' . $hours . ' ' . ($hours == 1 ? $txt['hour'] : $txt['hours']);
elseif ($minutes > 0 && $seconds > 59)
$retVal = $txt['in'] . '  ' . $minutes . ' ' . ($minutes == 1 ? $txt['minute'] : $txt['minutes']);
else
$retVal = $txt['in'] . '  ' . $seconds . ' ' . ($seconds == 1 ? $txt['second'] : $txt['seconds']);
}
}
// Defaults FTW!
else
$retVal = $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);

return $retVal;
}


I think it has something to do with the "if" tags.
EDIT: Also, after making a post I'm shown with a "in 0 seconds" display, is there any way to change to..."just now"? Thanks.
Title: Re: Relative Dates
Post by: ocmdiaz714 on September 01, 2012, 06:18:45 AM
Any update?
Title: Re: Relative Dates
Post by: Rain Forest on September 01, 2012, 02:31:53 PM
Thank you! Im using this mod right now :)
Title: Re: Relative Dates
Post by: ocmdiaz714 on September 01, 2012, 04:41:41 PM
Quote from: Liam_michael on March 10, 2012, 06:45:36 PM
Quote from: SilverKnight on March 10, 2012, 02:52:12 AM
Great Mod, just what i was searching for. Can you make it so it also takes into consideration weeks and months as well?

So 2 days ago, 2 weeks ago, 1 month ago etc.

It shouldn't be too difficult to put together, all you'd need is the mathematics formula to calculate how many seconds are in a week, month, year, etc.

Any idea on how I can add days?
Title: Re: Relative Dates
Post by: Biology Forums on June 08, 2013, 07:19:57 PM
This mod really needs to be updated to include this week, this month, etc.

Anyone interested in this?
Title: Re: Relative Dates
Post by: TheListener on June 08, 2013, 07:21:30 PM
Quote from: Liam_michael on June 08, 2013, 07:19:57 PM
This mod really needs to be updated to include this week, this month, etc.

Anyone interested in this?

Ya know the mods author is the only person whom can do this right?

I use the mod myself and believe it to be perfect as it is.
Title: Re: Relative Dates
Post by: Rain Forest on July 05, 2013, 06:39:18 PM
Is there a way to include this for like 24 hours? :)

What I mean: If I go online at 00:04 the message will say: user x posted at July 05, 2013, 23:57:38

I know it was yesterday but it's only 7 minutes ago :)

Using SMF 2.0.4
Title: Re: Relative Dates
Post by: Deaks on July 05, 2013, 06:46:33 PM
sorry on holiday atm will look at this when i get home
Title: Re: Relative Dates
Post by: Biology Forums on July 05, 2013, 10:40:04 PM
Quote from: 4Three on July 05, 2013, 06:39:18 PM
Is there a way to include this for like 24 hours? :)

What I mean: If I go online at 00:04 the message will say: user x posted at July 05, 2013, 23:57:38

I know it was yesterday but it's only 7 minutes ago :)

Using SMF 2.0.4

I like this idea.
Title: Re: Relative Dates
Post by: live627 on July 06, 2013, 12:41:34 AM
Quote from: Runic on July 05, 2013, 06:46:33 PM
sorry on holiday atm will look at this when i get home

Maybe you also improve i18n handling with sprintf()'s instead of a literal text order.
Title: Re: Relative Dates
Post by: Rain Forest on September 11, 2013, 06:19:32 PM
Quote from: Liam_michael on July 05, 2013, 10:40:04 PM
Quote from: 4Three on July 05, 2013, 06:39:18 PM
Is there a way to include this for like 24 hours? :)

What I mean: If I go online at 00:04 the message will say: user x posted at July 05, 2013, 23:57:38

I know it was yesterday but it's only 7 minutes ago :)

Using SMF 2.0.4

I like this idea.

I hope he can fix it :)
Title: Re: Relative Dates
Post by: 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?
Title: Re: Relative Dates
Post by: Matthew K. on June 13, 2014, 02:41:32 PM
You could definitely add it yourself if you want...the idea is you don't need a relative timestamp if it's more than a day or so. A week is already a pretty big "about" timeframe. A month or a year is a long time. I'd rather have the timestamp at that point. You could modify the files and do it for yourself pretty easily.
Title: Re: Relative Dates
Post by: Biology Forums on June 13, 2014, 06:05:46 PM
Quote from: Labradoodle-360 on June 13, 2014, 02:41:32 PM
You could definitely add it yourself if you want...the idea is you don't need a relative timestamp if it's more than a day or so. A week is already a pretty big "about" timeframe. A month or a year is a long time. I'd rather have the timestamp at that point. You could modify the files and do it for yourself pretty easily.

But how :P ?
Title: Re: Relative Dates
Post by: live627 on June 13, 2014, 08:58:59 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?
Complete rewrite needed.
Title: Re: Relative Dates
Post by: samborabora on June 14, 2014, 07:46:14 AM
Quote from: live627 on June 13, 2014, 08:58:59 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?
Complete rewrite needed.

Aww, isn't it written so, say, a threshold time period can be assigned a new friendly time? What's the kinda structure the script uses so far that makes it impossible to just customize it? Is there another mod that does the same thing with more options?
Title: Re: Relative Dates
Post by: Matthew K. on June 14, 2014, 11:35:12 AM
Quote from: samborabora on June 14, 2014, 07:46:14 AM
Quote from: live627 on June 13, 2014, 08:58:59 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?
Complete rewrite needed.

Aww, isn't it written so, say, a threshold time period can be assigned a new friendly time? What's the kinda structure the script uses so far that makes it impossible to just customize it? Is there another mod that does the same thing with more options?
I'd tend to believe the person who originally wrote the mod...
Title: Re: Relative Dates
Post by: live627 on June 14, 2014, 08:00:35 PM
Quote from: samborabora on June 14, 2014, 07:46:14 AM
Quote from: live627 on June 13, 2014, 08:58:59 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?
Complete rewrite needed.

Aww, isn't it written so, say, a threshold time period can be assigned a new friendly time? What's the kinda structure the script uses so far that makes it impossible to just customize it? Is there another mod that does the same thing with more options?
Only within the last 24 hours IIRC.
Title: Re: Relative Dates
Post by: samborabora on June 15, 2014, 10:52:14 AM
Quote from: live627 on June 14, 2014, 08:00:35 PM
Quote from: samborabora on June 14, 2014, 07:46:14 AM
Quote from: live627 on June 13, 2014, 08:58:59 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?
Complete rewrite needed.

Aww, isn't it written so, say, a threshold time period can be assigned a new friendly time? What's the kinda structure the script uses so far that makes it impossible to just customize it? Is there another mod that does the same thing with more options?
Only within the last 24 hours IIRC.

And there's no other mod available that does this/the original author isn't planning on a rewrite?
Title: Re: Relative Dates
Post by: vbgamer45 on June 15, 2014, 01:08:32 PM
No rewrite planned.
Title: Re: Relative Dates
Post by: samborabora on June 15, 2014, 02:00:17 PM
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?
Title: Re: Relative Dates
Post by: vbgamer45 on June 15, 2014, 02:23:36 PM
Check the code easy to see
Title: Re: Relative Dates
Post by: samborabora on June 15, 2014, 04:40:52 PM
Quote from: vbgamer45 on June 15, 2014, 02:23:36 PM
Check the code easy to see
Can you be more descriptive/helpful, please?
Title: Re: Relative Dates
Post by: vbgamer45 on June 15, 2014, 11:38:48 PM
Download and analyze code from http://custom.simplemachines.org/mods/index.php?mod=2432
Title: Re: Relative Dates
Post by: Hj Ahmad Rasyid Hj Ismail 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.
Title: Re: Relative Dates
Post by: samborabora on July 14, 2014, 02:57:58 PM
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?
Title: Re: Relative Dates
Post by: margarett 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.
Title: Re: Relative Dates
Post by: Hj Ahmad Rasyid Hj Ismail 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.
Title: Re: Relative Dates
Post by: live627 on July 14, 2014, 09:26:45 PM
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.
Title: Re: Relative Dates
Post by: Hj Ahmad Rasyid Hj Ismail 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.
Title: Re: Relative Dates
Post by: confuseamuse on July 18, 2018, 06:38:27 AM
Is this mod still under development? Possibility for a 2.1 version after beta?
Title: Re: Relative Dates
Post by: Wellwisher 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?
Title: Re: Relative Dates
Post by: vbgamer45 on January 25, 2021, 10:52:11 PM
What would you want the date to show?
Title: Re: Relative Dates
Post by: Wellwisher on January 25, 2021, 11:11:42 PM
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)
Title: Re: Relative Dates
Post by: 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.
Title: Re: Relative Dates
Post by: Wellwisher on January 27, 2021, 01:22:08 AM
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:

(https://i.imgur.com/dHmKhmc.png)
Title: Re: Relative Dates
Post by: Kindred 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)
Title: Re: Relative Dates
Post by: vbgamer45 on January 27, 2021, 03:34:25 PM
Interesting I don't understand the months calculation says 4.35
Title: Re: Relative Dates
Post by: Kindred 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.
Title: Re: Relative Dates
Post by: vbgamer45 on January 27, 2021, 03:49:19 PM
Interesting learn something new.
Title: Re: Relative Dates
Post by: Wellwisher on January 28, 2021, 01:14:26 AM
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.

(https://i.imgur.com/7lnxPn0.png)



Title: Re: Relative Dates
Post by: 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.
Title: Re: Relative Dates
Post by: Wellwisher on January 28, 2021, 11:36:12 AM
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)
Title: Re: Relative Dates
Post by: 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...
Title: Re: Relative Dates
Post by: Wellwisher on January 29, 2021, 01:51:27 AM
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.
Title: Re: Relative Dates
Post by: Senkusha on December 07, 2023, 10:14:19 AM
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?
Title: Re: Relative Dates
Post by: Pipke on December 07, 2023, 10:31:18 AM
Relative Time Formats (https://custom.simplemachines.org/index.php?mod=4235) mod for smf 2.1
Title: Re: Relative Dates
Post by: Senkusha on December 07, 2023, 11:16:10 AM
Thank you!  I don't know why this didn't come up with I tried looking for it.
Title: Re: Relative Dates
Post by: live627 on December 07, 2023, 02:52:43 PM
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.