mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
22 lines
584 B
JavaScript
22 lines
584 B
JavaScript
import fecha from 'fecha';
|
|
|
|
// Check for support of native locale string options
|
|
function toLocaleDateStringSupportsOptions() {
|
|
try {
|
|
new Date().toLocaleDateString('i');
|
|
} catch (e) {
|
|
return e.name === 'RangeError';
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export default (toLocaleDateStringSupportsOptions() ?
|
|
function (dateObj, locales) {
|
|
return dateObj.toLocaleDateString(
|
|
locales,
|
|
{ year: 'numeric', month: 'long', day: 'numeric' },
|
|
);
|
|
} : function (dateObj, locales) { // eslint-disable-line no-unused-vars
|
|
return fecha.format(dateObj, 'mediumDate');
|
|
});
|