You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metron.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/07/13 14:52:00 UTC
[jira] [Commented] (METRON-1003) ParserUtil parses dates incorrect
[ https://issues.apache.org/jira/browse/METRON-1003?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16085807#comment-16085807 ]
ASF GitHub Bot commented on METRON-1003:
----------------------------------------
Github user justinleet commented on the issue:
https://github.com/apache/metron/pull/623
Thanks for submitting this, and thanks for being patient. I took a look at what the method was doing, and it seems like we could probably just cleanup that method to something like:
```
public static Long convertToEpoch(String m, String d, String ts,
boolean adjust_timezone) throws ParseException {
String day = StringUtils.leftPad(d.trim(), 2, '0');
int year = Calendar.getInstance().get(Calendar.YEAR);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMMddHH:mm:ss");
if (adjust_timezone) {
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
}
String conglomerated_ts = year + m.trim() + day + ts;
Date date = sdf.parse(conglomerated_ts);
return date.getTime();
}
```
At that point it gets rid of a bunch of the unnecessary `Calendar` stuff and pushed it to the `DateFormat`. I'm also just generally unsure if this is the right place to even handle this function. It hardly seems like it's useful for anything outside of Fireeye, given the formatting (but I don't know that we want to fix that here). I'm inclined to just leave it here for now to get things working and clean up as follow-on.
> ParserUtil parses dates incorrect
> ---------------------------------
>
> Key: METRON-1003
> URL: https://issues.apache.org/jira/browse/METRON-1003
> Project: Metron
> Issue Type: Bug
> Reporter: Vladimir
> Priority: Minor
>
> ParserUtils class has method convertToEpoch that takes month, day and time (as strings), parses it and returns milliseconds since epoch.
> Month expected in "MMM" format (i.e. "Jun")
> Month is parsed and then it is tried to get int value as:
> {code}
> String month = String.valueOf(cal.get(Calendar.MONTH));
> {code}
> But according to documentation (see https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#MONTH) months start from 0.
> So this method returns incorrect value.
> This method should be refactored, but would be great to fix it and write some tests before.
> This is minor bug as this method is used in FireEye parser only.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)