Looking for a way to avoid adjusting TZ on a date-time field

Chris Melville
Contributor
January 20, 2025

Jira helpfully converts all date-time fields to the user's local Timezone.  However, there are cases where this is undesirable.  We need to track an 'Event time' that must always be in UTC, regardless of who is viewing it and their local TZ.

AFAIK, there is no way to achieve this without creating a new field type. Has anyone solved this problem?  If so, how?  We user scriptrunner extensively so pointers on how to achieve this, or to buy a plugin that already has it, are most welcome.

2 answers

0 votes
Layssa Souza
Contributor
January 27, 2025

Hi @Chris Melville , see if this helps you

 

1: Identify the Original Date/Time Field

  1. Make sure you already have a custom field of type Date/Time that will be used as the source for the calculation.

  2. Locate the ID of the field

Step 2: Create a Scripted Field

  1. Go to ScriptRunnerScripted Fields.

  2. Click Create Script Field.

  3. Configure the field:

    • Name: Event Time (UTC)

    • Template: Date/Time (important to match the script's return type).

    • Description: "Displays the event time in UTC, based on the original field."

3: Add the Script

  1. Copy the following script into the Script section:

import com.atlassian.jira.component.ComponentAccessor
import java.time.ZonedDateTime
import java.time.ZoneOffset
import java.util.Date

// ID of the original Date/Time field
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def dateTimeField = customFieldManager.getCustomFieldObject("customfield_XXXXX") // Replace with your field ID

if (dateTimeField) {
def fieldValue = issue.getCustomFieldValue(dateTimeField) as Date
if (fieldValue) {
// Convert the value to UTC and return as Date
def utcDate = ZonedDateTime.ofInstant(fieldValue.toInstant(), ZoneOffset.UTC)
return Date.from(utcDate.toInstant())
}
}
return null

Replace customfield_XXXXX with the actual ID of your source Date/Time field.

4: Add the Scripted Field to Screens

5: Test the Configuration

  1. Create or edit an issue that uses the original Date/Time field (customfield_22218).

  2. Verify that the Scripted Field (Event Time (UTC)) displays the correct time converted to UTC.

Additional Notes

  • Read-Only Field: Scripted Fields are calculated dynamically and cannot be edited directly. The value depends entirely on the source field (customfield_XXXXX).

  • Field Visibility: Ensure the source Date/Time field is added to the screens where users can populate it, as the Scripted Field depends on its value.

  • The line def utcDate = ZonedDateTime.ofInstant(fieldValue.toInstant(), ZoneOffset.UTC) can be modified to convert the date to other time zones instead of UTC. 
Let me know if you need further clarification! 😊Best Regards.

0 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 20, 2025

Hello @Chris Melville 

Date/time fields are stored as UTC in the Jira database. They are converted for display based on the viewing user's timezones setting.

Can you tell us more about the problem you are trying to solve? Is the problem related to displaying the data in UTC? Why would you need to do this? Do you need to filter data by UTC? Do you need to report based on UTC?

Chris Melville
Contributor
January 21, 2025

The usage is to track an 'Event Time' which must always be shown in UTC so that it can be used to index into external data sets, graphs, etc.  The data might be entered or viewed in one of many different timezones, but must always remain unaltered regardless of the use.

We just need a date-time picker that does no TZ conversion at all.  The help text for the field would indicate the field is always considered to be a UTC time.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 27, 2025

I am not aware of any method to "lock" a native Jira date/time/timestamp field to take the entry as UTC and display only UTC regardless of a user's timezone preference. I have not found anything in Atlassian's public backlog for that either.

Suggest an answer

Log in or Sign up to answer