Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

fieldsJEMH JEMH velocity context, relating to emails (comment header specifically) has $sentDate (if present, reverts to now() if not) as well as $receivedDate.  Presentation of these dates can be altered through helper classes in the velocity context.

...

JEMH can build date objects too, to enable values to be generated for arbitrary dates, ege.g.:

Date Time
Code Block
#set($longVal = $currentMillis.longValue() + 86400000 )
$dateFormatter.format($jemhDateUtils.createDate($longVal))

...

Code Block
#set($longVal = $currentMillis.longValue() + 86400000 )
$dateFormatter.withStyle($dateTimeStyle.DATE).format(formatDMY($jemhDateUtils.createDate($longVal))

Example Output:

29/Mar/15

...

DatePicker custom fields

Code Block
$dateFormatter.formatDatePicker($issue.getCustomFieldValue("customfield_10700"))

For further Date formatting options please see:

...

...

...

...

...

JEMHDateUtils

Status
colourRed
titlesince 3.2.6

...

Code Block
#set ($headerDate = "Wed, 19 Feb 2020 14:50:59 +0000")
#set ($dateFormat = "E, ddd MMM yyyy HH:mm:ss Z")
#set ($date = $jemhDateUtils.getZonedDateTime($headerDate, $dateFormat))
The date/time in the email is: $date.format($jemhDateUtils.getFormatter($dateFormat))

#set ($zone = $jemhDateUtils.getZoneId("America/Los_Angeles"))
#set ($laTime = $date.withZoneSameInstant($zone))
In Los Angeles this is: $laTime.format($jemhDateUtils.getFormatter($dateFormat))

Debugging velocity rendered custom fields as above is a bit tedious (issue JEMH-7794 logged to pick and evaluate script against a stored JEMH Test Case email). For rapid testing against a Test Case, you can do the same thing in a Script Field Processor edit window:

Code Block
if (message.getHeader("Date") !=null)
{
 var headerDate = message.getHeader("Date")[0];
 var dateFormat = "E, d MMM yyyy HH:mm:ss Z";
 var date = jemhDateUtils.getZonedDateTime(headerDate, dateFormat);

print ('The date/time in the email is: ' +date.format(jemhDateUtils.getFormatter(dateFormat)) );

 var zone = jemhDateUtils.getZoneId("America/Los_Angeles");
 var laTime = date.withZoneSameInstant(zone);

print ('In Los Angeles this is: '+laTime.format(jemhDateUtils.getFormatter(dateFormat)) );
}
else
{
    print ('no Date: header');
}

The key functionality to note:

  • ZonedDateTime - we are using ZonedDateTime which allows us to retain the timezone time zone aspect along with the date + time. This is vital aspect in case you’d wish to convert this to another timezone time zone (which is what is being done in the above example)

  • Formatter - to format the date in a certain pattern (i.e. 12/02/2020 - 08:29), we have provided the getFormatter(pattern) method which is responsible for returning a DateTimeFormatter. The same can be used to format the ZonedDateTime to any other preferred format

...

This set of methods doesn’t depend on any Jira user in the authentication context, ege.g., you want to do date/time manipulation for a custom field default

Code Block
$jemhDateUtils.createLocalDate().plusDays(15).format($jemhDateUtils.getFormatter("dd/MMM/yy"))

If you want to use the Jira format:

Code Block
#set ($javaDateFormat = $applicationProperties.getDefaultBackedString("jira.date.picker.java.format"))
#set ($formatter = $jemhDateUtils.getFormatter($javaDateFormat))
$jemhDateUtils.createLocalDate().plusDays(14).format($formatter)

Filter by label (Content by label)
showLabelsfalse
max5
spacesJEMH
sortmodified
showSpacefalse
reversetrue
typepage
cqllabel in ( "velocity" , "template" , "macro" , "date" ) and space = "JEMH"
labelsevent listener jemh issue notification
Page Properties
hiddentrue

Related issues