Skip to content

Commit

Permalink
Merge pull request #320 from dtcenter/issue/319-date_xml_parser
Browse files Browse the repository at this point in the history
 The loading module produses an error when parsing <date_list> elemen…
  • Loading branch information
TatianaBurek authored Aug 13, 2021
2 parents 27fc3dc + f552b5e commit be29053
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions java/edu/ucar/metviewer/MVUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -937,21 +937,16 @@ public static List<String> buildDateList(final MVNode node, final PrintStream pr
* @param date (optional) String representation of the date from which to offset
* @return String representation of the offset date
*/
public static String parseDateOffset(final MVNode node, final String format, final String date)
throws ValidationException {
public static String parseDateOffset(final MVNode node, final String format, final String date) {
int intOffset = 0;
int intHour = 0;

for (int i = 0; i < node.children.length; i++) {
MVNode nodeChild = node.children[i];
try {
if (nodeChild.tag.equals("day_offset")) {
intOffset = Integer.parseInt(nodeChild.value);
} else if (nodeChild.tag.equals("hour")) {
intHour = Integer.parseInt(nodeChild.value);
}
} catch (NumberFormatException e) {
throw new ValidationException("day_offset or hour is invalid");
if (nodeChild.tag.equals("day_offset")) {
intOffset = Integer.parseInt(nodeChild.value);
} else if (nodeChild.tag.equals("hour")) {
intHour = Integer.parseInt(nodeChild.value);
}
}

Expand All @@ -960,8 +955,7 @@ public static String parseDateOffset(final MVNode node, final String format, fin
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
try {
cal.setTime(formatOffset.parse(date));
} catch (ParseException e) {
throw new ValidationException("date" + date + " is invalid");
} catch (Exception e) {
}
cal.set(Calendar.HOUR_OF_DAY, intHour);
cal.set(Calendar.MINUTE, 0);
Expand Down

0 comments on commit be29053

Please sign in to comment.