Skip to content

Commit

Permalink
fix(itinerary-details): wrong date time locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Helms authored and Andreas Helms committed Dec 12, 2024
1 parent 29a5e7e commit 8a13cfa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions app/component/Duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import PropTypes from 'prop-types';
import React from 'react';
import cx from 'classnames';

import { FormattedMessage } from 'react-intl';
import { FormattedMessage, intlShape } from 'react-intl';
import Icon from './Icon';
import { durationToString } from '../util/timeUtils';

function Duration(props) {
function Duration(props, { intl }) {
const timeOptions = {
hour: 'numeric',
minute: 'numeric',
hour12: false,
};
const duration = durationToString(props.duration * 1000);
const startTime = new Intl.DateTimeFormat('en-US', timeOptions).format(
const startTime = new Intl.DateTimeFormat(intl.locale, timeOptions).format(
new Date(props.startTime),
);
const endTime = new Intl.DateTimeFormat('en-US', timeOptions).format(
const endTime = new Intl.DateTimeFormat(intl.locale, timeOptions).format(
new Date(props.endTime),
);
const futureText = props.futureText
Expand Down Expand Up @@ -74,4 +74,8 @@ Duration.defaultTypes = {
multiRow: false,
};

Duration.contextTypes = {
intl: intlShape,
};

export default Duration;
2 changes: 1 addition & 1 deletion app/component/ItineraryDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class ItineraryDetails extends React.Component {
id: 'tomorrow',
});
}
return getFormattedTimeDate(startTime, 'dd D.M.');
return getFormattedTimeDate(startTime, 'dd D.M.', this.context.intl.locale);
};

setExtraProps = itinerary => {
Expand Down
4 changes: 2 additions & 2 deletions app/util/timeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export function isToday(startTime, refTime) {
/**
* Returns formatted date / time
*/
export function getFormattedTimeDate(startTime, pattern) {
return moment(startTime).format(pattern);
export function getFormattedTimeDate(startTime, pattern, locale) {
return moment(startTime).locale(locale).format(pattern);
}

/**
Expand Down

0 comments on commit 8a13cfa

Please sign in to comment.