I what to report the number of days until a due date. The pseudo code might look like:
June 15, 2012 - NOW() = 63 days
Can a Confluence Webpage generate the value dynamically when before it is presented to the user to let them know the number of days before the due date?
I hope that make sense.
Thanks,
Troy
You could write a user macro for that. Here is my example that counts down the number of days until a specific date:
## 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>$action.dateFormatter.format($endDate): $deltaDays days $deltaHours hours $deltaMinutes minutes $deltaSeconds seconds</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
Learn more about user macros here: Guide To User Macro Templates
Hope this helps
Thanks for your help Remo.
Is this feature available in Confluence 3.5?
Do I need special admin privileges to create and install a user macro?
I can't find where I would install the user macro.
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, user macros are available in Confluence 3.5, but you need to have System Administrator permissions in order to create user macros.
Source: Writing User Macros
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi!
I am looking for a way to manage document retention periods. Imho this could be used just to do that, provided that every document has a clearly set end-date?
Could that be extended in a way that documents that are beyond the end date will be archived and/or purged?
Kind regards
Bernd
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User macros are only executed on page load. I would suggest you create a custom plugin with a Job Module for that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
thank you for this macro!
but the macro does not calculate the correct number of days.
30.12.2012 (US 12/30/2012)
and
30.12.2013 (US 12/30/2013)
it comes out the same result?
why?
thank you for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, it does calculate the correct number of days, just the remaining years are not displayed yet. If you want to display the remaining years also as days, you could rewrite the macro like this:
## Macro title: Date Countdown ## Macro has a body: No ## Body processing: No macro body ## ## Developed by: Remo Siegwart ## Date created: 21/07/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 delta #set( $delta = ($endDate.getTime() - $currentDate.getTime())) ## calculate remaining days #set( $deltaDays = ($delta / (24 * 3600 * 1000)) ) ## calculate remaining hours #set( $deltaHours = ($delta % (24 * 3600 * 1000)) / (3600 * 1000) ) ## calculate remaining minutes #set( $deltaMinutes = (($delta % (24 * 3600 * 1000)) % (3600 * 1000) / (60 * 1000)) ) ## calculate remaining seconds #set( $deltaSeconds = (($delta % (24 * 3600 * 1000)) % (3600 * 1000) % (60 * 1000)) / (1000) ) <div class="aui-message info shadowed"> <p>Countdown until <strong>$action.dateFormatter.format($endDate): $deltaDays days $deltaHours hours $deltaMinutes minutes $deltaSeconds seconds</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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm trying to get the message to say something like "N days, N hours, N minutes, N seconds until <event>" where <event> is the name of an event that you specify in the macro, for example, Bob's Anniversary.
Any idea how I can make it print a customizable message like this instead of what is currently prints?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
For simple calculations have a look at CelesteCS Math for Confluence plugin: https://marketplace.atlassian.com/plugins/com.celestecs.confluence.celestecs-math. Macros as well as table cell values may be used as formula operands.
----- UPDATE -----
We have added Date type support to Math macro so from now you may use our macro to accomplish what you want. Just specify the EXCEL-style formula, like "DAYS(NOW(), DATE(2016, 04,17))".
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I'm trying to setup a user macro that inserts a current timestamp on new entries as they're added to a page.
I'm able to show the current time/date using the below, but I'm having trouble figuring out how to get the value to remain static, rather than updating to show the current time:
## @noparams
$action.dateFormatter.formatDateTime($content.currentDate)
I wondered whether anyone would have suggestions on what I'd need to add to get this to act as an actual timestamp rather than a clock?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
thank you for this macro!
but the macro does not calculate the correct number of days.
30.12.2012 (US 12/30/2012)
and
30.12.2013 (US 12/30/2013)
it comes out the same result?
why?
thank you for your help
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.