Skip to content

Commit ab2659a

Browse files
author
Dave MacFarlane
committed
Format date according to locale
1 parent d975cee commit ab2659a

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

jsx/I18nSetup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const resources = {
1414
},
1515
en: {
1616
loris: enResources,
17-
}
17+
},
1818
};
1919

2020
i18n

modules/candidate_profile/jsx/CandidateInfo.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {Component} from 'react';
2-
import i18n from 'I18nSetup';
32
import {withTranslation} from 'react-i18next';
43
import PropTypes from 'prop-types';
4+
import 'I18nSetup';
55

66
/**
77
* CandidateInfo is a React component which is used for the
@@ -37,9 +37,15 @@ class CandidateInfo extends Component {
3737
const months = years*12 + now.getMonth() - dobdate.getMonth();
3838

3939
if (months <= 36) {
40-
return this.props.t('{{months}} months old', {ns: 'loris', months: months});
40+
return this.props.t(
41+
'{{months}} months old',
42+
{ns: 'loris', months: months}
43+
);
4144
}
42-
return this.props.t('{{years}} years old', {ns: 'loris', years: years});
45+
return this.props.t(
46+
'{{years}} years old',
47+
{ns: 'loris', years: years}
48+
);
4349
}
4450

4551
/**
@@ -107,6 +113,14 @@ class CandidateInfo extends Component {
107113
*/
108114
render() {
109115
const cohorts = this.getCohorts(this.props.Visits);
116+
const dateFormatter = new Intl.DateTimeFormat(
117+
loris.user.langpref.replace('_', '-'),
118+
{
119+
style: 'short',
120+
timeZone: 'UTC',
121+
122+
}
123+
);
110124

111125
const data = [
112126
{
@@ -119,7 +133,7 @@ class CandidateInfo extends Component {
119133
},
120134
{
121135
label: this.props.t('Date of Birth', {ns: 'loris'}),
122-
value: this.props.Candidate.Meta.DoB,
136+
value: dateFormatter.format(new Date(this.props.Candidate.Meta.DoB)),
123137
valueWhitespace: 'nowrap',
124138
},
125139
{
@@ -210,6 +224,11 @@ CandidateInfo.propTypes = {
210224
Visits: PropTypes.array.isRequired,
211225
VisitMap: PropTypes.object.isRequired,
212226
ExtraCandidateInfo: PropTypes.array,
227+
228+
// Provided by withTranslation HOC
229+
t: PropTypes.func,
213230
};
214231

215-
export default {CandidateInfo: withTranslation(['candidate_profile', 'loris'])(CandidateInfo)};
232+
export default {
233+
CandidateInfo: withTranslation(['candidate_profile', 'loris'])(CandidateInfo),
234+
};

0 commit comments

Comments
 (0)