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
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
Hey, Thanks for getting back here to share the solution. Wonderful!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to know!
Let us hear how it goes over there in our Sister Community.
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.