Thanks for assisting @icaro_guerra
That makes sense but in trying to do that I am faced with another issue. Im unsure why using parseInt()
is throwing a reference error. I did not get this problem when using the Contentful Field
It’s also odd that parseInt
is recognized by the linter when I hover over it, implying that I have scope to use it, yet you can see in the field there is a Reference Error (intellisense, unsure what the correct term is)
Why is this happening? Guess there is some nuance to these code snippets
Here is the code for ease of access
function formatTime(time) {
time = String(time);
let hours = parseInt(time.substring(0, time.length - 2));
let minutes = time.substring(time.length - 2);
hours = hours % 24;
const suffix = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12 || 12;
return `${hours}${minutes === '00' ? '' : ':' + minutes}${suffix}`;
}
return formatTime($ctx.currentContentfulCenterOpenAndCloseItem.fields.openTimeText);