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: added fix to support the behavior of twelve hour timepicker format if seconds not passed" #1392

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ Array [
onKeyPress={[Function]}
placeholder="DD/MM/YYYY - DD/MM/YYYY"
type="text"
value="14/06/2020 - 18/06/2020"
value=""
/>
<span
className="fd-input-group__addon fd-input-group__addon--button fd-input-group__addon--compact"
Expand Down
20 changes: 17 additions & 3 deletions src/TimePicker/TimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,31 @@ class TimePicker extends Component {
};
getFormattedTime = value => {
let time = {};
let timeArray = value.split(':');
let timeArray = [];
if (value.includes(this.props.localizedText.meridiemAM) || value.includes(this.props.localizedText.meridiemPM)) {
let splitBySpace = value.trim().match(/^(\S+)\s(.*)/).slice(1);
let timeMerideim = splitBySpace[1];
timeArray = splitBySpace[0].split(':');
timeArray.push(timeMerideim);
} else {
timeArray = value.trim().split(':');
}
if (typeof timeArray[0] !== 'undefined' && this.props.showHour) {
time.hour = this.formatWithLeadingZero(timeArray[0]);
}
if (typeof timeArray[1] !== 'undefined' && this.props.showMinute) {
time.minute = this.formatWithLeadingZero(timeArray[1]);
}
if (typeof timeArray[2] !== 'undefined' && this.props.showSecond) {
time.second = this.formatWithLeadingZero(timeArray[2].match(/\d+/)[0]);
if ((timeArray[2] !== this.props.localizedText.meridiemPM) && timeArray[2] !== this.props.localizedText.meridiemAM) {
time.second = this.formatWithLeadingZero(timeArray[2].match(/\d+/)[0]);
}
if (this.props.format12Hours) {
time.meridiem = timeArray[timeArray.length - 1].indexOf(this.props.localizedText.meridiemAM) !== -1 ? 0 : 1;
}
} else {
if (this.props.format12Hours) {
time.meridiem = timeArray[2].indexOf(this.props.localizedText.meridiemAM) !== -1 ? 0 : 1;
time.meridiem = timeArray[timeArray.length - 1].indexOf(this.props.localizedText.meridiemAM) !== -1 ? 0 : 1;
}
}
return time;
Expand Down
14 changes: 14 additions & 0 deletions src/TimePicker/TimePicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ describe('<TimePicker />', () => {

expect(wrapper.children().state('value')).toEqual('00:24:00 am');

// just hour and minute, 12 hr format with pm
wrapper = mount(
<TimePicker
format12Hours
showHour
showMinute
showSecond={false} />
);
wrapper
.find('input[type="text"]')
.at(0)
.simulate('change', { target: { value: '10:30 pm' } });

expect(wrapper.children().state('value')).toEqual('10:30 pm');
// just hour and minute, no 12 hr format
wrapper = mount(
<TimePicker
Expand Down