2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software 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.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.analytics.model.runtime;
40 import java.text.ParseException;
41 import java.text.SimpleDateFormat;
42 import java.util.Date;
43 import java.util.GregorianCalendar;
45 import org.onap.portalsdk.analytics.system.Globals;
46 import org.onap.portalsdk.analytics.util.AppConstants;
47 import org.onap.portalsdk.analytics.util.Utils;
49 public class ReportParamDateValueParser {
51 /*public static final SimpleDateFormat[] dateFormats;
54 dateFormats = new SimpleDateFormat[5];
55 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))
57 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY))
59 (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY))
61 (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY))
63 (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY))
67 public static boolean isDateHrParam(String param) {
68 SimpleDateFormat[] dateFormats = new SimpleDateFormat[2];
69 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR))
71 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR))
73 for (int i = 0; i < dateFormats.length; i++) {
75 if (dateFormats[i].parse(param) != null) {
78 } catch (ParseException pe) {
79 // do nothing, continue to check param against other dates
81 catch (NumberFormatException pe) {
82 // do nothing, continue to check param against other dates
87 public static boolean isDateParam(String param) {
88 SimpleDateFormat[] dateFormats = new SimpleDateFormat[5];
89 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))
91 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY))
93 (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY))
95 (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY))
97 (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY))
100 for (int i = 0; i < dateFormats.length; i++) {
102 if (dateFormats[i].parse(param) != null) {
105 } catch (ParseException pe) {
106 // do nothing, continue to check param against other dates
108 catch (NumberFormatException pe) {
109 // do nothing, continue to check param against other dates
115 public static String formatDateParamValue(String param) {
116 return ReportParamDateValueParser.formatDateParamValue(param, null);
119 public static String formatDateHrParamValue(String param) {
120 return ReportParamDateValueParser.formatDateHrParamValue(param, null);
123 public static String formatDateHrParamValue(String param, String dateHrFormatPattern) {
124 String formattedDate = null;
125 Date parsedDate = null;
127 dateHrFormatPattern = (dateHrFormatPattern != null) ? dateHrFormatPattern
130 SimpleDateFormat[] dateFormats = new SimpleDateFormat[2];
131 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR))
133 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR))
136 for (int i = 0; i < dateFormats.length; i++) {
138 if (dateFormats[i].parse(param) != null) {
139 SimpleDateFormat newDateFormat = new SimpleDateFormat(dateHrFormatPattern);
140 parsedDate = dateFormats[i].parse(param);
141 formattedDate = newDateFormat.format(parsedDate);
144 return formattedDate;
146 } catch (ParseException pe) {
147 // do nothing, continue to check param against other dates and
148 // format accordingly
150 catch (NumberFormatException pe) {
151 // do nothing, continue to check param against other dates
158 public static String formatDateParamValue(String param, String dateFormatPattern) {
159 String formattedDate = null;
160 Date parsedDate = null;
162 dateFormatPattern = (dateFormatPattern != null) ? dateFormatPattern
163 : AppConstants.JAVA_DATE_FORMAT_MMDDYYYY;
165 SimpleDateFormat[] dateFormats = new SimpleDateFormat[5];
166 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))
168 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY))
170 (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY))
172 (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY))
174 (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY))
177 for (int i = 0; i < dateFormats.length; i++) {
179 if (dateFormats[i].parse(param) != null) {
180 SimpleDateFormat newDateFormat = new SimpleDateFormat(dateFormatPattern);
181 parsedDate = dateFormats[i].parse(param);
182 formattedDate = newDateFormat.format(parsedDate);
184 if (Globals.getMonthFormatUseLastDay()
185 && (dateFormats[i].toPattern().equals(
186 AppConstants.JAVA_DATE_FORMAT_MMYYYY) || dateFormats[i]
188 AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))) {
190 GregorianCalendar gc = new GregorianCalendar();
191 gc.setTime(parsedDate);
192 int day = gc.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
193 formattedDate = Utils.replaceInString(formattedDate, "/01/", "/"
194 + String.valueOf(day) + "/");
198 return formattedDate;
200 } catch (ParseException pe) {
201 // do nothing, continue to check param against other dates and
202 // format accordingly
204 catch (NumberFormatException pe) {
205 // do nothing, continue to check param against other dates
211 } // ReportParamValues