Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I want a Scripted Field which will show only time in UTC bypassing the User's local timezone

Want to ByPass the date time functionality of jira and create a date time type scripted field which will show the UTC value onn all users profile no matter what timezone he is in.

using date time calculated field will also work if someone has the formula ready.

Thanks in advance,

Sumit

3 answers

1 accepted

0 votes
Answer accepted

Hi Nic,

I was able to write a script by myself

**************************************************************

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.fields.CustomField

import org.apache.log4j.Level

import org.apache.log4j.Logger

import java.text.SimpleDateFormat;

import com.atlassian.jira.issue.IssueManager;

Logger log = Logger.getLogger("********* Chaging Field **********");

log.setLevel(Level.DEBUG)

//log.debug("##########################################################".toString())

//log.debug("##########################################################".toString())

//log.debug("##########################################################".toString())

ComponentAccessor comAcc=new ComponentAccessor()

CustomFieldManager cfm = comAcc.getCustomFieldManager()

IssueManager issueManager = comAcc.getIssueManager()

CustomField time = cfm.getCustomFieldObject('customfield_10601') // id to be changed

timeValue=issue.getCustomFieldValue(time)

// log.debug("timeValue ::: ${timeValue}".toString())

if(timeValue!=null){

//log.debug("Time in UTC is:::: Not Null".toString())

SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");

Date date = sdf.parse("${timeValue}");

sdf.setTimeZone (TimeZone.getTimeZone ("Etc/GMT"));

UTCtime=sdf.format(date)

return UTCtime

//log.debug("Time in UTC is:::: ${UTCtime}".toString())

}

else {

return null

}

****************************************

Actually, I wanted to bypass the time mechanism of jira and show the time in UTC for one custom field.

As of now it is working fine , I will comment back if any bug is observed

thanks a lot for looking into the question.

Regards,

Sumit

1 vote

Could you explain what you are trying to display and where?

I understand you want to show the UTC value of a date/time, but what actual date/time do you need? The current time? Issue created? Updated? A custom field?

You also talk about "users profile" - fields belong to issues, not users, but it's not clear why you mention the profile.

Actually, Groovy provides a very handy enhancement to Date class, the Date.format() method.

So, you can simply use following snippet to have the same effect:

import com.atlassian.jira.component.ComponentAccessor

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10001') // id to be changed
def time = issue.getCustomFieldValue(cf) as Date return time?.format("yyyy-MM-dd HH:mm:ss", TimeZone.getTimeZone("Etc/GMT"))

The Date.format() documentation also shows how to format your date representation.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New cloud apps roundup - June 2021

Since our last roundup in April, Atlassian's Marketplace Partners have added over 100 new cloud apps to the Atlassian Marketplace to help your teams work more efficiently. Let’s take a quick look a...

351 views 5 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you