#1 2018-12-11 17:21:40

FLU73
Member
Registered: 2018-10-25
Posts: 38

date parameter with formula in UE language

Hello,

I'am trying to create a date parameter with formula, but it's not working as expected :

example #1:
${today == today.addYears(0).setMonth(12).setDay(11) ? today.addDays(-1) : today.addDays(1)}

which means :
if today_date = 11/12/2018
then 10/12/2018
else 12/12/2018

As current day is 11/12/2018, I am expecting to get the result 2018-12-10
but when executing, the returned value is 2018-12-12

I would like to try with :
${today == 2018-12-11 ? today.addDays(-1) : today.addDays(1)}
but I get an error "Cannot coerce '20181211' of class net.datenwerke.rs.utils.juel.wrapper.TodayWrapper to class java.lang.Long (incompatible type)"


example #2:
${today >= today.addYears(0).setMonth(12).setDay(15) ? today.firstDay() : today.lastDay()}
if today_date => 15/12/2018
then 01/12/2018
else 31/12/2018

I get the error : "lexical error at position 8, encountered invalid character '=', expected expression token"
operators like "=>" or ">=" or "ge" are not usable with dates ?
("ge" returns : Cannot compare 'class net.datenwerke.rs.utils.juel.wrapper.TodayWrapper' and 'class net.datenwerke.rs.utils.juel.wrapper.TodayWrapper')

As a newbie, I probably don't use the correct syntax, but I did not found examples on the forum or on other websites.

Offline

#2 2018-12-11 18:17:06

eduardo
Administrator
Registered: 2016-11-01
Posts: 1,004
Website

Re: date parameter with formula in UE language

Hi FLU73,

please try with:
${today.equals(today.addYears(0).setMonth(12).setDay(11)) ? today.addDays(-1) : today.addDays(1)}

since today objects are dates, thus java objects, you cannot compare them with "==". Check here for more information:
https://www.admfactory.com/how-to-compa … s-in-java/

Regards,
Eduardo

Offline

#3 2019-01-03 18:01:03

FLU73
Member
Registered: 2018-10-25
Posts: 38

Re: date parameter with formula in UE language

Hi Eduardo,

Thanks for the link, but it seems to not work.

I've used the code : ${(today).compareTo(today.addYears(0).setMonth(04).setDay(01)) == 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}

but when executing the query, I get the error : Method not found: class net.datenwerke.rs.utils.juel.wrapper.TodayWrapper.compareTo(net.datenwerke.rs.utils.juel.wrapper.TodayWrapper)

I wonder if date.compareTo() is found in the library, in the link they have :
package com.admfactory.date;
import java.text.SimpleDateFormat;
import java.util.Date;

Maybe something need to be added somewhere.

Offline

#4 2019-01-04 09:10:16

eduardo
Administrator
Registered: 2016-11-01
Posts: 1,004
Website

Re: date parameter with formula in UE language

Hi FLU73,

please try with  ${today.getDate().compareTo(today.addYears(0).setMonth(4).setDay(01)) == 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}

Regards,
Eduardo

Offline

#5 2019-01-09 10:12:12

FLU73
Member
Registered: 2018-10-25
Posts: 38

Re: date parameter with formula in UE language

Hi Eduardo,

Ok, it's fixed.
I tried what you suggested:
${today.getDate().compareTo(today.addYears(0).setMonth(4).setDay(01)) == 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}

Due to persistence of error message, I've replaced it by:
${today.getDate().compareTo(today.addYears(0).setMonth(4).setDay(01).getDate()) == 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}

it works fine with == operator, but not with <, or <=

Finally, it works with: lt, gt
${today.getDate().compareTo(today.addYears(0).setMonth(4).setDay(01).getDate()) lt 0 ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}

or with: before, after
${today.getDate().before(today.addYears(0).setMonth(4).setDay(01).getDate()) ? today.addYears(-1).addMonths(0).addDays(0) : today.addYears(1).addMonths(0).addDays(0)}

Offline

Board footer

Powered by FluxBB