Calculate time difference between custom date fields

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

Accepted Answer
3 votes

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.

I'm testing some script writers.

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

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;
}

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?

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

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

Java is no problem, but scripting is.


Thank you.

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

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

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

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?

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

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

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

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.

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!

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Friday in Europe

Venue Needed! 23rd October

Hey Everyone! Unfortunately, the venue that was hosting us on the 23rd has pulled out so we're looking for a new venue.    If anyone would have a room free that we could use on the ev...

40 views 1 0
View post

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