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.
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() } }
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.