Making WordPress.org


Ignore:
Timestamp:
12/17/2018 07:35:16 AM (5 years ago)
Author:
vedjain
Message:

WCPT: Remove js based humanize_time_diff to favour PHP based function.

Earlier I added JS based version of the function, but turns out I can use PHP version using a little workaround. PHP's implementation is favored because it is a method in core, so it will be maintained and translations are already available.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/javascript/tracker/source/tracker.jsx

    r7982 r7984  
    88
    99/**
    10  * Courtesy: https://stackoverflow.com/a/3177838/1845153
    11  *
    12  * Converts unix seconds into human readable time.
    13  * Looks like exact javascript convert of WordPress's human_time_diff, except this always compares from current time, instead of getting two arguments.
    14  *
    15  * @param {int} seconds Seconds ago to convert to human readable time
    16  *
    17  * @returns {string} Human readable time ago
     10 * Custom render function for lastUpdatedColumn. Will display X time ago instead of unix timestamp. Use `humanizedTime` field sent from server.
    1811 */
    19 const timeSince = ( seconds ) => {
    20 
    21     let interval = Math.floor ( seconds / 31536000 );
    22 
    23     if ( interval >= 1)  {
    24         return interval + " years";
    25     }
    26     interval = Math.floor ( seconds / 2592000);
    27     if ( interval >= 1 ) {
    28         return interval + " months";
    29     }
    30     interval = Math.floor ( seconds / 86400);
    31     if ( interval >= 1 ) {
    32         return interval + " days";
    33     }
    34     interval = Math.floor ( seconds / 3600);
    35     if ( interval >= 1 ) {
    36         return interval + " hours";
    37     }
    38     interval = Math.floor ( seconds / 60);
    39     if ( interval >= 1 ) {
    40         return interval + " minutes";
    41     }
    42     return Math.floor ( seconds ) + " seconds";
    43 };
    44 
    45 /**
    46  * Custom render function for lastUpdatedColumn. Will display X time ago instead of unix timestamp
    47  */
    48 const renderHumanizeTime = ( time ) => {
    49     return timeSince( time ) + " ago";
     12const renderHumanizedTime = ( row ) => {
     13    return row['humanizedTime'];
    5014};
    5115
     
    5721        customRender     = {
    5822            {
    59                 lastUpdate: renderHumanizeTime
     23                lastUpdate: renderHumanizedTime
    6024            }
    6125        }
Note: See TracChangeset for help on using the changeset viewer.