@prezly/theme-kit-ui
Version:
UI components for Prezly themes
19 lines • 639 B
JavaScript
import React from "react";
import { format } from 'date-fns';
// FIXME: avoid importing all locales
import * as locales from 'date-fns/locale';
export function StoryPublicationDate(_ref) {
var {
publishedAt,
locale: currentLocale,
dateFormat = 'd/MM/YY'
} = _ref;
if (!publishedAt) {
return null;
}
var date = typeof publishedAt === 'string' ? new Date(publishedAt) : new Date(publishedAt * 1000);
var locale = currentLocale ? locales[currentLocale] : undefined;
return /*#__PURE__*/React.createElement(React.Fragment, null, format(date, dateFormat.replace('D', 'd').replace('YY', 'yy'), {
locale
}));
}