Skip to content

Commit

Permalink
Fix date picker ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
majakomel committed Feb 27, 2023
1 parent 6a02865 commit 63d7a14
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions components/DateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,22 @@ const getDateFnsLocale = locale => {

const DateRangePicker = ({handleRangeSelect, initialRange, close, ...props}) => {
const intl = useIntl()
const tomorrow = addDays(new Date(), 1)
const ranges = ['Today', 'LastWeek', 'LastMonth', 'LastYear']

const selectRange = (range) => {
switch (range) {
case 'Today':
handleRangeSelect({from: new Date(), to: new Date()})
handleRangeSelect({from: new Date(), to: tomorrow})
break
case 'LastWeek':
handleRangeSelect({from: sub(new Date(), {weeks: 1}) , to: new Date()})
handleRangeSelect({from: sub(new Date(), {weeks: 1}) , to: tomorrow})
break
case 'LastMonth':
handleRangeSelect({from: sub(new Date(), {months: 1}) , to: new Date()})
handleRangeSelect({from: sub(new Date(), {months: 1}) , to: tomorrow})
break
case 'LastYear':
handleRangeSelect({from: sub(new Date(), {years: 1}) , to: new Date()})
handleRangeSelect({from: sub(new Date(), {years: 1}) , to: tomorrow})
break
}
}
Expand Down Expand Up @@ -125,8 +126,6 @@ const DateRangePicker = ({handleRangeSelect, initialRange, close, ...props}) =>
setRange(range)
}

const tomorrow = addDays(new Date(), 1)

return (
<StyledDatetime>
<OutsideClickHandler onOutsideClick={() => close()}>
Expand Down

0 comments on commit 63d7a14

Please sign in to comment.