Skip to content

Commit

Permalink
enabling yesterday option when 24 hours is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Feb 2, 2021
1 parent 2a4d39a commit 14d8cd4
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const PrependContainer = styled.div`
padding: 0 ${px(unit)};
`;

const weekDurationInHours = moment.duration(7, 'days').asHours();

function formatPreviousPeriodDates({
momentStart,
momentEnd,
Expand All @@ -38,7 +40,6 @@ function formatPreviousPeriodDates({
function getSelectOptions({ start, end }: { start?: string; end?: string }) {
const momentStart = moment(start);
const momentEnd = moment(end);
const dateDiff = getDateDifference(momentStart, momentEnd, 'days');

const yesterdayOption = {
value: 'yesterday',
Expand All @@ -59,13 +60,15 @@ function getSelectOptions({ start, end }: { start?: string; end?: string }) {
text: formatPreviousPeriodDates({ momentStart, momentEnd }),
};

const dateDiffInHours = getDateDifference(momentStart, momentEnd, 'hours');

// Less than one day
if (dateDiff < 1) {
if (dateDiffInHours <= 24) {
return [yesterdayOption, aWeekAgoOption];
}

// Less than one week
if (dateDiff <= 7) {
if (dateDiffInHours <= weekDurationInHours) {
return [aWeekAgoOption];
}

Expand Down

0 comments on commit 14d8cd4

Please sign in to comment.