Skip to content

Commit a175935

Browse files
committed
Extend time input widget to support AM/PM clock format
1 parent c9191ee commit a175935

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/TimeView.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,33 @@ var DateTimePickerTime = React.createClass({
2323
}
2424
}
2525

26+
let daypart = false;
27+
if( this.props.timeFormat.indexOf(' A') != -1 && this.state != null ){
28+
daypart = ( this.state.hours > 12 ) ? 'PM' : 'AM';
29+
}
30+
2631
return {
2732
hours: date.format('H'),
2833
minutes: date.format('mm'),
2934
seconds: date.format('ss'),
3035
milliseconds: date.format('SSS'),
36+
daypart: daypart,
3137
counters: counters
3238
};
3339
},
3440
renderCounter: function( type ){
35-
return DOM.div({ key: type, className: 'rdtCounter'}, [
36-
DOM.span({ key:'up', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'increase', type ) }, '▲' ),
37-
DOM.div({ key:'c', className: 'rdtCount' }, this.state[ type ] ),
38-
DOM.span({ key:'do', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'decrease', type ) }, '▼' )
39-
]);
41+
if (type !== 'daypart') {
42+
let value = this.state[ type ];
43+
if (type === 'hours' && this.props.timeFormat.indexOf(' A') != -1 && value > 12) {
44+
value = value - 12;
45+
}
46+
return DOM.div({ key: type, className: 'rdtCounter'}, [
47+
DOM.span({ key:'up', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'increase', type ) }, '▲' ),
48+
DOM.div({ key:'c', className: 'rdtCount' }, value ),
49+
DOM.span({ key:'do', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'decrease', type ) }, '▼' )
50+
]);
51+
}
52+
return '';
4053
},
4154
render: function() {
4255
var me = this,
@@ -49,6 +62,11 @@ var DateTimePickerTime = React.createClass({
4962
counters.push( me.renderCounter( c ) );
5063
});
5164

65+
66+
if (this.state.daypart !== false) {
67+
counters.push(DOM.div({ key: this.state.daypart, className: 'rdtDayPart'}, this.state.daypart ));
68+
}
69+
5270
if( this.state.counters.length == 3 && this.props.timeFormat.indexOf('S') != -1 ){
5371
counters.push( DOM.div( {className: 'rdtCounterSeparator', key: 'sep5' }, ':' ));
5472
counters.push(

0 commit comments

Comments
 (0)