datetimepicker
datetimepicker copied to clipboard
Option to control precision of newDate returned
Feature Request
Add a precision option prop to the DateTimePicker component. (Or remove extraneous seconds from returned newDate)
Currently the DatePicker seems to return a timestamp with a random number of seconds. Ex: When I select: Thu Jan 2 12 20 PM I get a newDate of: 2020-01-02T17:20:28.000Z When I select Tue Dec 31 11:14 AM I get a newDate of: 2019-12-31T16:14:28.000Z
For some reason the returned date has a random extra 28 seconds. I think on other runs I have observed different numbers of excess seconds. Sometimes the returned newDate will be before the date I want and sometimes it is after.
<DateTimePicker
isVisible={isVisible}
mode={mode}
onConfirm={timethingy => {
console.log("GLB", timethingy);
onPressConfirm(timethingy);
}}
onCancel={onPressCancel}
date={typeof selectedMs === "number" ? new Date(selectedMs) : undefined}
titleIOS={titleIos}
is24Hour={is24Hour}
/>
Why it is needed
The extra seconds added to the selected date time make code less predictable and I can't think of a reason why the current behavior is desirable. I guess maybe it's an artifact of the date library or timezone conversion?
Possible implementation
When converting the user selected date and time to a date object, either set the precision to ignore seconds or round to the nearest minute.
Code sample
<DateTimePicker
isVisible={isVisible}
mode={mode}
onConfirm={newDate => {
onPressConfirm(newDate);
}}
onCancel={onPressCancel}
date={typeof selectedMs === "number" ? new Date(selectedMs) : undefined}
titleIOS={titleIos}
precision={is24Hour}
/>