parseInt not working

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);

Another oddity, it seems when previewing the site, the values work as intended, but in the editor the Reference Error is still thrown

Hello @anthony_schanen. We have a list of functions enabled in our canvas for security reasons and it seems that we havent added parseInt to it. You can change it to globalThis.parseInt (like using window.parseInt but safer) while we work on supporting it natively.

2 Likes

Thanks a bunch!