Help with post-function script returning wrong date

Francisco Fuentes February 15, 2024

Hello!

I need help getting the desired result when using the following JMWE post-function script to return specific days of the week in my custom field's calendar:

Date date = new Date();
int day = date.day;


if (day == 0) {
day = 7;
}

int daysToAdjust = (day <= 2) ? (4 - day) : (2 - day);

return date + daysToAdjust;

Basically, if the current day is thursday, friday, saturday, sunday or monday, it should return the upcoming tuesday, and if the current day is tuesday or wednesday it should return the upcoming thursday.

Now, if the current day is Thursday, this script returns the Tuesday of the current week (past Tuesday) instead of the upcoming one. It should always return the upcoming Tuesday or Thursday.

Any ideas on how to modify this script?

1 answer

1 accepted

1 vote
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 15, 2024

Hi @Francisco Fuentes 

I believe this should work:

int daysToAdjust = (day == 2 || day == 3) ? (4 - day) : (day == 1) ? 1 : (9 - day);
Francisco Fuentes February 15, 2024

It totally worked!

 

Thanks again for your help.

Suggest an answer

Log in or Sign up to answer