Fixing date formatting bug, attempt 3
This commit is contained in:
parent
23ac4c36b4
commit
73e00e2038
1 changed files with 11 additions and 3 deletions
|
@ -23,8 +23,16 @@ const {
|
|||
|
||||
const locale = 'ru-RU';
|
||||
|
||||
if (!Intl.DateTimeFormat.supportedLocalesOf(locale)) {
|
||||
Intl.DateTimeFormat = require('intl').DateTimeFormat;
|
||||
function formatDate(obj?: Date) {
|
||||
if (!obj) return null;
|
||||
|
||||
const formatter = (
|
||||
Intl.DateTimeFormat.supportedLocalesOf(locale).length ?
|
||||
Intl.DateTimeFormat :
|
||||
require('intl').DateTimeFormat
|
||||
);
|
||||
|
||||
return new formatter(locale).format(obj);
|
||||
}
|
||||
---
|
||||
|
||||
|
@ -32,7 +40,7 @@ if (!Intl.DateTimeFormat.supportedLocalesOf(locale)) {
|
|||
<h1>{title}</h1>
|
||||
<address>
|
||||
on
|
||||
<time datetime={date?.toISOString()}>{date?.toLocaleDateString(locale)}</time>
|
||||
<time datetime={date?.toISOString()}>{formatDate(date)}</time>
|
||||
by
|
||||
<a href="https://t.me/dcat09" rel="author">DarkCat09</a>
|
||||
//
|
||||
|
|
Loading…
Add table
Reference in a new issue