All files / utils timeUtils.js

100% Statements 20/20
100% Branches 24/24
100% Functions 2/2
100% Lines 20/20

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 30 31 328x 475x 1x   474x 474x 474x     474x 2x     472x 314x 158x 155x 3x 1x   2x     470x 470x   470x     8x 237x  
export const hhmmTohhmma = (HHMM) => {
    if (HHMM === null) {
        return "";
    }
    var time = HHMM.split(':');
    var hours = Number(time[0]);
    var minutes = Number(time[1]);
    var timeValue;
 
    if (minutes > 59 || minutes < 0) {
        return "";
    }
 
    if (hours > 12 && hours < 24) {
        timeValue= "" + (hours - 12);
    } else if (hours > 0 && hours <= 12) {
        timeValue= "" + hours;
    } else if (hours === 0) {
        timeValue= "12";
    } else { 
        return "";
    }
    
    timeValue += (minutes < 10) ? ":0" + minutes : ":" + minutes;  // get minutes
    timeValue += (hours >= 12) ? " PM" : " AM";  // get AM/PM
    
    return timeValue;
}
 
export const convertToTimeRange = (time1, time2) => {
    return (time1 !== "" && time2 !== "") ? `${time1} - ${time2}` : "";
}