Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Calculated date/time field

Stas January 13, 2015

Hi! I'm using JIRA 6.3.9

 

I'm trying to create date field, that will count time in city

For example:

In field "city" i set "Paris"

In field "Date in city" i get "20/oct/14 6:55 PM"

 

I tryed to set some formulas, but i've got 2 problems:

1) <!-- @@Formula: org.apache.commons.lang.time.DateUtils.addHours(new Date(),10) --> does not work (i get "10 hours" instead of date)

2) How can i set cascade for >2 values (if "Paris" then ... if "London" then...)

1 answer

1 accepted

0 votes
Answer accepted
David _old account_
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.
January 14, 2015

1) this is normal, as JIRA displays dates in a user-friendly manner when they are close to now. So "ten hours from now" will be displayed as "in 10 hours".

2) you can use a cascade of i/else:

String city = issue.get("customfield_12345");
if ("Paris".equalsIgnoreCase(city))
	return org.apache.commons.lang.time.DateUtils.addHours(new Date(),10);
if ("London".equalsIgnoreCase(city))
	return org.apache.commons.lang.time.DateUtils.addHours(new Date(),9);
[...]

Note that if field 12345 is of type Select list (a combobox), then the first line should read:

String city = issue.get("customfield_12345").getValue();

And you might want to protect against null value for city 

Stas January 14, 2015

1) I understand 2) not working. Maybe i did something wrong? (field is not picker, just text field) <!-- @@Formula: String city = issue.get("customfield_10400") if ("Paris".equalsIgnoreCase(city)) return org.apache.commons.lang.time.DateUtils.addHours(new Date(),10); if ("London".equalsIgnoreCase(city)) return org.apache.commons.lang.time.DateUtils.addHours(new Date(),9); -->

David _old account_
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.
January 14, 2015

Sorry, I forgot a semicolon at the end of the first line. In general, if it doesn't work, it might be a syntax error and you will see it in atlassian-jira.log

Stas January 14, 2015

Wow! now it works great!!! Thanks! You are my hero now!

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25 europe, atlassian event, barcelona 2025, jira, confluence, atlassian intelligence, rovo, ai-powered collaboration, developer tools, agile teams, digital transformation, teamwork solutions, atlassian conference, product announcements

🌆 Team '25 Europe registration is now open!

Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.

Register now
AUG Leaders

Atlassian Community Events