Medium
How to Implement Cached Date Formatters with Multiple Locales in JavaScript
You're implementing a date formatting utility that needs to handle different locales and formats. What's missing to make this implementation work correctly?
1class DateFormatter {2 constructor(locale = 'en-US') {3 this.locale = locale;4 this.formatters = new Map();5 }67 getFormatter(format) {8 // Missing implementation9 _______________10 }1112 format(date, format = 'short') {13 const formatter = this.getFormatter(format);14 return formatter.format(new Date(date));15 }16}1718// Usage:19const formatter = new DateFormatter('en-US');20console.log(formatter.format('2024-01-15', 'full')); // Monday, January 15, 202421console.log(formatter.format('2024-01-15', 'short')); // 1/15/24