Forums

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

Math-Time Expression required for JWT plugin post function

SWAPNIL SRIVASTAV
Contributor
August 13, 2019

We want to populate a Date and Time picker custom field while using the JWT post function "Create issues and subtasks" with the following logic:

If System Time <16:30:00, then Date part of the field - same as system date and Time part of the field - System Time+ 30 Minutes.

If System Time >16:30:00, then Date part of the field - next working day and Time part of the field = 10:00.

Could you please help us with the math/time expression for above logic, so that we can use the same while creating issues.

Any help would be appreciated.

1 answer

1 vote
Thorsten Letschert _Decadis AG_
Community Champion
August 14, 2019

Hi @SWAPNIL SRIVASTAV ,

what you're trying to implement should be absolutely possible.

Could you please further elaborate the schedule you're thinking of, e.g. specifiy your 'working days' (MO - FR?) as well as the starting time for each day?

I got you covered regarding the following examples:

  • Today 12:05 > Today 12:35
  • Today 18:00 > Tomorrow (if tomorrow is a working day) 10:00
  • Today 23:59 > Tomorrow (if tomorrow is a working day) 10:00

I'm curious about the exact limits starting from 00:00 (assumptions following):

  • Today 00:01 > Today 10:00
  • Today 09:45 > Today 10:00
  • Today 10:05 > Today 10:25

Cheers
Thorsten

SWAPNIL SRIVASTAV
Contributor
August 16, 2019

Hi @Thorsten Letschert _Decadis AG_ ,

We have come up with it :

Math-Time Expression.PNG

and it is working fine. Any improvements are welcome.

Thanks,

Swapnil Srivastav

Thorsten Letschert _Decadis AG_
Community Champion
August 19, 2019 edited

Hi @SWAPNIL SRIVASTAV ,

first of all congrats to coming up with a valid solution yourself.

With regard to future maintainability, personally I'd prefer a more generic approach using schedules (see the documentation).

First, create a schedule, e.g. called Business Hours using the expression

MON-FRI{10:00-16:30;}

community_schedule.PNG

Afterwards, use this schedule within your expression, that's then is as short as (00057 is the field code for Current date and time):

inSchedule({00057}, "Business Hours", LOCAL) ? {00057} + 30 * {MINUTE} : nextTime({00057}, "Business Hours", LOCAL)

Update: just saw that you were skipping weekends when adding those 30 minutes. To do so, the correct expression would be:

inSchedule({00057}, "Business Hours", LOCAL) ? addTime({00057}, 30 * {MINUTE}, "Business Hours", LOCAL) : nextTime({00057}, "Business Hours", LOCAL)

Short explanation of the expression above:

  • Check whether current date and time is within the schedule provided
  • If so, just add 30 minutes
  • If not, use the next date/time that would be in schedule again

The advantages, apart from a shorter expression, lie primarily in the future maintainability and flexibility in editing the business hours (e.g. taking holidays into account, using different hours per weekday, etc.).

Cheers
Thorsten

Like • Max Foerster - K15t likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events