//time format is HHmm - 0130 - 1h 30m
//0225 -> 145
export function countMinutesInUrlTime(time?: string) {
    if (!time) {
        return undefined;
    }

    return Number(time.slice(0, 2)) * 60 + Number(time.slice(2));
}

//145 -> 0225
export function minutesToTimeString(totalMinutes?: number) {
    if (totalMinutes === undefined) {
        return undefined;
    }

    const hours = toTimeString(Math.floor(totalMinutes / 60));
    const minutes = toTimeString(totalMinutes % 60);

    return `${hours}${minutes}`;
}

export function toTimeString(num: number) {
    return num < 10 ? `0${num}` : String(num);
}
