File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -598,4 +598,22 @@ export function generateMessageHtmlForRecordChange(changedFields: Record<string,
598598 const listHtml = items ? `<ul class="mt-2 list-disc list-inside">${ items } </ul>` : '' ;
599599 const messageHtml = `<div>${ escapeHtml ( t ( 'There are unsaved changes. Are you sure you want to leave this page?' ) ) } ${ listHtml } </div>` ;
600600 return messageHtml ;
601+ }
602+
603+ export function getTimeAgoString ( date : Date ) : string {
604+ const now = new Date ( ) ;
605+ const diffInSeconds = Math . floor ( ( now . getTime ( ) - date . getTime ( ) ) / 1000 ) ;
606+
607+ if ( diffInSeconds < 60 ) {
608+ return `${ diffInSeconds } ${ diffInSeconds === 1 ? 'second' : 'seconds' } ago` ;
609+ } else if ( diffInSeconds < 3600 ) {
610+ const minutes = Math . floor ( diffInSeconds / 60 ) ;
611+ return `${ minutes } ${ minutes === 1 ? 'minute' : 'minutes' } ago` ;
612+ } else if ( diffInSeconds < 86400 ) {
613+ const hours = Math . floor ( diffInSeconds / 3600 ) ;
614+ return `${ hours } ${ hours === 1 ? 'hour' : 'hours' } ago` ;
615+ } else {
616+ const days = Math . floor ( diffInSeconds / 86400 ) ;
617+ return `${ days } ${ days === 1 ? 'day' : 'days' } ago` ;
618+ }
601619}
You can’t perform that action at this time.
0 commit comments