Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I configure my Date Time custom field to offset in the picker the same way as the built in Due Date field?

Ronald Horner
Contributor
January 25, 2012

We have a series of custom date fields that we want to have set. Our users' timezones are set to the default JIRA timezone, GMT, but our desktops are scattered around the world. When we click to add the time on Due Date, the displayed date time is offset to be the same as GMT, so if a user is in 12:00 CST they would then see 17:00 GMT. This does not show up for our custom fields, the picker show the local time in the local timezone. How do I get the custom field to have the same behavior?

4 answers

1 accepted

0 votes
Answer accepted
Ronald Horner
Contributor
April 15, 2012

I have found a solution. It was to create a custom field that initializes the date picker calendar with the system time. And it was an incredibly easy solution to write. Why Atlassian doesn't offer this custom field out of the box is mind boggling. Perhaps in the future Atlassian could design for disable so that new features can be ignored if not actually needed.

I did this by creating a new macro. Turns out that the Calendar (put in link to the Calendar library) doesn't like to parse the date based on the set format Internet Explorer or Firefox. This is an issue. What I did was modify the to change it to a format it would parse on all platforms: YYYY/MM/DD HH:MM where HH is in 24 hour format.

#macro (serverPopup $inputField $inputButton $dateTimeFormat $dateFormat $timeFormat $dateTimePicker $currentMillis $currentCalendar)
    $calendarIncluder.includeForLocale($i18n.getLocale())
    #set ($firstDay = $currentCalendar.firstDayOfWeek - 1)
    #set ($dateFormatter = $dateFormatter.withSystemZone())
    <input title="date" type="hidden" value="$dateFormatter.format($dateutils.date($currentMillis))" />

    <fieldset class="hidden datepicker-params">
        <input title="firstDay" type="hidden" value="$firstDay" /> ## first day of the week
        <input title="inputField" type="hidden" value="$inputField" /> ## id of the input field
        <input title="button" type="hidden" value="$inputButton" /> ## trigger for the calendar (button ID)
        <input title="align" type="hidden" value="Br" /> ## alignment (defaults to "Bl")
        <input title="singleClick" type="hidden" value="true" />
        <input title="date" type="hidden" value="$dateFormatter.format($dateutils.date($currentMillis))" />
        #if($!{dateTimePicker})
            <input title="ifFormat" type="hidden" value="$textutils.htmlEncode($dateTimeFormat)" /> ## our date and time format
            <input title="showsTime" type="hidden" value="true" /> ## display the time selector
            <input title="timeFormat" type="hidden" value="$textutils.htmlEncode($timeFormat)" /> ## 12 or 24 hours format
        #else
            <input title="ifFormat" type="hidden" value="$textutils.htmlEncode($dateFormat)" /> ## our date only format
        #end
    </fieldset>
#end

There is a little more to this solution that included extending DateTimeCFType and replacing all of the forLoggedInUser() with withSystemZone(). This was done in the constructor for CustomDateTimeCFType

datePickerFormatter = dateTimeFormatterFactory.formatter().withSystemZone().withStyle(DateTimeStyle.DATE_TIME_PICKER);

I also changed view-datetime.vm to display a Z at the end of the time so the user would know it was in Zulu time.

#if ($value)
    #if ($customField.customFieldType.isUseNow($value))
      Current date will be used
    #else
        <span title="$titleFormatter.format($value)"><time datetime="$iso8601Formatter.format($value)">$datePickerFormatter.format($value)Z</time></span>
    #end
#end

0 votes
Nikolay Borodachev
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 5, 2020

@Ronald Horner , we are facing a similar issue where we need a date/time field to be displayed and edited in UTC time zone. 
I'd like to try your solution but it seems to be incomplete.

I.e., where do you put the new macro (file name)? Where is this macro called from? How are you extending DateTimeCFType? Does it require creating a new Jira plugin?

Please provide some clarity of how to make this work.

Thank you
Nikolay

0 votes
Ronald Horner
Contributor
February 21, 2012

Short answer is that you can't. I'll look into writing a custom date time field that can.

0 votes
Ronald Horner
Contributor
February 6, 2012

If you set a default value in the Date Time custom field then it will default to the correct server time. This makes me think that the picker popup is linked to the input box.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events