refactor(v2): format post date using Intl (#4344)

* refactor(v2): format post date using Intl

* Fix test

* Blog: add localized blog post date test

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Alexey Pyltsyn 2021-03-04 21:11:31 +03:00 committed by GitHub
parent a4b409c93b
commit 1dd400db7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 87 additions and 214 deletions

View file

@ -23,6 +23,7 @@ import {
// @ts-expect-error: no typedefs :s
import resolvePathnameUnsafe from 'resolve-pathname';
import {mapValues} from 'lodash';
import areIntlLocalesSupported from 'intl-locales-supported';
const fileHash = new Map();
export async function generate(
@ -634,3 +635,10 @@ export async function readDefaultCodeTranslationMessages({
return {};
}
export function getDateTimeFormat(locale: string) {
return areIntlLocalesSupported([locale])
? global.Intl.DateTimeFormat
: // eslint-disable-next-line @typescript-eslint/no-var-requires
require('intl').DateTimeFormat;
}