ClearTime Date function is clearing JIRA values

I have the following scripted field that I'm using to create a numerical value of the difference between the date an issue was created in JIRA vs the DueDate of that item. But it seems like the clearTime() function may be inappropriately also clearing the time of the actual created date of the issue as it appears on JIRA.  When I use this script it correctly gives me the difference between due date and created date, but for some reason my "Created Date" timestamp value in JIRA becomes 12:00 AM.

Why would a function call on an isolated date variable alter the value of my issue's created time? 

 

import com.atlassian.jira.issue.MutableIssue

use(groovy.time.TimeCategory) {
    MutableIssue issue = (MutableIssue) issue
    try{
    	def date1 = issue.getDueDate()
    	def date2 = issue.getCreated()
        def dueDate = date1.clearTime()
        def createDate = date2.clearTime()
    	def duration = dueDate - createDate
    	return "${duration.days}".toDouble()
        }
    catch(NullPointerException e) {
        return 0.toDouble()
        }
}

 

 

 

Update: 

I believe have I isolated this issue. I noticed today I was seeing certain requests come through with good timestamps. After running some tests on different request types I've found out that any time a "due date" is populated on an issue, my Created Date timestamp zeroes out. If I remove the "due date" from the ticket, the created date immediately returns to a proper value which tells me that it still exists in the system and isn't getting cleared out. It seems to be a visual effect that whenever there's a due date populated, the created date timestamp clears out.

This does still seem related to the script, as I removed the script from one of my projects and specifically populated a due date and the created date seems to populate. When I add the scripted field back on, the created date immediately goes to 12:00 AM unless I clear the due date, in which case it reverts to the proper time.

2 answers

1 accepted

I answered my own issue after some trial and error. Apparently the clearTime() function also executes on the object you call it from in addition to returning a date value to be stored in a variable. I fixed my issue by cloning the date objects so that any changes I made would change the clone, not the original.

 

import com.atlassian.jira.issue.MutableIssue
 
use(groovy.time.TimeCategory) {
    MutableIssue issue = (MutableIssue) issue
    try{
        def date1 = issue.getDueDate().clone()
        def date2 = issue.getCreated().clone()
        def dueDate = date1.clearTime()
        def createDate = date2.clearTime()
        def duration = dueDate - createDate
        return "${duration.days}".toDouble()
        }
    catch(NullPointerException e) {
        return 0.toDouble()
        }
}
1 votes

clearTIme clears the time part on the object you you call it, and returns that, which I eventually worked out from http://stackoverflow.com/questions/6739561/groovy-date-cleartime-question

So your original code would modify the issue object in the current thread, but not actually store any changes to the database. 

 

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,789 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot