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)
I don't think it works on my 2.0 RC2
It says: 1453 seconds ago , by Knat Simon
Hmm, thanks for pointing that out. I fixed the problem and reuploaded it
nice mod live, good work
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 :)
What's the problem? (see attachment)
Russian translation:
$txt['hours'] = 'часов';
$txt['minutes'] = 'минут';
$txt['seconds'] = 'секунд';
$txt['hour'] = 'час';
$txt['minute'] = 'минута';
$txt['second'] = 'секунда';
$txt['ago'] = 'назад';
$txt['relative_today'] = 'Сегодня с относительным временем';
I installed this on my 2.0 RC2 Curve but unfortunately there was no option to enable it.
Look at a screenshot on the mod page
It is there for anyone who can read :D
Hello Live627,
Did you look into the thing in my post above ?
Great addition Live.
Installed within seconds on the forum.
( Raven Theme)
Update: 1.1 fixes all reported bugs
Did you try the settings as mentioned in the first post?
Quote from: Bugo link=topic=364742.msg2495393#msg2495393 date=
Russian translation
/quote]
Is it utf8, or otherwise, or both?
Updated russian translation.
Add this files to install package :)
Thank you Bugo
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';
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!
Nice Mod
Please update it for SMF 2.0RC3 ;)
Thanks
Good Mod.
Weldone.
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
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!!
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']);
}
Thank you!! that did it!!
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'] = '今天的相对时间';
Not sure, but try index.chinese.php
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"
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 ::)
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';
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?
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)
I attached the Hungarian language.
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.
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
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.
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.
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 :-\
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.
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.
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.
Any update?
Thank you! Im using this mod right now :)
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?
This mod really needs to be updated to include this week, this month, etc.
Anyone interested in this?
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.
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
sorry on holiday atm will look at this when i get home
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.
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.
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 :)
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?
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.
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 ?
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.
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?
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...
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.
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?
No rewrite planned.
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?
Check the code easy to see
Quote from: vbgamer45 on June 15, 2014, 02:23:36 PM
Check the code easy to see
Can you be more descriptive/helpful, please?
Download and analyze code from http://custom.simplemachines.org/mods/index.php?mod=2432
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.
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?
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.
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.
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.
May be you should have it back. After all, there are already requests for it to be updated / rewritten.
Is this mod still under development? Possibility for a 2.1 version after beta?
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?
What would you want the date to show?
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)
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.
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)
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.
// 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);
}
$nowtime = forum_time();
$retVal = time_ago($nowtime, $time);
return $retVal;
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} ";
}
$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)
Interesting I don't understand the months calculation says 4.35
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.
Interesting learn something new.
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)
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.
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)
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...
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.
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.
// 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);
}
$nowtime = forum_time();
$retVal = time_ago($nowtime, $time);
return $retVal;
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} ";
}
$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?
Relative Time Formats (https://custom.simplemachines.org/index.php?mod=4235) mod for smf 2.1
Thank you! I don't know why this didn't come up with I tried looking for it.
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.