-
Notifications
You must be signed in to change notification settings - Fork 17
Solved Challenge #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) => { | ||
| let filters = []; | ||
|
|
||
| const today = new Date(2020,0,1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!