This code appears to be using logical operations and manipulation...
This code appears to be using logical operations and manipulation functions to calculate a specific date and then format it in the yyyy-MM-dd
format. It is written in an expression language typically used in platforms like Microsoft Power Automate (Logic Apps).
Breakdown of What the Code Does:
-
outputs('Compose_OOFEndDate')
:- Pulls data from a previously defined step (e.g., named
Compose_OOFEndDate
) in the workflow.
- Pulls data from a previously defined step (e.g., named
-
if(empty(outputs('Compose_OOFEndDate')), utcNow(), outputs('Compose_OOFEndDate'))
:- Checks if the
Compose_OOFEndDate
is empty:- If empty, it uses the current date and time (
utcNow()
). - Otherwise, it uses the value of
Compose_OOFEndDate
.
- If empty, it uses the current date and time (
- Checks if the
-
addDays(...)
:- Adds a specific number of days to the resulting date from above.
-
dayOfWeek(addDays(...))
:- Determines which day of the week the new calculated date is:
0
corresponds to Sunday.6
corresponds to Saturday.
- Determines which day of the week the new calculated date is:
-
if(or(equals(dayOfWeek(...), 6), equals(dayOfWeek(...), 0)), 2, 1)
:- Checks if the new calculated date falls on a Saturday (6) or Sunday (0):
- If it is a weekend, it selects
2
(i.e., add 2 days to skip the weekend). - Otherwise, it selects
1
(i.e., add 1 day).
- If it is a weekend, it selects
- Checks if the new calculated date falls on a Saturday (6) or Sunday (0):
-
Outer
addDays(...)
:- Adds either 1 day (if it's not a weekend) or 2 days (if it is a weekend) to the date.
-
formatDateTime(..., 'yyyy-MM-dd')
:- Formats the final calculated date into the
yyyy-MM-dd
string format.
- Formats the final calculated date into the
Overall Functionality of the Code:
The code calculates a future date based on the provided Compose_OOFEndDate
(or the current date if it's empty). It then checks if this date lands on a weekend (Saturday or Sunday). If it does, the code skips the weekend by adding 2 days instead of 1 day. Finally, the new date is formatted into the yyyy-MM-dd
format for output.