Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Jul 16, 2024
1 parent b25e45a commit 46484cf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
2 changes: 2 additions & 0 deletions client/selectors/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export const orderedEvents = createSelector(

const dateRange = getSearchDateRange(search, appConfig.start_of_week);

console.info("RANGE", dateRange.startDate.toString(), dateRange.endDate.toString());

Check failure on line 52 in client/selectors/events.ts

View workflow job for this annotation

GitHub Actions / client (14.x)

Strings must use singlequote

return eventUtils.getEventsByDate(events, dateRange.startDate, dateRange.endDate);
}
);
Expand Down
2 changes: 1 addition & 1 deletion client/selectors/tests/events_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('selectors', () => {
session: {identity: {_id: 'user1'}},
});

const setAdvancedSearchDates = (state, startDate, endate) => {
const setAdvancedSearchDates = (state, startDate, endate?) => {
state.main = {
filter: 'EVENTS',
search: {
Expand Down
50 changes: 30 additions & 20 deletions client/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
IPlanningCoverageItem,
IIngestProvider,
IFeaturedPlanningItem,
ISearchParams,
ICommonSearchParams,
} from '../interfaces';
import {IUser} from 'superdesk-api';
import {superdeskApi} from '../superdeskApi';
Expand Down Expand Up @@ -685,43 +687,51 @@ export const isDateInRange = (inputDate, startDate, endDate) => {
return true;
};

export const getSearchDateRange = (currentSearch, startOfWeek) => {
const dates = get(currentSearch, 'advancedSearch.dates', {});

interface IDateRange {
startDate: moment.Moment;
endDate: moment.Moment;
}

export const getSearchDateRange = (currentSearch: ICommonSearchParams<any>, startOfWeek?: number): IDateRange => {
const dates = currentSearch.advancedSearch.dates ?? {};
const dateRange = {startDate: null, endDate: null};

if (!get(dates, 'start') && !get(dates, 'end') && !get(dates, 'range')) {
dateRange.startDate = moment(moment().format('YYYY-MM-DD'), 'YYYY-MM-DD', true);
dateRange.endDate = moment().add(999, 'years');
} else if (get(dates, 'range')) {
let range = get(dates, 'range');
console.info("DATES", JSON.stringify(dates));

Check failure on line 700 in client/utils/index.ts

View workflow job for this annotation

GitHub Actions / client (14.x)

Strings must use singlequote

if (range === MAIN.DATE_RANGE.TODAY) {
if (dates.range != null) {
if (dates.range === MAIN.DATE_RANGE.TODAY) {
dateRange.startDate = moment(moment().format('YYYY-MM-DD'), 'YYYY-MM-DD', true);
dateRange.endDate = dateRange.startDate.clone().add('86399', 'seconds');
} else if (range === MAIN.DATE_RANGE.TOMORROW) {
} else if (dates.range === MAIN.DATE_RANGE.TOMORROW) {
const tomorrow = moment().add(1, 'day');

dateRange.startDate = moment(tomorrow.format('YYYY-MM-DD'), 'YYYY-MM-DD', true);
dateRange.endDate = tomorrow.clone().add('86399', 'seconds');
} else if (range === MAIN.DATE_RANGE.LAST_24) {
} else if (dates.range === MAIN.DATE_RANGE.LAST_24) {
dateRange.endDate = moment();
dateRange.startDate = dateRange.endDate.clone().subtract('86400', 'seconds');
} else if (range === MAIN.DATE_RANGE.THIS_WEEK) {
} else if (dates.range === MAIN.DATE_RANGE.THIS_WEEK) {
dateRange.endDate = timeUtils.getStartOfNextWeek(null, startOfWeek);
dateRange.startDate = dateRange.endDate.clone().subtract(7, 'days');
} else if (range === MAIN.DATE_RANGE.NEXT_WEEK) {
} else if (dates.range === MAIN.DATE_RANGE.NEXT_WEEK) {
dateRange.endDate = timeUtils.getStartOfNextWeek(null, startOfWeek).add(7, 'days');
dateRange.startDate = dateRange.endDate.clone().subtract(7, 'days');
}
} else {
if (get(dates, 'start')) {
dateRange.startDate = moment(get(dates, 'start'));
}

if (get(dates, 'end')) {
dateRange.endDate = moment(get(dates, 'end'));
}
} else if (dates.start != null && dates.end != null) {
dateRange.startDate = moment(dates.start);
dateRange.endDate = moment(dates.end);
} else if (dates.start != null) {
dateRange.startDate = moment(dates.start);
dateRange.endDate = dateRange.startDate.clone().add(1, 'month');
} else if (dates.end != null) {
dateRange.endDate = moment(dates.end);
dateRange.startDate = dateRange.endDate.clone().subtract(1, 'month');
} else { // Default to today
dateRange.startDate = moment().startOf('day');
dateRange.endDate = moment().add(1, 'month');
}

return dateRange;
};

Expand Down

0 comments on commit 46484cf

Please sign in to comment.