Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Compare dueDate with currentDate in Velocity Template (duedate-columnview.vm) * Edit

Lars Hellström Marcus January 25, 2012

Edit*

Hi!

I am trying to do the same as the overdue field plugin. As it is right now not supporting JIRA 4.4.3. My only solution is to edit the templates to get the same result. No plugin for this time.

I have found following $content.getCurrentDate() and $dateutils.today().

I want to extract a number from these to dates that corresponds to how many days there are between.

I am using JIRA 4.4.3

* Edit

I have found new ways to complete this task by following code

#set( $difference = $currentMillis - $duedate.getTime() )
#set( $diffDays = $difference / (1000*60*60*24) )

The problem is now the first line. The substraction doesn't happen. And what I can see Jira doens't implement the mathTool. Is there any other way to complete this task?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Henry Mulherin February 22, 2012

I found the following worked for me

$dueDateFormatter.parseDatePicker($dueDateFormatter.format($date)).compareTo($duedate)

Lars Hellström Marcus February 22, 2012

It didn't work for me. I got 1 as answer all the time. Regardless what the duedate was set to.

Lars Hellström Marcus February 22, 2012

It seems that the $date variable doesn't exist.

Lars Hellström Marcus February 22, 2012

Thanks! The solutions works well for my purpose.

Morgan Nilsson February 23, 2012

I use Jira 4.4.3 and $date is null in duedate-columnview.vm, so

$dueDateFormatter.format($date) is the same as $dueDateFormatter.format(null)

$duedate is java.sql.Timestamp and the current date would be java.lang.Date so compareTo() should work
directly. But I cannot find any way to get the current date.

I want a solution where you don't have to parse a string (twice) to get Calendar.getInstance().

I have not found $dateutils.today(), only $dateutils.yesterday() and $dateutils.tomorrow(). :)

I cannot really understand why $dateutils.date($currentMillis) don't work?
I just gives me the literal text "$dateutils.date($currentMillis)". Maybe because the DateUtils class is not public?
According to the Velocity FAQ it may cause problems otherwise.

If I can use DateTool then everything would be easy. Does anyone know how I can add that tool to
the velocity context?

Morgan Nilsson February 23, 2012

I use Jira 4.4.3 and $date is null in duedate-columnview.vm, so

$dueDateFormatter.format($date) is the same as $dueDateFormatter.format(null)

$duedate is java.sql.Timestamp and the current date would be java.lang.Date so compareTo() should work
directly. But I cannot find any way to get the current date.

I want a solution where you don't have to parse a string (twice) to get Calendar.getInstance().

I have not found $dateutils.today(), only $dateutils.yesterday() and $dateutils.tomorrow(). :)

I cannot really understand why $dateutils.date($currentMillis) don't work?
I just gives me the literal text "$dateutils.date($currentMillis)". Maybe because the DateUtils class is not public?
According to the Velocity FAQ it may cause problems otherwise.

If I can use DateTool then everything would be easy. Does anyone know how I can add that tool to
the velocity context?

Like 최재웅 likes this
0 votes
Ron K January 26, 2012

I am not sure what you are exactly trying to do, but I have had good success inserting jQuery/JavaScript in Velocity Templates to manipulate output. Try inserting the following in the template as a test.

<script type="text/javascript">

jQuery(function($){

$(document).ready(function(){

var today = new Date();

alert( "${value} -"+ today);

});

});

</script>

Also, what version of JIRA are you using? The columunview templates have been modified in recent version and I believe there are some that are no longer used. I hope this helps.

Lars Hellström Marcus February 20, 2012

I can use javascript. But it's a dirty solution to my dirty solution.

TAGS
AUG Leaders

Atlassian Community Events