Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion src/filter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
const sub = require('date-fns/sub');
const format = require('date-fns/format');
const localeES = require('date-fns/locale/es')
const startOfMonth = require('date-fns/startOfMonth')
const endOfMonth = require('date-fns/endOfMonth')
const startOfYear = require('date-fns/startOfYear')
const endOfYear = require('date-fns/endOfYear')

const makeFilter = (date) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No usas el parámetro date

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resuelto en el siguiente commit. ¡Gracias!

let filters = [];

const today = new Date(2020,0,1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tienes que quemar el valor de la fecha, lo recibes como parámetro.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resuelto en el siguiente commit. ¡Gracias!

const dateFormat = 'yyyy/MM/dd';

let filters = [
{
label: 'Últimos 7 días',
startAt: format(sub(today, { days: 7 }), dateFormat),
endAt: format(today, dateFormat)
},
{
label: 'Últimos 28 días',
startAt: format(sub(today, { days: 28 }), dateFormat),
endAt: format(today, dateFormat)
},
{
label: 'Últimos 90 días',
startAt: format(sub(today, { days: 90 }), dateFormat),
endAt: format(today, dateFormat)
},
{
label: 'Últimos 365 días',
startAt: format(sub(today, { days: 365 }), dateFormat),
endAt: format(today, dateFormat)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cuando tienes código similar repetido varias veces es señal de que debes implementar una función o una clase

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resuelto en el siguiente commit. ¡Gracias!

];

for (let i = 1; i <= 3; i++) {
const pastYearDate = sub(today, {years: i});
filters.push({
label: format(pastYearDate, 'yyyy'),
startAt: format(startOfYear(pastYearDate), dateFormat),
endAt: format(endOfYear(pastYearDate), dateFormat)
});
}

for (let i = 1; i <= 3; i++) {
const pastMonthDate = sub(today, {months: i});
filters.push({
label: format(pastMonthDate, 'MMMM', {locale: localeES}),
startAt: format(startOfMonth(pastMonthDate), dateFormat),
endAt: format(endOfMonth(pastMonthDate), dateFormat)
});
}

return filters;
}

Expand Down