Skip to content

Commit 19a9f07

Browse files
Use moment with locales
1 parent 09847cc commit 19a9f07

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

__tests__/Datepicker.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import {Platform, Animated, DatePickerAndroid, Modal, View} from 'react-native';
33
import Enzyme, {shallow} from 'enzyme';
44
import Adapter from 'enzyme-adapter-react-16';
5-
import Moment from 'moment';
5+
import Moment from 'moment/min/moment-with-locales';
66
import DatePicker from '../datepicker.js';
77

88
Enzyme.configure({adapter: new Adapter()});
@@ -354,4 +354,11 @@ describe('Coverage', () => {
354354

355355
wrapper.find('DatePickerIOS').simulate('dateChange');
356356
});
357+
358+
it('Sets locale', () => {
359+
jest.spyOn(Moment, 'locale');
360+
shallow(<DatePicker locale="es" />);
361+
362+
expect(Moment.locale).toHaveBeenCalledWith('es');
363+
});
357364
});

datepicker.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
Keyboard
1515
} from 'react-native';
1616
import Style from './style';
17-
import Moment from 'moment';
17+
import Moment from 'moment/min/moment-with-locales';
1818

1919
const FORMATS = {
2020
'date': 'YYYY-MM-DD',
@@ -58,6 +58,12 @@ class DatePicker extends Component {
5858
console.ignoredYellowBox.push('Warning: Failed propType');
5959
}
6060

61+
componentDidMount() {
62+
if (this.props.locale) {
63+
Moment.locale(this.props.locale);
64+
}
65+
}
66+
6167
componentWillReceiveProps(nextProps) {
6268
if (nextProps.date !== this.props.date) {
6369
this.setState({date: this.getDate(nextProps.date)});

0 commit comments

Comments
 (0)