I want to find a way of using a macro from (https://community.atlassian.com/t5/Confluence-questions/How-to-evaluate-values-on-Confluence-Page/qaq-p/331934#M56003). I don't know anything about macros.
I have created a macro in Confluence called datecountdown and copied the script into it.
When I add it to a page I get:
"<div class="aui-message info shadowed"> <p>Countdown until <strong>Feb 29, 2020: 173 days 8 hours 36 minutes 20 seconds</strong></p> </div>" rather than the number of days.
I don't know how to write macros, is there something simple a dumb user can do to add a macro to a page?
Help appreciated.
I am modifying this to just print number if days, hours and minutes,
## Macro title: Date Countdown ## Macro has a body: No ## Body processing: No macro body ## ## Developed by: Remo Siegwart ## Date created: 14/04/2012 ## This user macro counts down the number of days until a specific date ## @param endDate:title=End Date|type=date|required=true|desc=The end date. Format: mm/dd/YYYY ## declare variables and initialize as java date objects with current date #set ( $endDate = $content.currentDate ) #set ( $currentDate = $content.currentDate ) ## parse endDate param to milliseconds and set as time of endDate variable $endDate.setTime($content.currentDate.parse($paramendDate)) ## now we have 2 valid java date objects to work with #if($currentDate.before($endDate)) ## currentDate is before endDate => calculate deltas #set( $delta = ($endDate.getTime() - $currentDate.getTime()) / 1000) ## calculate remaining seconds #set( $deltaSeconds = $delta % 60 ) #set( $delta = $delta / 60 ) ## calculate remaining minutes #set( $deltaMinutes = $delta % 60 ) #set( $delta = $delta / 60 ) ## calculate remaining hours #set( $deltaHours = $delta % 24 ) #set( $delta = $delta / 24 ) ## calculate remaining days #set( $deltaDays = $delta % 365 ) <div class="aui-message info shadowed"> <p>Countdown until <strong>$deltaDays days $deltaHours hours $deltaMinutes minutes</strong></p> </div> #else ## currentDate is after endDate <div class="aui-message success shadowed"> <p>Countdown to <strong>$action.dateFormatter.format($endDate)</strong> expired <strong>$generalUtil.getRelativeTime($endDate)</strong>!</p> </div> #end
Macro in Confluence are similar to Macro in word or excel.
Confluence provide some built-in macro, if these Macro doen't suffice our need we can create User Macro which provide little bit of programming, and if we want full control we can Java Macro code using Java API and plugin model provided my Confluence.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@[deleted]I think you should accept this answer by @DPKJ . You have currently accepted your own answer :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, but neither response answers my question. I don't have the time to learn how to write macros, I just want to use that one to show the number of days until a date on my page. The one above simply gives me a piece of HTML, not a number.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have updated given HTML and it is just a number now,
## Macro title: Date Countdown ## Macro has a body: No ## Body processing: No macro body ## ## Developed by: Remo Siegwart ## Date created: 14/04/2012 ## This user macro counts down the number of days until a specific date ## @param endDate:title=End Date|type=date|required=true|desc=The end date. Format: mm/dd/YYYY ## declare variables and initialize as java date objects with current date #set ( $endDate = $content.currentDate ) #set ( $currentDate = $content.currentDate ) ## parse endDate param to milliseconds and set as time of endDate variable $endDate.setTime($content.currentDate.parse($paramendDate)) ## now we have 2 valid java date objects to work with #if($currentDate.before($endDate)) ## currentDate is before endDate => calculate deltas #set( $delta = ($endDate.getTime() - $currentDate.getTime()) / 1000) ## calculate remaining days #set( $deltaDays = $delta % 365 ) $deltaDays
#end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Brilliant, thank you, it now gives a number - but unfortunately an incorrect one. With and end date of 28th Feb 2020 it should give 172 days from 9th Sept, but it gives a different number every time I load the page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@[deleted]My mistake, try this
## Macro title: Date Countdown ## Macro has a body: No ## Body processing: No macro body ## ## Developed by: Remo Siegwart ## Date created: 14/04/2012 ## This user macro counts down the number of days until a specific date ## @param endDate:title=End Date|type=date|required=true|desc=The end date. Format: mm/dd/YYYY ## declare variables and initialize as java date objects with current date #set ( $endDate = $content.currentDate ) #set ( $currentDate = $content.currentDate ) ## parse endDate param to milliseconds and set as time of endDate variable $endDate.setTime($content.currentDate.parse($paramendDate)) ## now we have 2 valid java date objects to work with #if($currentDate.before($endDate)) ## currentDate is before endDate => calculate deltas #set( $delta = ($endDate.getTime() - $currentDate.getTime()) / 1000) ## calculate remaining seconds #set( $delta = $delta / 60 ) #set( $delta = $delta / 60 ) #set( $delta = $delta / 24 )
## calculate remaining days #set( $deltaDays = $delta % 365 ) $deltaDays #end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fantastic, thank you very much. Appreciated!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
I totally understand how Ormond feels and what he is getting at. I am do not have much macro knowledge as well but i there is so much needed to be done on confluence which the functions are not available.
@DPKJyou mentioned that Confluence provide some built-in macros. Can i know where can i find them?
Is there any references or documentations which a newbie macro user like me can refer to when writing a macro or to learn how to write a macro?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jason_TeoEverything that is not plain text is kind of a Macro in Confluence.
Macro can be as simple as banner, side-bar etc and as complex as fetching data from external source and displaying on Confluence page.
So, if you are getting started with Confluence, read this - https://confluence.atlassian.com/doc/get-started-777010817.html
And also watch this webinar - https://www.youtube.com/watch?v=y1YTsMTrC7c
if you want to build a Macro, you have two options,
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.