Posts/topics date format ("2 year ago" -> "20 may 2014")



  • I move my old forum from PhpBB3 to NodeBB. And my question about posts dates.
    Many topics date looks like "3 year ago" or even "8 year ago". Its useful for new messages ("5 minute ago" or "10 day ago") but for older post it useless.

    I want show real date for posts older 1 month (like "5 may 2016, 15:12"). How I can do it?



  • I don't know if this is helpfull but I have changed the views and messages changed from (example) 1.1k in 1105.

    I used this in CSS

    .human-readable-number:before {
        content: attr(title);
        font-size: 20px;
    }
    .human-readable-number {
        font-size: 0;
    }
    


  • Ok, thank for tip. Very original by the way, change content in css. Blow my mind a little bit.



  • @alff0x1f said in Posts/topics date format ("2 year ago" -> "20 may 2014"):

    Ok, thank for tip. Very original by the way, change content in css. Blow my mind a little bit.

    If you have it woring, please let me know cause i wanna use it to :)

    If I het it working, I share with you :)



  • @MJ My solution. For demo you can look at my forum (russian language)

    WARNING!!! It is dirty solution (change source code may cause problem with updating in future, you must know how to solve it) and I am not recommend use it, if you didn't understand what you do. Solution without localization, use it only if your forum use only one language (or change code and use number month)

    1. Set cutoff settings for timeago library

    Open acp > custom HTML&CSS > Custom Header and add this:

    <script type="text/javascript">
       jQuery(document).ready(function() {
         jQuery.timeago.settings.cutoff = 2419200000;
       });
    </script>
    

    In this example I set 28 days for relative date (1000 * 60 * 60 * 24 * 28 = 2419200000), you can change it.

    Didn't forget turn on checkbutton "Enable Custom Header" and save changes. After this, all dates older 28 days become unvisible.

    2 Change timeago library

    Onen file public/vendor/jquery/timeago and this code:

        if (!isNaN(data.datetime)) {
          if ( $s.cutoff == 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
            $(this).text(inWords(data.datetime));
          }
        }
    

    replace to this:

        if (!isNaN(data.datetime)) {
          if ( $s.cutoff === 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
            $(this).text(inWords(data.datetime));
          } else {
            var monthNames = [
               "Jan", "Feb", "Mar",
               "Apr", "May", "June", 
               "July", "Aug", "Sept", 
               "Oct", "Nov", "Dec"
            ];
            var day = data.datetime.getDate()
            var year = data.datetime.getFullYear();
            var monthIndex = data.datetime.getMonth();
            var hours = ("0" + data.datetime.getHours()).slice(-2);
            var minutes = ("0" + data.datetime.getMinutes()).slice(-2);
            $(this).text(day + ' ' + monthNames[monthIndex] + ' ' + year + ' ' + hours + ':' + minutes);
          }
        }
    
    

    3. Restart forum

    All must work fine

    Revert changes back

    If you need revert changes, you can do it with command

    git checkout /public/vendor/jquery/timeago/jquery.timeago.js
    

    And remove added text from acp > custom HTML&CSS > Custom Header


Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.