Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix date formatting when timezone is missing

Patryk Zawadzkiafbc89ba69b8
diff --git a/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx b/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx
index 98bce1a0fa..266523094d 100644
--- a/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx
+++ b/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx
@@ -14,6 +14,13 @@ interface DateFormatterProps {
const DateFormatter: React.StatelessComponent<DateFormatterProps> = ({
date
}) => {
+ const getTitle = (value: string, locale?: string, tz?: string) => {
+ let date = moment(value).locale(locale);
+ if (tz !== undefined) {
+ date = date.tz(tz);
+ }
+ return date.toLocaleString();
+ };
return (
<LocaleConsumer>
{locale => (
@@ -21,12 +28,7 @@ const DateFormatter: React.StatelessComponent<DateFormatterProps> = ({
{tz => (
<Consumer>
{currentDate => (
- <Tooltip
- title={moment(date)
- .locale(locale)
- .tz(tz)
- .toLocaleString()}
- >
+ <Tooltip title={getTitle(date, locale, tz)}>
<ReactMoment from={currentDate} locale={locale} tz={tz}>
{date}
</ReactMoment>