Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onStartTimeTracking = () => {
const { now } = this.props;
const { entry } = this.state;
const startTime = new Date();
const isOldTempItem = isBefore(entry.start, addDays(now, -1));
const isNewTempItem = isEqual(entry.start, startOfDay(now));
const newEntry = {
...entry,
start: isOldTempItem || isNewTempItem ? startTime : entry.start,
end: startTime,
};
this.onUpdateItem(newEntry, true);
this.setState({
tracking: true,
entry: newEntry,
});
// track event
let date = startOfWeek(startOfMonth(activeMonth), { weekStartsOn })
const end = endOfWeek(endOfMonth(activeMonth), { weekStartsOn })
// TODO: simplify with FC approach, remove state logic from child components
// this is passed from the parent component
// @ts-ignore
if (this._selectionInProgress && rangeLimit) {
minDate = this._getMinDate()
maxDate = this._getMaxDate()
}
while (
// TODO: External helper with weeknumber etc
/* eslint-disable no-unmodified-loop-condition */
(typeof minNumberOfWeeks === 'number' && minNumberOfWeeks > weeks.length) ||
(isBefore(date, end) || isSameDay(date, end))
) {
weeks.push(date)
date = addDays(date, 7)
}
return weeks.map((week) => {
return (
_pushUpdate() {
const { onChange, rangeLimit } = this.props
let start, end
// TODO: simplify with FC approach, remove state logic from child components
// this is passed from the parent component
// @ts-ignore
if (this._selectionStart && this._selectionEnd) {
// TODO: simplify with FC approach, remove state logic from child components
// this is passed from the parent component
// @ts-ignore
if (isBefore(this._selectionStart, this._selectionEnd)) {
// TODO: simplify with FC approach, remove state logic from child components
// this is passed from the parent component
// @ts-ignore
start = this._selectionStart
// TODO: simplify with FC approach, remove state logic from child components
// this is passed from the parent component
// @ts-ignore
end = this._selectionEnd
} else {
// TODO: simplify with FC approach, remove state logic from child components
// this is passed from the parent component
// @ts-ignore
start = this._selectionEnd
// TODO: simplify with FC approach, remove state logic from child components
// this is passed from the parent component
// @ts-ignore
isHoveredInRange(date) {
if (this.isSingleMode || this.allDatesSelected) {
return false
}
return (
(isAfter(date, this.selectedDate1) && isBefore(date, this.hoverDate)) ||
(isAfter(date, this.hoverDate) && isBefore(date, this.selectedDate1))
)
},
isBeforeMinDate(date) {
export function withinRange(date: Date, { start, end }: { start: Date | null, end: Date | null }) {
if (start === null) {
if (end === null) {
return true;
} else {
return isBefore(date, end);
}
} else {
if (end === null) {
return isAfter(date, start);
} else {
return isWithinRange(date, start, end);
}
}
}
isDateEnabled(date) {
const now = new Date();
const todayDay = now.getDate();
const todayMonth = now.getMonth();
const todayYear = now.getFullYear();
const today = new Date(todayYear, todayMonth, todayDay);
return !isBefore(date, today);
}
onStartDateSelected(date) {
} = event
const date = parse(value)
const {onDayMouseEnter} = this.props
if (onDayMouseEnter) {
onDayMouseEnter(date)
}
if (!this._selectionInProgress) return
const {rangeLimit} = this.props
const dateLimit = subDays(this._selectionStart, rangeLimit)
const isDisabledWithin = this._getDisabledRange({
start: isBefore(this._selectionStart, date) ? this._selectionStart : date,
end: !isBefore(this._selectionStart, date) ? this._selectionStart : date,
})
if (!isDisabledWithin) return
if (!isEqual(date, this._selectionEnd)) {
if (!rangeLimit || (rangeLimit && !isBefore(date, dateLimit))) {
this._selectionEnd = date
this._pushUpdate()
}
}
}
function getSortedSelection({start, end}) {
return isBefore(start, end)
? {start, end}
: {start: end, end: start};
}
isBeforeMinDate(date) {
if (!this.minDate) {
return false
}
return isBefore(date, this.minDate)
},
isAfterEndDate(date) {
function getYearsRange (startDate, endDate) {
const years = []
let curDate = startDate
while (isBefore(curDate, endDate)) {
years.push(getYear(curDate))
curDate = addYears(curDate, 1)
}
return years
}