Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Velocity compare 2 dates

Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2020

Hi all

I had a good solution to compare two dates in a confluence user macro.

I checked both dates with the millisecond timestamp.

#set( $modDateTimeMillis = $childVersion.getLastModificationDate().getTime() )
#if( $modDateTimeMillis > $startDate.timeInMillis)
#set( $dummy = $allVersions.add($childVersion) )
#end

But since the update to confluence 7.4 the "getTime()" function gives no return value.

How can I get the milliseconds from a date?

or even better:

Does anybody know, how I can compare two dates in a confluence user macro? The DateTool of Velocity dosen't seems to work in confluence.

Regards, Dominic

2 answers

1 accepted

1 vote
Answer accepted
Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 27, 2020

The Developer community helped a lot! Also thank you @Diego for pointing to the developer community!

Here is the post and the answer: https://community.developer.atlassian.com/t/velocity-compare-2-dates/38614

My answer

Thanks a lot for all the support! 

First, I have to explain where the startDate comes from:

The startDate comes from a parameter in the user macro, which gives a german date in a string format.

#set( $startDate = $action.dateFormatter.getCalendar()) 
## Parse the parameter, which is a date in german format like "28.05.2020"
$startDate.set($year, $month, $day, 0, 0, 0)

This gives me a calendar date. The Calendar API says, that the compareTo method needs Calendar parameter. But the “getLastModificationDate()” returns a Date, not a Calendar.

What I did:

I get the Date from the Calendar with:

$startDate.getTime() 
#Returns a `Date` object representing this `Calendar` 's time value (millisecond offset from the [Epoch](https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html?is-external=true#Epoch)").

Now I can compare the two Dates with

#if( $startDate.getTime().compareTo($childVersion.getLastModificationDate()) ) 

And that worked for me!

Regards, Dominic

Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 28, 2020

Hey, Thanks for getting back here to share the solution. Wonderful!

Like Dominic Lagger likes this
0 votes
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 20, 2020

Hello @Dominic Lagger !

The behavior you described “But since the update to confluence 7.4 the "getTime()" function gives no return value.” Is indeed strange.

I have yet to try this method, but I will try to and update this thread with the results.

You also specified that there is a need to compare two dates. I was able to find this thread here in our community that might be helpful:

Further, I believe that this page should be helpful:

Looking at the methods of the available objects, some of them have been deprecated after Confluence 7.3.

There is also a bigger chance of you finding specialized help from our Developer community. Here, take a look:

 

I hope this helps! Looking forward to your reply.

Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 25, 2020

Hi @Diego 

Thanks for your answer.

The post for comparing two dates doesn't helped me out. I'm not able to get it work properly.

The page with the accessible objects from Velocity I also found. But also there, I'm not able to find a proper solution.

I now created a post in the developer community. Unfotunatley I was blocked (My account is "temporarily on hold"...

Regards, Dominic

Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 26, 2020

Hey, thanks for sharing this information with us @Dominic Lagger ! Would it be possible for you to share the question title you used in our Developer Community?
Also, are you using the same Atlassian Account in our Developer Community?

I will try to look into your current situation there.

Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 26, 2020

Hi @Diego 

The post was approved a little bit later, so all good :) 

https://community.developer.atlassian.com/t/velocity-compare-2-dates/38614

Regards, Dominic

Like Diego likes this
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 27, 2020

Glad to know!

Let us hear how it goes over there in our Sister Community.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events