game.js
// Calculate difference between 2 date objects and return formatted text
Calculate difference between 2 date objects and return formatted text
Calculate difference between 2 date objects and return formatted text
function FormatDateDifference(date0, date1) {
    let TotalSeconds = Math.floor(date0.getTime() / 1000 - date1.getTime() / 1000);
    let Minutes = Math.floor(TotalSeconds / 60);
    let Seconds = TotalSeconds % 60;
    let FormatTime = "";
    if (Minutes == 1) {
        FormatTime += "1 minute"
    }
    else if (Minutes > 1) {
        FormatTime += `${Minutes} minutes`
    }
    if (Seconds == 1) {
        if (Minutes > 0) {
            FormatTime += " and ";
        }
        FormatTime += `${Seconds} second`;
    } 
    else if (Seconds > 1) {
        if (Minutes > 0) {
            FormatTime += " and ";
        }
        FormatTime += `${Seconds} seconds`;
    } 
    return FormatTime;
}
function FormatDateDifference ( date0 , date1 ) { let TotalSeconds = Math . floor ( date0 . getTime ( ) / 1000 - date1 . getTime ( ) / 1000 ) ; let Minutes = Math . floor ( TotalSeconds / 60 ) ; let Seconds = TotalSeconds % 60 ; let FormatTime = "" ; if ( Minutes == 1 ) { FormatTime += "1 minute" } else if ( Minutes > 1 ) { FormatTime += ` ${ Minutes } ` } if ( Seconds == 1 ) { if ( Minutes > 0 ) { FormatTime += " and " ; } FormatTime += ` ${ Seconds } ` ; } else if ( Seconds > 1 ) { if ( Minutes > 0 ) { FormatTime += " and " ; } FormatTime += ` ${ Seconds } ` ; } return FormatTime ; }
Calculate difference between 2 date objects and return formatted text
Calculate difference between 2 date objects and return formatted text
// Append minutes if greater than 0 // Singular form // Plural // Append seconds if greater than 0 // Singular // Check if minutes are present in formattime // Plural // Check if minutes are present in formattime // Return