I want to change my months and days language to my language with d3 time format v6. I use some method
method 1:
const localeTime = {
"days": ["Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"],
"months": ["Januari", "Februari", "Maret", "April", "Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"]
};
const localeFormat = d3.locale(localeTime);
const formatTime = localeFormat.timeFormat("%d %B %Y");
console.log(formatTime(date));
I get d3.locale is not a function error. Then I change to d3.timeFormatLocale and d3.timeFormatDefaultLocale (Method 2)
Method 2:
const localeTime = {
"days": ["Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"],
"months": ["Januari", "Februari", "Maret", "April", "Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"]
};
const localeFormat = d3.timeFormatLocale(localeTime);
const formatTime = localeFormat.timeFormat("%d %B %Y");
console.log(formatTime(date));
I get this error
Cannot read property 'map' of undefined
at wy (VM25 d3.min.js:2)
at Object.py [as timeFormatLocale] (VM25 d3.min.js:2)
when I don't use the locale as the formatter, the format still won't work because of the locale definition
const localeTime = d3.timeFormatLocale({
"days": ["Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"],
"months": ["Januari", "Februari", "Maret", "April", "Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"]
});
const formatTime = d3.timeFormat("%d %B %Y"); //I don't use the locale this time
console.log(formatTime(date)); //It should be normally formatted as English date, but is not
and I still get the Cannot read property 'map' of undefined error. When I delete the locale definition, the formatter works fine in English
full code on https://codepen.io/louislugas/pen/OJmmzwd