Changeset 7976 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/javascript/tracker/source/tracker.jsx
- Timestamp:
- 12/17/2018 07:34:12 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/javascript/tracker/source/tracker.jsx
r3814 r7976 7 7 require( './style.scss' ); 8 8 9 /** 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} date Unix timestamp date to compare from 16 * 17 * @returns {string} Human readable time ago 18 */ 19 const timeSince = ( date ) => { 20 21 const seconds = Math.floor( (new Date() / 1000 ) - date ); 22 23 let interval = Math.floor(seconds / 31536000); 24 25 if (interval > 1) { 26 return interval + " years"; 27 } 28 interval = Math.floor(seconds / 2592000); 29 if (interval > 1) { 30 return interval + " months"; 31 } 32 interval = Math.floor(seconds / 86400); 33 if (interval > 1) { 34 return interval + " days"; 35 } 36 interval = Math.floor(seconds / 3600); 37 if (interval > 1) { 38 return interval + " hours"; 39 } 40 interval = Math.floor(seconds / 60); 41 if (interval > 1) { 42 return interval + " minutes"; 43 } 44 return Math.floor(seconds) + " seconds"; 45 }; 46 47 /** 48 * Custom render function for lastUpdatedColumn. Will display X time ago instead of unix timestamp 49 */ 50 const renderHumanizeTime = ( time ) => { 51 return timeSince( time ) + " ago"; 52 }; 53 54 9 55 ReactDOM.render( 10 56 <FilterableTable 11 57 initialSortField = { wpcApplicationTracker.initialSortField } 12 58 columns = { wpcApplicationTracker.displayColumns } 59 customRender = { 60 { 61 lastUpdate: renderHumanizeTime 62 } 63 } 13 64 />, 14 65 document.getElementById( 'wpc-application-tracker' )
Note: See TracChangeset
for help on using the changeset viewer.