Calculate time difference between custom date fields

Sir Be April 7, 2014

I have 2 custom date fields (start and end time).

I want to calculate the difference between them.

The difference has to be greater than 4hours.

This will be set in a workflow as a condition/validation when creating an issue.

Working in jira 4.2, standalone version

Downloaded and installed a lot of plugins, none give me the result i wanted

(1 of my conditions if end time has to be larger or equal than begintime)

4 answers

1 accepted

3 votes
Answer accepted
Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 7, 2014

Hi,

I think that you can do this by adding a condition to the transition using one of the scripting utilities plugin like script runner or jjupin, jss.. or develop you own plugin.
Look to this links its can help you and give you more ideas.
https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunnerhttps://marketplace.atlassian.com/plugins/com.quisapps.jira.jsshttps://marketplace.atlassian.com/plugins/com.keplerrominfo.jira.plugins.jjupin

In our company, we use JJUPIN to do like what do you need.

Sir Be April 9, 2014

I'm testing some script writers.

JJupin will be the best, except ..
https://answers.atlassian.com/questions/282630/jjupin-cursor

Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2014

Hi,

try this code as a condition in yur transition workflow

replace sDate with your custom field start date and eDate with your customfield end date

date #{sDate} ="2014-04-10 12:00:00";// start date time
date #{eDate}="2014-04-10 16:30:00";//end date time
number #{diffTime}=0;
 while(#{sDate}<#{eDate}){
	#{sDate}=#{sDate}+"1h";   
      #{diffTime}=#{diffTime}+1;
  }
if(#{diffTime}>4){
return true;
}
else{
return false;
}

Sir Be April 9, 2014

Put it as validator when creating an issue
Script workflow function : Simple scripted validator : Checks script

i get always the error message :s

Timedifference between the 2 has to be at least 4 hours.
So if startdate is today at noon and enddate is tomorrow at noon, it's ok.

But it's a good start ty.

What are the possible languages to write the script in?

Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2014
Sir Be April 9, 2014

Ok, shall search and try so.
I will keep you all informed.

Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2014

Hi,

jjupin is a paid plugin but it's very easy to work with it (don't have knowledge in java language)

groovy and jss are free plugins but it's hard to work with it, ithink that you must have some knowledge in java or python languages

If this answer or other answers to your questions have helped you, please can you accept answers to help other who has the same problems

good luck

Sir Be April 10, 2014

Java is no problem, but scripting is.


Thank you.

Sir Be April 13, 2014

Even when the script is - in the simple script validator-:

Script workflow function : Simple scripted validator : Checks script:

date sDate = cfValues['Start time'];// start date time
date eDate = cfValues['End time'];//end date time
number diffTime=0;
/*while(sDate<eDate){
   sDate=sDate+"1h";   
   diffTime=diffTime+1;
}*/
return true;
/*if(diffTime>4){
return true;
}
else{
return false;
}*/
 
I still get the error message...
What's the syntax for custom fields? 
cfValues['CF name'] or cfValues['CF ID']
1 vote
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2014

Hi Bert,

Do you just need a custom field to calculate time difference between two custom date fields? Or you need a workflow condition/validation to calculate difference and set your workflow accordingly?

If you raise an issue describing the details, I can add such a feature to Enhancer Plugin ASAP.

Tuncay Senturk

Sir Be April 7, 2014

A user may not be able to create an issue if the timespan between start and end date(time) is less than 4h.

The difference don't have to be stored, it may be calulated when the user wants to create the issue.

So custom field not necessary, prefer the condition/validation

btw: TY :D

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2014

Hi,

Sorry but it is not clear for me.

How will those custom fields be calculated, if there is no issue?

I mean, custom fields are located in an issue, but you want to calculate according to two custom fields.

My question, where will these fields take place, so that workflow condition will check for them?

Sir Be April 7, 2014

Including a prt scr for some clarification
When an user wants to create an issue, they have to fill in the start and end date.

If they click on 'create', a message will appear if the difference between those 2 is less than 4 hours.
(like now, except my condition is wrong)

(gd, why cant i upload a picture? ><)


old fashion way: http://tinypic.com/r/201e1c/8

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2014

Hmm, I got the point now. It will do a validation according to user inputs.

By the way, I have just seen that you are using JIRA 4.2

I am sorry, it is impossible to implement a feature to support JIRA 4.2

Sorry again

Tuncay

Sir Be April 7, 2014

Nor problem, thanks anyway for your time and interest.

JIRA 4.2 is my problem, it's not so supported anymore.
We are slowly upgrading to a 6 version (atm only for testing), but we work on JIRA 4.2

0 votes
CelesteCS June 8, 2016

Hello!

For any calculations in Confluence, including any manipulations with table data, you may use CelesteCS Math for Confluence.

Assume you have a table with three columns and three rows on your page – from A1 till C3, where row 1 is the header row. The sum calculation formula for rows 2 and 3 will be simple:

SUM(Table1.A2:C3)

There is a plenty of other functions in the macro, so you may perform any calculations using formulas in EXCEL style.

Thanks!

 

0 votes
Stephen Hayden
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 12, 2015

SIL custom field, use this script:

 

interval age = currentDate() - created;
return "This issue is " + age + " old";

 

replace currentdate() and created with customfield_000000 where 00000 = the custom field IDs.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events