@@ -11,8 +11,8 @@ import {
11
11
} from '../utils'
12
12
import { enforceValues , validateTrendsReducer } from '../utils/reducers'
13
13
import actions from '../actions'
14
+ import dayjs from 'dayjs'
14
15
import { isGreaterThanYear } from '../utils/trends'
15
- import moment from 'moment'
16
16
17
17
const queryString = require ( 'query-string' )
18
18
@@ -25,7 +25,7 @@ export const defaultQuery = {
25
25
dateRange : '3y' ,
26
26
date_received_max : startOfToday ( ) ,
27
27
date_received_min : new Date (
28
- moment ( startOfToday ( ) ) . subtract ( 3 , 'years' )
28
+ dayjs ( startOfToday ( ) ) . subtract ( 3 , 'years' )
29
29
) ,
30
30
enablePer1000 : true ,
31
31
focus : '' ,
@@ -83,26 +83,26 @@ export function alignDateRange( state ) {
83
83
const dateMin = state . date_received_min
84
84
85
85
// All
86
- if ( moment ( dateMax ) . isSame ( defaultQuery . date_received_max ) &&
87
- moment ( dateMin ) . isSame ( types . DATE_RANGE_MIN )
86
+ if ( dayjs ( dateMax ) . isSame ( defaultQuery . date_received_max ) &&
87
+ dayjs ( dateMin ) . isSame ( types . DATE_RANGE_MIN )
88
88
) {
89
89
state . dateRange = 'All'
90
90
return state
91
91
}
92
92
93
93
const rangeMap = {
94
- '3y' : new Date ( moment ( dateMax ) . subtract ( 3 , 'years' ) ) ,
95
- '3m' : new Date ( moment ( dateMax ) . subtract ( 3 , 'months' ) ) ,
96
- '6m' : new Date ( moment ( dateMax ) . subtract ( 6 , 'months' ) ) ,
97
- '1y' : new Date ( moment ( dateMax ) . subtract ( 1 , 'year' ) )
94
+ '3y' : new Date ( dayjs ( dateMax ) . subtract ( 3 , 'years' ) ) ,
95
+ '3m' : new Date ( dayjs ( dateMax ) . subtract ( 3 , 'months' ) ) ,
96
+ '6m' : new Date ( dayjs ( dateMax ) . subtract ( 6 , 'months' ) ) ,
97
+ '1y' : new Date ( dayjs ( dateMax ) . subtract ( 1 , 'year' ) )
98
98
}
99
99
const ranges = Object . keys ( rangeMap )
100
100
let matched = false
101
101
102
102
for ( let i = 0 ; i < ranges . length && ! matched ; i ++ ) {
103
103
const range = ranges [ i ]
104
104
105
- if ( moment ( dateMin ) . isSame ( rangeMap [ range ] , 'day' ) ) {
105
+ if ( dayjs ( dateMin ) . isSame ( rangeMap [ range ] , 'day' ) ) {
106
106
state . dateRange = range
107
107
matched = true
108
108
}
@@ -255,10 +255,10 @@ export function changeDateRange( state, action ) {
255
255
256
256
const res = {
257
257
'All' : new Date ( types . DATE_RANGE_MIN ) ,
258
- '3m' : new Date ( moment ( maxDate ) . subtract ( 3 , 'months' ) ) ,
259
- '6m' : new Date ( moment ( maxDate ) . subtract ( 6 , 'months' ) ) ,
260
- '1y' : new Date ( moment ( maxDate ) . subtract ( 1 , 'year' ) ) ,
261
- '3y' : new Date ( moment ( maxDate ) . subtract ( 3 , 'years' ) )
258
+ '3m' : new Date ( dayjs ( maxDate ) . subtract ( 3 , 'months' ) ) ,
259
+ '6m' : new Date ( dayjs ( maxDate ) . subtract ( 6 , 'months' ) ) ,
260
+ '1y' : new Date ( dayjs ( maxDate ) . subtract ( 1 , 'year' ) ) ,
261
+ '3y' : new Date ( dayjs ( maxDate ) . subtract ( 3 , 'years' ) )
262
262
}
263
263
264
264
/* istanbul ignore else */
@@ -286,10 +286,10 @@ export function changeDates( state, action ) {
286
286
287
287
let { maxDate, minDate } = action
288
288
289
- minDate = moment ( minDate ) . isValid ( ) ?
290
- new Date ( moment ( minDate ) . startOf ( 'day' ) ) : null
291
- maxDate = moment ( maxDate ) . isValid ( ) ?
292
- new Date ( moment ( maxDate ) . startOf ( 'day' ) ) : null
289
+ minDate = dayjs ( minDate ) . isValid ( ) ?
290
+ new Date ( dayjs ( minDate ) . startOf ( 'day' ) ) : null
291
+ maxDate = dayjs ( maxDate ) . isValid ( ) ?
292
+ new Date ( dayjs ( maxDate ) . startOf ( 'day' ) ) : null
293
293
294
294
295
295
const newState = {
@@ -554,7 +554,7 @@ export function removeAllFilters( state ) {
554
554
newState . dateRange = '3y'
555
555
/* eslint-disable camelcase */
556
556
newState . date_received_min =
557
- new Date ( moment ( startOfToday ( ) ) . subtract ( 3 , 'years' ) )
557
+ new Date ( dayjs ( startOfToday ( ) ) . subtract ( 3 , 'years' ) )
558
558
newState . date_received_max = startOfToday ( )
559
559
560
560
newState . focus = ''
0 commit comments