How do I display a version release date in a custom release notes velocity template?

Jason Plumhoff
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.
August 9, 2012

After a bit of searching, I found that the "$version.getReleaseDate()" function will return a date object that has the information I'm trying to display. But the problem is that I can't figure out how to format the returned object so that it will render as a string in the release notes. It seems like it should be simple, but I just haven't been able to get anything to work. Can anyone provide a function that will format this date as a string?

Thanks,

Jason

Edit - Here's the template I'm trying to use. Everything works except the release date:

#macro (getReleaseNoteComment $issue $customFieldManager)
    #set ($customFields = $customFieldManager.getCustomFieldObjects($issue.project.getLong("id"), $issue.issueType.getString("id")))
    #foreach($customField in $customFields)
        #if($customField.name.equals("Release Notes"))
            #if($customField.getValue($issue))
               $textUtils.htmlEncode($customField.getValue($issue))
            #end
        #end
    #end
#end
              
<title>$action.getText('release.notes.text.title', $project, $version) </title>
<body>
    <h1>$action.getText('release.notes.heading', $project, $version)<br>$!dateFormatter.format($version.getReleaseDate())</h1><P>
        <table>
            <tr>
                <td>
                    #foreach ($issueType in $issueTypes)
                         #if($issueType.issues.size() > 0)
                             #if ($textUtils.htmlEncode($issueType.name) == "Bug")
                                #set ($FixedIssueTypeName = "Resolved Issues")
                             #elseif ($textUtils.htmlEncode($issueType.name) == "Improvement")
                                #set ($FixedIssueTypeName = "Enhancements")
                             #else
                                #set ($FixedIssueTypeName = $textUtils.htmlEncode($issueType.name))
                             #end
                             <h2>$FixedIssueTypeName</h2>
                             <ol>
                                 #foreach ($issue in $issueType.issues)
                                 <li style="padding-bottom:12pt;"><Strong>[<a xhref='$!appProps.getString("jira.baseurl")/browse/$issue.key'>$issue.key</a>] -
                                     $textUtils.htmlEncode($issue.summary)</Strong><BR>#getReleaseNoteComment($issue $customFieldManager)</li>
                                 #end
                             </ol>
                         #end
                    #end
                </td>
            </tr>
    </table>
</body>

2 answers

1 accepted

0 votes
Answer accepted
jftempo January 9, 2013

Not very clean but this code works:

#macro (getVersionDate $issueTypes $versionName)
#set( $seen = "0" )
#foreach ($issueType in $issueTypes)
#if($issueType.issues.size() > 0)
#foreach ($issue in $issueType.issues)
#foreach ($vv in $issue.fixVersions)
#if($seen.equals("0") && $vv.name.equals($versionName))
$textUtils.htmlEncode($vv.getReleaseDate().toLocaleString().replace('00:00:00', '')) #set( $seen = "1" )
#end
#end
#end
#end
#end
#end

......
<h1>#getVersionDate($issueTypes $version) $textUtils.htmlEncode($project) version $textUtils.htmlEncode($version)</h1>
.....

Please feel free to make it better.

Jason Plumhoff
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.
January 9, 2013

THANK YOU! That did exactly what I wanted!

Jason Plumhoff
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.
January 9, 2013

Oops - I did have to change the '00:00:00' to '12:00:00 AM' to get rid of the time, but otherwise it did what I wanted. :)

Diogo_Barbosa March 26, 2020

in what context can I use your solution? I am interested, but couldn´t understand. Thanks in advance

0 votes
SherryX
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.
August 9, 2012

Try dateformatter.formatDMYHMS or dateformatter.format

hope this helps

Sherry

Jason Plumhoff
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.
August 9, 2012

Sherry - thanks for responding! Unfortunately neither of these worked. All I got back was "$dateFormatter.format($version.getReleaseDate())" or "$dateFormatter.formatDMYHMS($version.getReleaseDate())". I also tried "$outlookDate.format($version.getReleaseDate())" with no luck. I know somebody else must have done this before...

Suggest an answer

Log in or Sign up to answer