Why does date-time Jira misc calculated field not work?

I've installed Jira Misc plugin. And I'd like to calculate date field, based on another custom fields.

I've created Number calculated field (Customfield_12695) to calculate number of days between two date fields:

<!-- @@Formula:  
  // Date1 -  issue.get("customfield_11295") 
 //  Date2  - issue.get("customfield_10151")
   (issue.get("customfield_11295") == null || issue.get("customfield_10151") == null ? null :
  (issue.get("customfield_11295").getTime() - issue.get("customfield_10151").getTime()) 
 / 1000 / 3600 / 24)

It works well.

Next I've tryed to create Date-time calculated field for calculate date based on values from created Customfield_12695 and two another custom date fields:

<!-- @@Formula:   (issue.get("customfield_11295") == null || issue.get("customfield_10151") == null || issue.get("customfield_11493") == null  ? null : 
  issue.get("customfield_12695").IntValue())) -->  

It doesn't work. I don't understand why...

I also tryed to create formula without another calculated custom field, but it's not working, becouse I can't pass integer argument for addDays(date, integer) function...

&lt;!-- @@Formula:   (issue.get("customfield_11493") == null || issue.get("customfield_10151") == null || issue.get("customfield_11295") == null ? null :
(issue.get("customfield_11295").GetTime() - issue.get("customfield_10151").GetTime()) / 1000 / 3600 / 24 ))

If I change expression (issue.get("customfield_11295").GetTime() -issue.get("customfield_10151").GetTime()) / 1000 / 3600 / 24 ) in this formula to integer number - it works.

Help me please to create correct formula for my use case.

I've tryed this variant from another Question, but it doesn't work too:

&lt;!-- @@Formula:long days(Date start, Date end) {
    Calendar c1 = GregorianCalendar.getInstance();
    int w1 = c1.get(Calendar.DAY_OF_WEEK);
    c1.add(Calendar.DAY_OF_WEEK, -w1 + 1);
    Calendar c2 = GregorianCalendar.getInstance();
    int w2 = c2.get(Calendar.DAY_OF_WEEK);
    c2.add(Calendar.DAY_OF_WEEK, -w2 + 1);
    //end Saturday to start Saturday 
    long days = (c2.getTimeInMillis()-c1.getTimeInMillis())/(1000*60*60*24);
    if (w1 == Calendar.SUNDAY) {
        w1 = Calendar.MONDAY;
    if (w2 == Calendar.SUNDAY) {
        w2 = Calendar.MONDAY;
    return days-w1+w2;
// Plan date of finish development - customfield_11493
// Plan date of publication for customer  - customfield_11492
// Date of agreement estimation time by cusomer - customfield_11295
// Date of customers notification - customfield_10151
if (issue.get("customfield_11493")==null || issue.get("customfield_10151") == null || issue.get("customfield_11295") == null)
  return null;
 return org.apache.commons.lang.time.DateUtils.addDays (issue.get("customfield_11493"), days(issue.get("customfield_11295"), issue.get("customfield_10151")))

But it doesn't work too :(.

1 answer

I've decided my problem described hear. There was problem in type of second argument of addDays() function. Decision is use intValue() in expression when calulated number of days for second argument.

This constuction is working now:

&lt;!-- @@Formula:(issue.get("customfield_11493") == null ? null : org.apache.commons.lang.time.DateUtils.addDays(issue.get("customfield_11493"), ((issue.get("customfield_11295").getTime()-issue.get("customfield_10151").getTime())/(1000*60*60*24)).intValue()))

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Sunday in Feedback & Announcements

How do you analyze GC logs, thread dumps and head dumps?

Hi awesome community!  In this article, I would like to describe the one of the toolset (service) for the analyze some problems on different Java-based instances, of course, as Atlassian admini...

124 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you