-
Notifications
You must be signed in to change notification settings - Fork 18
Accomplished #4
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?
Accomplished #4
Changes from all commits
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,60 @@ | ||
| const sub = require('date-fns/sub'); | ||
| const format = require('date-fns/format'); | ||
| 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 EXPECTED_FORMAT = 'yyyy/MM/dd'; | ||
|
|
||
| const makeFilter = (date) => { | ||
| let filters = []; | ||
| const filters = []; | ||
| const days = [7,28,90,365]; | ||
|
|
||
| const objGen = (label,startAt,endAt)=>{ | ||
| return { | ||
| label: label, | ||
| startAt: startAt, | ||
| endAt: endAt | ||
| } | ||
| } | ||
|
|
||
| const filterObj = (label, date, subtract) => { | ||
|
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. Usa nombres más descriptivos a la función que desempeña |
||
| const newFilter = objGen( | ||
| label, | ||
| format(sub(date, { days: subtract }), EXPECTED_FORMAT), | ||
| format(date, EXPECTED_FORMAT) | ||
| ) | ||
| return newFilter; | ||
| } | ||
|
|
||
| const filtersByAmountDays = (i) =>{ | ||
| const filter = filterObj(`Últimos ${i} días`, date, i); | ||
| filters.push(filter); | ||
| } | ||
|
|
||
| days.forEach(filtersByAmountDays); | ||
|
|
||
| for (let i = 1; i <= 3; i++) { | ||
|
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. Usas funciones y de momento cambias ciclos. Esto puede ser confuso para alguien que lea tu código. |
||
| const yearlyRange = sub(date, {years: i}); | ||
| const obj = objGen( | ||
| format(yearlyRange, 'yyyy'), | ||
| format(startOfYear(yearlyRange),EXPECTED_FORMAT), | ||
| format(endOfYear(yearlyRange),EXPECTED_FORMAT) | ||
| ) | ||
| filters.push(obj); | ||
| } | ||
|
|
||
| for (let i = 1; i <= 3; i++) { | ||
| const monthlyRange = sub(date, {months: i}); | ||
| const obj = objGen( | ||
| monthlyRange.toLocaleString('es-CO',{month:"long"}), | ||
| format(startOfMonth(monthlyRange), EXPECTED_FORMAT), | ||
| format(endOfMonth(monthlyRange), EXPECTED_FORMAT) | ||
| ) | ||
| filters.push(obj); | ||
| } | ||
|
|
||
| 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.
Puedes hacer una clase