Skip to content

Commit ea7e774

Browse files
Update DateTimePicker.tsx
add max & min dates
1 parent a6f18db commit ea7e774

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/controls/dateTimePicker/DateTimePicker.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Async, css } from 'office-ui-fabric-react/lib/Utilities';
1515
import { IDateTimePickerProps, IDateTimePickerState, DateTimePickerStrings } from ".";
1616
import { TimeHelper } from "./TimeHelper";
1717
import { TimeDisplayControlType } from "./TimeDisplayControlType";
18+
import { addMonths, addYears } from 'office-ui-fabric-react/lib/utilities/dateMath/DateMath';
1819

1920
interface IDateComponents {
2021
day: Date;
@@ -53,7 +54,8 @@ export class DateTimePicker extends React.Component<IDateTimePickerProps, IDateT
5354
hours,
5455
minutes,
5556
seconds,
56-
errorMessage: ''
57+
errorMessage: '',
58+
today: new Date(Date.now())
5759
};
5860

5961
this.async = new Async(this);
@@ -205,7 +207,9 @@ export class DateTimePicker extends React.Component<IDateTimePickerProps, IDateT
205207
strings: dateStrings = new DateTimePickerStrings(), // Defines the DatePicker control labels
206208
timeDisplayControlType,
207209
placeholder,
208-
showLabels
210+
showLabels,
211+
minDate = addYears(this.state.today, 1),
212+
maxDate = addYears(this.state.today, 1)
209213
} = this.props;
210214

211215
const hours: number = value != null ? value.getHours() : this.state.hours;
@@ -293,6 +297,8 @@ export class DateTimePicker extends React.Component<IDateTimePickerProps, IDateT
293297
showMonthPickerAsOverlay={showMonthPickerAsOverlay}
294298
showWeekNumbers={showWeekNumbers}
295299
placeholder={placeholder}
300+
minDate={minDate}
301+
maxDate={maxDate}
296302
/>
297303
</div>
298304
</div>

0 commit comments

Comments
 (0)