Does anyone have a pattern available to determine difference between two timestamps and add the duration to another timestamp, both of which calculations would exclude weekends?

For example, three inputs and one output:

- Baseline start timestamp
- Baseline end timestamp
- Target start timestamp

Logic would find the time diff between 1 and 2, excluding weekends and add that time to 3, excluding weekends to land on target end timestamp.

For example, using reference range of last Friday 1/28 until Thursday 2/3 and target start of Friday 2/4. The 4 day difference would be calculated and added to 2/4 - excluding the coming weekend, result would be Thursday 2/10.

Thanks!

Adam

Hey @ahouston,

I believe that the pipeline below will give you the result you need:

Dates Difference_2022_02_03.slp (5.1 KB)

It can be done in one mapper, but itâ€™ll become a bit messy.

Bojan

2 Likes

This is fantastic Bojan! Very much appreciated.

I really like the approach taken although this doesnâ€™t work when difference is one or two days and target start is a Friday. For example:

{

â€śstartDateâ€ť: â€ś2022-01-28â€ť,

â€śendDateâ€ť: â€ś2022-01-31â€ť, <<2022-02-01>>

â€śtargetStartDateâ€ť: â€ś2022-02-04â€ť

}

In these cases, the filter range and and and index get out of alignment.

Is there an elegant way to solve? Iâ€™m building ternary operations for each exception but thinking there has to be something cleaner.

We can add some specific number of days to this calculation, which is basically a failsafe mechanism for picking up working days. Before it was just multiplying the difference, just to be sure, but adding, letâ€™s say 4 days will help the logic to cover this edge cases.

Or we can complicate the second expression by adding more logic to it, again regarding the exclusion of the non working days.

I did some unit testing and it seems fine, but you can try more scenarios with both fixes and let me know if we need more updates.

Dates Difference Updated_2022_02_03.slp (8.1 KB)

2 Likes

This is excellent and seems to do exactly what I needed. Thank you very much!