2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
27 dateRangeSelectorActionTypes,
34 } from 'generic-components/dateRangeSelector/DateRangeSelectorConstants.js';
36 function buildPeriodChangeAction(startMoment, endMoment, period) {
38 type: dateRangeSelectorActionTypes.EVENT_PERIOD_CHANGE,
41 startDate: startMoment,
49 function buildUnknownPeriodAction(startMoment, endMoment, period, errorMsg) {
51 type: dateRangeSelectorActionTypes.EVENT_PERIOD_ERROR,
54 startDate: startMoment,
64 onPeriodChange(startMoment, endMoment, period) {
65 var moment = require('moment');
66 let startPeriod = moment(new Date());
67 let endPeriod = moment(new Date());
68 let unknownPeriod = false;
72 // already have today's date set
75 startPeriod = moment(startPeriod).subtract(1, 'days');
78 startPeriod = moment(startPeriod).subtract(7, 'days');
81 startPeriod = moment(startPeriod).subtract(1, 'months');
84 startPeriod = startMoment;
85 endPeriod = endMoment;
93 let errorMsg = ERROR_UNKNOWN_PERIOD + ': ' + period;
94 return buildUnknownPeriodAction(startMoment, endMoment, period, errorMsg);
97 Temp fix until we support time ...
98 - set start date time to 00:00:00
99 - set end date time to 23:59:59
100 this is to ensure we cover an entire day
101 (ex: start day May 26, end day May 26 ... expect to cover
102 0:00:00 to 23:59:59 for that day)
104 startPeriod.toDate();
106 startPeriod.minute(0);
107 startPeriod.second(0);
111 endPeriod.minute(59);
112 endPeriod.second(59);
114 return buildPeriodChangeAction(startPeriod, endPeriod, period);