Confluence custom user macro relative date not working anymore
Asked by Francois Sabatini:

Hi,

We have a custom user macro that is no longer working and we are not able to fix the code.

This user macro compute dates based on current date

Here is the code:

## Macro title: Relative Date  
## Macro has a body: No  
## Body processing: No macro body  
##  

## This user macro compute date base on current date and the parameters  

## [@Param](/t5/user/viewprofilepage/user-id/1345631) type:title=Type\|type=enum\|required=true\|enumValues=Day,Week,Month,Year  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) increment:title=Increment\|type=int\|required=true\|desc= Increment value  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) rounded:title=Round\|type=enum\|required=false\|enumValues=Up,Down

<br />

## declare variables and initialize as java date objects with current date  

#set ($newDate = $action.dateFormatter.calendar)  
#set($increment = $generalUtil.convertToInteger("$paramincrement"))  
$newDate.setTime($content.currentDate)

## <https://docs.oracle.com/javase/7/docs/api/constant-values.html#java.util.Calendar.WEEK_OF_MONTH>

##Year  
#if( $paramtype == "Year" )  
$newDate.add(1, $increment)  
#if( $paramrounded == "Up")  
$newDate.set(6, $newDate.getActualMaximum(6))  
#elseif( $paramrounded == "Down" )  
$newDate.set(6, 1)  
#end  
##Month  
#elseif( $paramtype == "Month" )  
$newDate.add(2, $increment)  
#if( $paramrounded == "Up")  
$newDate.set(5, $newDate.getActualMaximum(5))  
#elseif( $paramrounded == "Down" )  
$newDate.set(5, 1)  
#end

##Week  
#elseif( $paramtype == "Week" )  
$newDate.add(4, $increment)  
#if( $paramrounded == "Up")  
$newDate.set(7, $newDate.getActualMaximum(7))  
#elseif( $paramrounded == "Down" )  
$newDate.set(7, 1)  
#end

<br />

##Day  
#elseif( $paramtype == "Day" )  
$newDate.add(6, $increment)  
#end

<br />

\<time datetime="$action.dateFormatter.formatGivenString("yyyy-MM-dd", $newDate.time)" class="date-upcoming"\>$action.dateFormatter.formatGivenString("dd MMM yyyy", $newDate.time)\</time\>

The type of error messages we see in Confluence now wherever the macro is used:

**$newDate.setTime($content.currentDate) $newDate.add(2, $increment) $newDate.set(5, $newDate.getActualMaximum(5)) ![](https://hssapps.int.bell.ca/wiki/plugins/servlet/confluence/placeholder/error?i18nKey=editor.placeholder.error&locale=en_US&version=2 "Invalid format: \"$action.dateFormatter.formatGive...\"")**

Anyone as an idea what is wrong in the code? It used to work fine until just recently...

Thanks!


Answers:
author: Matt
body: Was Confluence recently updated? This is a "feature" introduced in 7.19.x, more information about the bug and a workaround here: <https://jira.atlassian.com/browse/CONFSERVER-82741?src=confmacro>  

Similar questions have been asked throughout the community - [User macro not working as expected after version u... (atlassian.com)](https://community.atlassian.com/t5/Confluence-questions/User-macro-not-working-as-expected-after-version-upgrade-and/qaq-p/2370731)

comments: author: Florian Bonniec
body: [@Francois Sabatini](/t5/user/viewprofilepage/user-id/1299636)

The workaround of adding the JVM param works on Confluence 8.3 on my side, it should fix your issue. Confluence version do not fix the issue but the workaround does.

```
-Dmacro.required.velocity.context.keys=generalUtil,bootstrap,containerContext,action,req,content
```

Thx [@Matt](/t5/user/viewprofilepage/user-id/2006978)

Regards


author: Francois Sabatini
body: Thank you! The workaround worked for us. Updating Confluence did not resolve the issue


Tags: confluence-server

server