-
Notifications
You must be signed in to change notification settings - Fork 18
Date-fns #1
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?
Date-fns #1
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,87 @@ | ||
| const sub = require('date-fns/sub'); | ||
| const format = require('date-fns/format'); | ||
| const startOfYear = require('date-fns/startOfYear'); | ||
| const endOfYear = require('date-fns/endOfYear'); | ||
| const startOfMonth = require('date-fns/startOfMonth'); | ||
| const endOfMonth = require('date-fns/endOfMonth'); | ||
|
|
||
| // spanish | ||
| const spanish = require('date-fns/locale/es'); | ||
|
|
||
| // today | ||
| const today = new Date(2020, 0, 1); | ||
|
|
||
| // Last years | ||
| const lastYear = sub(today, {years:1}); | ||
| const lastTwoYear = sub(today, {years:2}); | ||
| const lastThreeYear = sub(today, {years:3}); | ||
|
Comment on lines
+15
to
+17
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 repites código similar es señal que debes implementar una función o una clase |
||
|
|
||
| // Last months | ||
| const lastMonth = sub(today, {months:1}); | ||
| const lastTwoMonth = sub(today, {months:2}); | ||
| const lastThreeMonth = sub(today, {months:3}); | ||
|
Comment on lines
+20
to
+22
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 repites código similar es señal que debes implementar una función o una clase |
||
|
|
||
| const makeFilter = (date) => { | ||
| let filters = []; | ||
|
|
||
| let filters = [ | ||
| // Filters per days | ||
| { | ||
| label: 'Últimos 7 días', | ||
| startAt: format(sub(date, {days: 7}), 'yyyy/MM/dd'), | ||
| endAt: format(date, 'yyyy/MM/dd') | ||
| }, | ||
| { | ||
| label: 'Últimos 28 días', | ||
| startAt: format(sub(date, {days: 28}), 'yyyy/MM/dd'), | ||
| endAt: format(date, 'yyyy/MM/dd') | ||
| }, | ||
| { | ||
| label: 'Últimos 90 días', | ||
| startAt: format(sub(date, {days: 90}), 'yyyy/MM/dd'), | ||
| endAt: format(date, 'yyyy/MM/dd') | ||
| }, | ||
| { | ||
| label: 'Últimos 365 días', | ||
| startAt: format(sub(date, {days: 365}), 'yyyy/MM/dd'), | ||
| endAt: format(date, 'yyyy/MM/dd') | ||
| }, | ||
|
|
||
| // Filters per years | ||
| { | ||
| label: format(lastYear, 'yyyy'), | ||
| startAt: format(startOfYear(lastYear), 'yyyy/MM/dd'), | ||
| endAt: format(endOfYear(lastYear), 'yyyy/MM/dd') | ||
| }, | ||
| { | ||
| label: format(lastTwoYear, 'yyyy'), | ||
| startAt: format(startOfYear(lastTwoYear), 'yyyy/MM/dd'), | ||
| endAt: format(endOfYear(lastTwoYear), 'yyyy/MM/dd') | ||
| }, | ||
| { | ||
| label: format(lastThreeYear, 'yyyy'), | ||
| startAt: format(startOfYear(lastThreeYear), 'yyyy/MM/dd'), | ||
| endAt: format(endOfYear(lastThreeYear), 'yyyy/MM/dd') | ||
| }, | ||
|
|
||
| // Filters per months | ||
| { | ||
| label: format(lastMonth, 'MMMM', {locale: spanish}), | ||
| startAt: format(startOfMonth(lastMonth), 'yyyy/MM/dd'), | ||
| endAt: format(endOfMonth(lastMonth), 'yyyy/MM/dd') | ||
| }, | ||
| { | ||
| label: format(lastTwoMonth, 'MMMM', {locale: spanish}), | ||
| startAt: format(startOfMonth(lastTwoMonth), 'yyyy/MM/dd'), | ||
| endAt: format(endOfMonth(lastTwoMonth), 'yyyy/MM/dd') | ||
| }, | ||
| { | ||
| label: format(lastThreeMonth, 'MMMM', {locale: spanish}), | ||
| startAt: format(startOfMonth(lastThreeMonth), 'yyyy/MM/dd'), | ||
| endAt: format(endOfMonth(lastThreeMonth), 'yyyy/MM/dd') | ||
| }, | ||
|
Comment on lines
+50
to
+81
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. Estos datos no se actualizan con el parámetro date, porque ya los fijaste en la linea 12 |
||
|
|
||
| ]; | ||
|
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 repites código similar es señal que debes implementar una función o una clase |
||
|
|
||
| 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.
La fecha la estás fijando, esta debe de ser la que llega como parámetro de la función