Issue
I have a function that formats date strings as shown below.
import { format, parseISO } from "date-fns";
export function convertDate(myDate, displayFormat) {
return format(new Date(parseISO(myDate)), displayFormat);
}
My articles contain data like this:
title: 'My title'
date: '2022-01-04'
To format the dates, I use the convertDate
function like this:
if (articles) {
for (let i = 0; i < articles.length; i++) {
const year = convertDate(articles[i].date, "y");
years.push(year);
}
uniqueYear = [...new Set(years)];
}
My timezone is CEST.
Error
Currently, I am encountering an error: https://i.sstatic.net/MoJpP.png
Desired outcome:
https://i.sstatic.net/HJHly.png
Alternatively, I can use
{convertDate(article.date, "PPP")}
which also produces the correct result.
Any assistance would be greatly appreciated!