Scripted Field Date JQL factors in timezone

David Yu
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.
June 6, 2024

I have this simple example Script Field (using the Date template) that returns a date value:

 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

String dateString = "2020-01-01"

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

try {

// Parse the date string into a Date object
Date date = formatter.parse(dateString);
return date

} catch (ParseException e) {

log.error("Unable to parse date value on issue")

}

It returns 2020-01-01 as expected. The field is configured with a Date Time Range Searcher (which is the only date searcher available).

JQL works when I do:

MyDate = 2020-01-01

But it doesn't work for users in a different timezone. Users in a different timezone must use MyDate >= 2020-01-01 for example.

So it seems like Jira is somehow factoring in the timestamp internally.

How can I get it to behave like the internal Due Date, or other regular Date fields?

I think the problem is that Script Runner's fields do not have a *Date Range Searcher* available.

date.png

 

1 answer

1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 11, 2024

Hi @David Yu

Firstly, I would like to clarify, when you use the Scripted Field in your JQL Query, are you also displaying it in the result? If yes, this can cause other issues in your environment.

Next, have you tried looking into the LocalDate class instead of just using Date?

I am looking forward to your feedback and clarification.

Thank you and Kind regards,
Ram

 

David Yu
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.
June 11, 2024

Ram, ScriptRunner does a type check it seems and refuses to let you return a LocalDate object.

Anyway, I think this is related to the Searcher ScriptRunner uses. If ScriptRunner supported *Date Range Searcher* in addition to *Date Time Range Searcher*, these problems would go away.

Suggest an answer

Log in or Sign up to answer