[
https://issues.apache.org/jira/browse/OOZIE-2724?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15644368#comment-15644368
]
Andras Piros edited comment on OOZIE-2724 at 11/7/16 2:45 PM:
--------------------------------------------------------------
I think based on
[*this*|http://stackoverflow.com/questions/16558898/get-difference-between-two-dates-in-months-using-java]
we can get the month difference between two {{Date}} instances perfectly well
even without using Joda Time library:
{code:java}
Calendar startCalendar = new GregorianCalendar();
startCalendar.setTime(startDate);
Calendar endCalendar = new GregorianCalendar();
endCalendar.setTime(endDate);
int diffYear = endCalendar.get(Calendar.YEAR) -
startCalendar.get(Calendar.YEAR);
int diffMonth = diffYear * 12 + endCalendar.get(Calendar.MONTH) -
startCalendar.get(Calendar.MONTH);
{code}
Actually I'm also in favor of avoiding any new external dependency if we have a
standard way to perform a single action.
was (Author: andras.piros):
I think based on
[*this*|http://stackoverflow.com/questions/16558898/get-difference-between-two-dates-in-months-using-java]
we can get the month difference between two {{Date}}s perfectly well even
without using Joda Time library:
{code:java}
Calendar startCalendar = new GregorianCalendar();
startCalendar.setTime(startDate);
Calendar endCalendar = new GregorianCalendar();
endCalendar.setTime(endDate);
int diffYear = endCalendar.get(Calendar.YEAR) -
startCalendar.get(Calendar.YEAR);
int diffMonth = diffYear * 12 + endCalendar.get(Calendar.MONTH) -
startCalendar.get(Calendar.MONTH);
{code}
Actually I'm also in favor of avoiding any new external dependency if we have a
standard way to perform a single action.
> coord:current resolves monthly/yearly dependencies incorrectly
> --------------------------------------------------------------
>
> Key: OOZIE-2724
> URL: https://issues.apache.org/jira/browse/OOZIE-2724
> Project: Oozie
> Issue Type: Bug
> Affects Versions: 4.2.0
> Reporter: Satish Subhashrao Saley
> Assignee: Satish Subhashrao Saley
> Priority: Critical
> Fix For: 4.3.0
>
>
> We calculate the difference between two dates to get the instance count.
> Consider a case where, {{initial instance = Thu Dec 31 16:00:00 PST 2009}}
> and {{effective date (nominal time) = Sun Oct 30 17:55:00 PDT 2016}}.
> Frequency is monthly. So the instance count would be simply number of months
> between these two dates. The number of months between are 81 (inclusively).
> But following code returns 83. A later part of code decreases (possibly some
> offset deletion logic) this by 1, making it 82.
> {code}
> Calendar org.apache.oozie.coord.CoordELFunctions.getCurrentInstance(Date
> effectiveTime, int[] instanceCount, ELEvaluator eval)
> ...
> ...
> case END_OF_MONTH:
> instanceCount[0] = (int) ((effectiveTime.getTime() -
> datasetInitialInstance.getTime()) / MONTH_MSEC);
> break;
> ....
> {code}
> later part of code which is reducing the value by 1:
> {code}
> if (instanceCount[0] > 2) {
> instanceCount[0] = (instanceCount[0] / dsFreq);
> current.add(dsTimeUnit.getCalendarUnit(), instanceCount[0] *
> dsFreq);
> } else {
> instanceCount[0] = 0;
> }
> while (!current.getTime().after(effectiveTime)) {
> current.add(dsTimeUnit.getCalendarUnit(), dsFreq);
> instanceCount[0]++;
> }
> current.add(dsTimeUnit.getCalendarUnit(), -dsFreq);
> instanceCount[0]--;
> return current;
> {code}
> This happens because there we consider only 30 number of days in a month
> while calculating the milliseconds in a month. It will also affect yearly
> jobs because leap year has 366 days.
> {code}
> public static final long MONTH_MSEC = 30 * DAY_MSEC;
> public static final long YEAR_MSEC = 365 * DAY_MSEC;
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)