Calculating Business Hours backwards

Christopher Stainczyk November 28, 2013

Hello Mr. Fischer,

is it possible to calculate in a calculated date field backwards with regards on work days?

For example, if the due date is the 21-nov-2013 and the calculated field is

"<!-- @@Formula: org.apache.commons.lang.time.DateUtils.addDays(issue.get("duedate"),-16) -->", the field simple calculates 16 days backwards. How can i tell the formula to calculate 16 "work days, mon-fri" backwards?

cheers

btw, great addon!

3 answers

0 votes
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.
December 1, 2013

I'm sorry, you're right. The @@Format expression works only for Calculated Number fields. Calculated Date fields respect the standard JIRA formatting for dates in both the issue view screen and the issue navigator.

If you really want custom formatting for your Date, you should use a Calculated String field instead, which returns a String. You can then use DateFormatUtils#format to format the date to your heart's content.

0 votes
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.
November 28, 2013

The Date/time calculated field must return a Date object.

You must add a @@Format to then format that date into a string (see the documentation)

Christopher Stainczyk December 1, 2013

Hey David,

thanks! Unfortunatly, i have no idea what you mean with @@format to. i've never seen a syntax like this before, sorry :-( could you explain that a little bit more detailed?

Next question: DateFormatutils.format(Date, String) returns a formatted date object, so technically a date, dateutils.adddays returns a date. The online String is the pattern string in the dateformatutils. Which one should be formated?

cheers

0 votes
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.
November 28, 2013

I don't believe such a method exists, but there are so many classes in JIRA and its dependencies that I'm not sure.

Christopher Stainczyk November 28, 2013

Thanks, i will take a look.

Other Problem: I try to format my calculated date by

<!-- @@Formula:
org.apache.commons.lang.time.DateFormatUtils.format(org.apache.commons.lang.time.DateUtils.addDays(issue.get("duedate"),-3),"dd-MM-yyy")
-->

but nothing happend. Could that work in any way?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events