I am getting back UTC time from an API, so in my next project, i am converting the UTC times to the users local time based on a timezone setting coming also from the API.
I am trying to use the isWithinInterval
function of date-fns
to check if the current time (in that users timezone) is within a start and end time, but it keeps throwing back a
invalid interval
At the top of the file, i am declaring the current time based on timezone;
const nowInUsersTimezone = new Date().toLocaleString('en-AU', { timeZone: user.timezone })
When i console log this, it shows perfect.
When i got to use the isWithinInterval
im using the following to check if the nowInUsersTimezone
is between 2 dates, if it is, then i just print within
, but i cant get it to work;
{
isWithinInterval(
parseISO(nowInUsersTimezone),
{
start: parseISO(formatInTimeZone(job.start_time, user.timezone, 'dd/MM/yyyy, h:mm:ss aaa')),
end: parseISO(formatInTimeZone(job.end_time, user.timezone, 'dd/MM/yyyy, h:mm:ss aaa')),
}
) && (
<>
<p>Within</p>
</>
)
}
console logging the start
and end
dates works perfect, just when its in the isWithinInterval
doesnt work.