Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamically update timestamps based on the chosen timezone in the Advanced Settings #196977

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiSpacer, EuiText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import moment from 'moment-timezone';
import { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import {
Expand Down Expand Up @@ -97,10 +98,16 @@ export const ActivityView = ({ item }: ActivityViewProps) => {
);
};

const dateFormatter = new Intl.DateTimeFormat(i18n.getLocale(), {
dateStyle: 'long',
timeStyle: 'short',
});
const formatDate = (time: string) => {
const locale = i18n.getLocale();
const timeZone = moment().tz();

return new Intl.DateTimeFormat(locale, {
dateStyle: 'long',
timeStyle: 'short',
timeZone,
}).format(new Date(time));
};

const ActivityCard = ({
what,
Expand Down Expand Up @@ -130,7 +137,7 @@ const ActivityCard = ({
id="contentManagement.contentEditor.activity.lastUpdatedByDateTime"
defaultMessage="on {dateTime}"
values={{
dateTime: dateFormatter.format(new Date(when)),
dateTime: formatDate(when),
}}
/>
</EuiText>
Expand Down