Closed fallenartist closed 1 year ago
I should have explained this would be to override native toLocaleString
which can give unsatisfying results. I've ended up writing my own functions that replace some of the results:
Date.prototype.getMonthNameShort = function(lang) {
lang = lang || 'en';
return lang in Date.locale ?
Date.locale[lang].month_names_short[this.getMonth()] :
this.toLocaleString(lang, {month: "short"});
};
Date.prototype.getDayNameShort = function(lang) {
lang = lang || 'en';
return lang in Date.locale ?
Date.locale[lang].day_names_short[this.getDay()] :
this.toLocaleString(lang, {weekday: "short"});
};
Date.locale = {
pl: { // Polish
month_names_short: ['Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sie', 'Wrz', 'Paź', 'Lis', 'Gru'],
day_names_short: ['Pn', 'Wt', 'Śr', 'Cz', 'Pt', 'Sb', 'Nd']
},
pt: { // Portugese
month_names_short: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
day_names_short: ['Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab', 'Dom']
}
};
// const customMonthName = holidayList[0].start.getMonthNameShort(lang);
Hi @fallenartist, thanks for sharing. I'd rather keep things related to this library, which is take care of holidays (and probably the names related to it). Therefor I'd recommend to either create a own library which takes care on calendar names or use Intl. Hence closing this one...
A big task but it would be great to be able to get names of months and week days according to language setting, e.g: