So I have a macro that will subtract a number of days from today's date, is there a way of having an input that determines the numbers of days to be subtracted i.e Macro(5) would subtract 5 days from today, macro(12) would be todays date minus 12 days etc.
here is the hardcoded date marco:
#set ( $date = $action.dateFormatter.calendar )
$date.setTime($content.currentDate)
$date.add(6, -3)
<time datetime="$action.dateFormatter.formatGivenString('yyyy-MM-dd', $date.time)"/>
Hi,
I assume you are using a user macro.
Yes, you will have to specify a macro parameter of type "int" and make it "required" so that the user must specify it.
Then you can reference it in your template code and make the appropriate calculation.
Documentation: https://confluence.atlassian.com/doc/writing-user-macros-4485.html
If this answers your question please mark it as answered.
Thanks but it seems to not like a variable in $date.add as I get:
$date.add(6, $paramName) 31 Jan 2018
when using this:
## @param Name:title=Name|type=int|default=12|required=true
#set ( $date = $action.dateFormatter.calendar )
$date.setTime($content.currentDate)
$date.add(6, $paramName)
<time datetime="$action.dateFormatter.formatGivenString('yyyy-MM-dd', $date.time)"/>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try just to print out the new variable directly on the page before you use it in a function to ensure that it has been declared correctly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep that works fine!
If I use
...
$date.add(6, $paramName)
<time datetime="$action.dateFormatter.formatGivenString('yyyy-MM-dd', $date.time)"/>
$paramName
I get:
$date.add(6, $paramName) 31 Jan 2018 12
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Got it working at last... looks like it sees the int as a string, so this converts it to an int:
## @param Name:title=Name|type=int|default=1
#set ( $Integer = 0 )
#set ($paramName = $Integer.parseInt($paramName))
#set ( $date = $action.dateFormatter.calendar )
$date.setTime($content.currentDate)
$date.add(6, $paramName)
<time datetime="$action.dateFormatter.formatGivenString('yyyy-MM-dd', $date.time)"/>
Found it here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think we found the same solution at about the same time....was just about to post it for you :)
Glad you got it working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.