Skip to content

Commit a339515

Browse files
authored
Merge pull request #56 from NativeScript/tgpetrov/min-max-issue
fix: issue happening on 31st
2 parents e14b20d + 65efef2 commit a339515

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/datetimepicker.android.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ export class DateTimePicker extends DateTimePickerBase {
155155
const context = options.context;
156156
let dateTime: Date;
157157
if (value) {
158+
if (nativePicker instanceof android.widget.DatePicker) {
159+
const minDate = (<DatePickerOptions>options).minDate;
160+
const maxDate = (<DatePickerOptions>options).maxDate;
161+
value = DateTimePicker._trimDate(value, minDate, maxDate);
162+
}
158163
dateTime = new Date(value.getTime());
159164
} else {
160165
dateTime = (nativePicker instanceof android.widget.DatePicker) ? getDateToday() : getDateNow();
@@ -188,6 +193,17 @@ export class DateTimePicker extends DateTimePickerBase {
188193
}
189194
}
190195

196+
private static _trimDate(originalDate: Date, minDate: Date, maxDate: Date) {
197+
let finalDate = originalDate;
198+
if (minDate !== undefined && minDate > finalDate) {
199+
finalDate = minDate;
200+
}
201+
if (maxDate !== undefined && maxDate < finalDate) {
202+
finalDate = maxDate;
203+
}
204+
return finalDate;
205+
}
206+
191207
private static _applyDialogColors(nativeDialog: android.app.AlertDialog, color: Color, backgroundColor: Color) {
192208
if (backgroundColor) {
193209
nativeDialog.getWindow().setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(backgroundColor.android));

0 commit comments

Comments
 (0)