Forums

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

Confluence custom user macro relative date not working anymore

Francois Sabatini
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!
June 1, 2023

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 type:title=Type|type=enum|required=true|enumValues=Day,Week,Month,Year
## @Param increment:title=Increment|type=int|required=true|desc= Increment value
## @Param rounded:title=Round|type=enum|required=false|enumValues=Up,Down


## 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


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


<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)) 

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

Thanks!

1 answer

1 accepted

1 vote
Answer accepted
Matt
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.
June 2, 2023

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)

Florian Bonniec
Community Champion
June 6, 2023

@Francois Sabatini

 

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  

Regards

Like # people like this
Francois Sabatini
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!
June 14, 2023

Thank you! The workaround worked for us. Updating Confluence did not resolve the issue

Like # people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.19.7
TAGS
AUG Leaders

Atlassian Community Events