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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Dummy's Use of Macros

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.

 

2 answers

2 accepted

1 vote
Answer accepted
DPK J Community Leader Sep 07, 2019

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 =&gt; 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 )

&lt;div class="aui-message info shadowed"&gt;
  &lt;p&gt;Countdown until &lt;strong&gt;$deltaDays days $deltaHours hours $deltaMinutes minutes&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;
#else
## currentDate is after endDate
&lt;div class="aui-message success shadowed"&gt;
  &lt;p&gt;Countdown to &lt;strong&gt;$action.dateFormatter.format($endDate)&lt;/strong&gt; expired &lt;strong&gt;$generalUtil.getRelativeTime($endDate)&lt;/strong&gt;!&lt;/p&gt;
&lt;/div&gt;
#end
DPK J Community Leader Sep 07, 2019

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.

@Ormond_StockI think you should accept this answer by @DPK J . You have currently accepted your own answer :-)

0 votes
Answer accepted

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.

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 =&gt; calculate deltas
#set( $delta =  ($endDate.getTime() - $currentDate.getTime()) / 1000)
## calculate remaining days
#set( $deltaDays = $delta % 365 )

$deltaDays
#end

 

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.

DPK J Community Leader Sep 08, 2019

@Ormond_StockMy 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 =&gt; 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
Like Vitor LC likes this

Fantastic, thank you very much.  Appreciated!

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.

@DPK Jyou 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?

DPK J Community Leader Oct 31, 2019

@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,

  1. User defined Macro (the macro discussed in this thread is of this type)
  2. Developer Macro Module (you need Java and plugin development knowledge for this)

@DPK JThanks for all the reference. I will definitely take a look :)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

408 views 23 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you