Split | const cueTimeToSecondsNew = (time) => {
const parts = time.split(':');
const hours = parseInt(parts[0], 10);
const minutes = parseInt(parts[1], 10);
const seconds = parseFloat(parts[2]);
return hours * 3600 + minutes * 60 + seconds;
};
const hour = Math.floor(Math.random()*999);
cueTimeToSecondsNew(`${hour}:53:26.000`)
| ready |
substring | const cueTimeToSecondsNew = (time) => {
const hoursEndIndex = time.indexOf(':');
const minutesEndIndex = time.indexOf(':', hoursEndIndex + 1);
const secondsEndIndex = time.indexOf('.', minutesEndIndex + 1);
const hours = parseInt(time.substring(0, hoursEndIndex), 10);
const minutes = parseInt(time.substring(hoursEndIndex + 1, minutesEndIndex), 10);
const seconds = parseFloat(time.substring(minutesEndIndex + 1));
return hours * 3600 + minutes * 60 + seconds;
};
const hour = Math.floor(Math.random()*999);
cueTimeToSecondsNew(`${hour}:53:26.000`)
| ready |
oldest | const cueTimeToSecondsNewOld = (timeString) => {
const timePattern = /^(\d{2}):(\d{2}):(\d{2}\.\d+)$/;
const match = timeString.match(timePattern);
if (!match) {
throw new Error(`Invalid time format: ${timeString}`);
}
const [, hours, minutes, seconds] = match;
return parseInt(hours, 10) * 3600 + parseInt(minutes, 10) * 60 + parseFloat(seconds);
};
const hour = Math.floor(Math.random()*99);
cueTimeToSecondsNewOld(`${hour}:53:26.000`)
| ready |