[CONF] Use velocity to find the date 6 months ago?

I'm modifying a macro that lists all the users on Confluence, but I'd like to be able to evaluate whether the user last logged in 6 months ago. I wanted to know how I could a) get the date 6 months ago 'today' and b) evaluate whether the last login date is farther than 6 months before it.


2 answers

1 accepted

Here's what you can use:

First you have set a variable for how long ago you want to test for in seconds. For example, 180 days in seconds is 15,552,000 seconds. So:

#set ($t1 = 15552000)

Then you have to get the current UNIX time.

#set ($t2 = $content.currentDate.time)

Then you need the time that you want to check. In this example, I am finding the date the user last logged in (note that these are arbitrary method and class names).

#set ($t3 = $loginManager.getLoginInfo($user).lastSuccessfulLoginDate.time)

Finally, you just need to do some maths.

#set ($t4 = $t2-$t3)

#if ($t4 > $t1)
   <p>They haven't logged in over 6 months!</p>
   <p>Leave them be!</p>

I haven't tested this yet but it should work.

I'm guessing you didn't try it. Didn't work for me.

It does work but it has to be part of a larger #foreach loop. $loginManager needs to be defined, as does $user. For example, see https://answers.atlassian.com/questions/33385/macro-that-produces-a-list-of-users-last-login-date

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,146 views 13 19
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot