2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 dateRangeSelectorActionTypes,
31 } from 'generic-components/dateRangeSelector/DateRangeSelectorConstants.js';
33 function buildPeriodChangeAction(startMoment, endMoment, period) {
35 type: dateRangeSelectorActionTypes.EVENT_PERIOD_CHANGE,
38 startDate: startMoment,
46 function buildUnknownPeriodAction(startMoment, endMoment, period, errorMsg) {
48 type: dateRangeSelectorActionTypes.EVENT_PERIOD_ERROR,
51 startDate: startMoment,
61 onPeriodChange(startMoment, endMoment, period) {
62 var moment = require('moment');
63 let startPeriod = moment(new Date());
64 let endPeriod = moment(new Date());
65 let unknownPeriod = false;
69 // already have today's date set
72 startPeriod = moment(startPeriod).subtract(1, 'days');
75 startPeriod = moment(startPeriod).subtract(7, 'days');
78 startPeriod = moment(startPeriod).subtract(1, 'months');
81 startPeriod = startMoment;
82 endPeriod = endMoment;
90 let errorMsg = ERROR_UNKNOWN_PERIOD + ': ' + period;
91 return buildUnknownPeriodAction(startMoment, endMoment, period, errorMsg);
94 Temp fix until we support time ...
95 - set start date time to 00:00:00
96 - set end date time to 23:59:59
97 this is to ensure we cover an entire day
98 (ex: start day May 26, end day May 26 ... expect to cover
99 0:00:00 to 23:59:59 for that day)
101 startPeriod.toDate();
103 startPeriod.minute(0);
104 startPeriod.second(0);
108 endPeriod.minute(59);
109 endPeriod.second(59);
111 return buildPeriodChangeAction(startPeriod, endPeriod, period);