Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(props) {
super(props);
this.state = {
dateTime: DateTimeUtils.createSafeDate(props.value),
isAmbiguousTime: false,
isTimeClarificationOpen: false,
dateFormat: DateUtil.getFormatByLocale(props.intl.locale),
prevPropsValue: props.value,
};
// The dateValue and timeValue variables represent the actual value in the date input and time input respectively.
// They are used to keep track of the currently entered value to determine whether or not the entry is valid.
// Unlike dateValue and timeValue, this.state.dateTime is the internal moment object representing both the date and time as one entity
// It is used for date/time manipulation and used to calculate the missing/ambiguous hour.
// The dateValue and timeValue are tracked outside of the react state to limit the number of renderings that occur.
this.dateValue = DateTimeUtils.formatMomentDateTime(this.state.dateTime, this.state.dateFormat);
this.timeValue = DateTimeUtils.hasTime(this.props.value) ? DateTimeUtils.formatISODateTime(this.props.value, 'HH:mm') : '';
this.isDefaultDateTimeAcceptable = true;
this.handleDateChange = this.handleDateChange.bind(this);
this.handleDateChangeRaw = this.handleDateChangeRaw.bind(this);
this.handleTimeChange = this.handleTimeChange.bind(this);
this.handleOnSelect = this.handleOnSelect.bind(this);
constructor(props) {
super(props);
this.state = {
dateTime: DateTimeUtils.createSafeDate(props.value),
isAmbiguousTime: false,
isTimeClarificationOpen: false,
dateFormat: DateUtil.getFormatByLocale(props.intl.locale),
prevPropsValue: props.value,
};
// The dateValue and timeValue variables represent the actual value in the date input and time input respectively.
// They are used to keep track of the currently entered value to determine whether or not the entry is valid.
// Unlike dateValue and timeValue, this.state.dateTime is the internal moment object representing both the date and time as one entity
// It is used for date/time manipulation and used to calculate the missing/ambiguous hour.
// The dateValue and timeValue are tracked outside of the react state to limit the number of renderings that occur.
this.dateValue = DateTimeUtils.formatMomentDateTime(this.state.dateTime, this.state.dateFormat);
this.timeValue = DateTimeUtils.hasTime(this.props.value) ? DateTimeUtils.formatISODateTime(this.props.value, 'HH:mm') : '';
this.isDefaultDateTimeAcceptable = true;
this.wasOffsetButtonClicked = false;
this.handleDateChange = this.handleDateChange.bind(this);
this.handleDateChangeRaw = this.handleDateChangeRaw.bind(this);
this.handleTimeChange = this.handleTimeChange.bind(this);
validateDefaultDate() {
let isAcceptable = true;
if (DateUtil.isDateOutOfRange(this.state.dateTime, DateUtil.createSafeDate(this.props.minDateTime), DateUtil.createSafeDate(this.props.maxDateTime))) {
isAcceptable = false;
}
if (DateUtil.isDateExcluded(this.state.dateTime, this.props.excludeDates)) {
isAcceptable = false;
}
return isAcceptable;
}
isDateTimeWithinRange(newDateTime) {
let isAcceptable = true;
if (DateUtil.isDateOutOfRange(newDateTime, DateUtil.createSafeDate(this.props.minDateTime), DateUtil.createSafeDate(this.props.maxDateTime))) {
isAcceptable = false;
}
if (DateUtil.isDateExcluded(newDateTime, this.props.excludeDates)) {
isAcceptable = false;
}
return isAcceptable;
}
static convertDateTimeStringToMomentObject(date, time, dateformat, hasSeconds) {
return DateTimeUtils.updateTime(DateUtil.createSafeDate(DateUtil.convertToISO8601(date, dateformat)), time, hasSeconds);
}
}
validateDefaultDate() {
let isAcceptable = true;
if (DateUtil.isDateOutOfRange(this.state.dateTime, DateUtil.createSafeDate(this.props.minDateTime), DateUtil.createSafeDate(this.props.maxDateTime))) {
isAcceptable = false;
}
if (DateUtil.isDateExcluded(this.state.dateTime, this.props.excludeDates)) {
isAcceptable = false;
}
return isAcceptable;
}
isDateTimeWithinRange(newDateTime) {
let isAcceptable = true;
if (DateUtil.isDateOutOfRange(newDateTime, DateUtil.createSafeDate(this.props.minDateTime), DateUtil.createSafeDate(this.props.maxDateTime))) {
isAcceptable = false;
}
if (DateUtil.isDateExcluded(newDateTime, this.props.excludeDates)) {
isAcceptable = false;
}
return isAcceptable;
}
static getTime(time, hasSeconds) {
const timeFormat = hasSeconds ? 'HH:mm:ss' : 'HH:mm';
return DateUtil.formatISODate(time, timeFormat);
}
static isValidDateTime(date, time, format, hasSeconds) {
return DateUtil.isValidDate(date, format) && DateTimeUtils.isValidTime(time, hasSeconds);
}