All files / _helpers getHoursFromTimestamp.js

72.22% Statements 13/18
37.5% Branches 3/8
100% Functions 2/2
72.22% Lines 13/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3010x   8x 8x   8x   8x   8x   8x         8x   8x     8x       10x 8x 8x    
export const getTimeDifference = (date) => {
    const millisec =
        new Date(Date.now()).getTime() - new Date(date).getTime();
    var seconds = (millisec / 1000).toFixed(1);
 
    var minutes = (millisec / (1000 * 60)).toFixed(1);
 
    var hours = (millisec / (1000 * 60 * 60)).toFixed(1);
 
    var days = (millisec / (1000 * 60 * 60 * 24)).toFixed(1);
 
    Iif (seconds < 60) {
        if(seconds<0){
        return "Just now";
        }
     return `${parseInt(seconds)} Sec ago`;
    } else Iif (minutes < 60) {
        return `${parseInt(minutes)} Min ago`;
    } else Iif (hours < 24) {
        return `${parseInt(hours)} Hrs ago`;
    } else {
        return `${parseInt(days)} Days ago`;
    }
};
 
export const getHoursFromTimestamp = (stamp) => {
    let date = new Date(stamp)
    return getTimeDifference(date)
}