@@ -56,10 +56,18 @@ class DateTimePicker extends BaseComponent {
56
56
* The date format for the text display
57
57
*/
58
58
dateFormat : PropTypes . string ,
59
+ /**
60
+ * A callback function to format date
61
+ */
62
+ dateFormatter : PropTypes . func ,
59
63
/**
60
64
* The time format for the text display
61
65
*/
62
66
timeFormat : PropTypes . string ,
67
+ /**
68
+ * A callback function to format time
69
+ */
70
+ timeFormatter : PropTypes . func ,
63
71
/**
64
72
* Allows changing of the locale of the component (iOS only)
65
73
*/
@@ -140,17 +148,22 @@ class DateTimePicker extends BaseComponent {
140
148
141
149
getStringValue = ( ) => {
142
150
const { value} = this . state ;
143
- const { mode, dateFormat, timeFormat} = this . getThemeProps ( ) ;
151
+ const { mode, dateFormat, timeFormat, dateFormatter , timeFormatter } = this . getThemeProps ( ) ;
144
152
if ( value ) {
145
- const dateString =
146
- mode === MODES . DATE
147
- ? dateFormat
148
- ? moment ( value ) . format ( dateFormat )
149
- : value . toLocaleDateString ( )
150
- : timeFormat
151
- ? moment ( value ) . format ( timeFormat )
152
- : value . toLocaleTimeString ( ) ;
153
- return dateString ;
153
+ switch ( mode ) {
154
+ case MODES . DATE :
155
+ return dateFormatter
156
+ ? dateFormatter ( value )
157
+ : dateFormat
158
+ ? moment ( value ) . format ( dateFormat )
159
+ : value . toLocaleDateString ( ) ;
160
+ case MODES . TIME :
161
+ return timeFormatter
162
+ ? timeFormatter ( value )
163
+ : timeFormat
164
+ ? moment ( value ) . format ( timeFormat )
165
+ : value . toLocaleTimeString ( ) ;
166
+ }
154
167
}
155
168
} ;
156
169
@@ -191,12 +204,7 @@ class DateTimePicker extends BaseComponent {
191
204
iconStyle = { { tintColor : Colors . dark10 } }
192
205
onPress = { this . toggleExpandableOverlay }
193
206
/>
194
- < Button
195
- link
196
- iconSource = { Assets . icons . check }
197
- useCustomTheme = { useCustomTheme }
198
- onPress = { this . onDonePressed }
199
- />
207
+ < Button link iconSource = { Assets . icons . check } useCustomTheme = { useCustomTheme } onPress = { this . onDonePressed } />
200
208
</ View >
201
209
) ;
202
210
}
0 commit comments