Created
November 28, 2023 01:19
-
-
Save AndyDaSilva52/ee63dddaa8ec1249d4143093a42a71e5 to your computer and use it in GitHub Desktop.
DataWeave - Range of Dates (Array) filtering Holidays, Saturday and Sunday.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%dw 2.0 | |
output application/json | |
fun isWeekend(d: String | Date) = do { | |
["1","7"] contains ((d as Date) as String { format: "c"}) | |
} | |
fun isWeekday(d: String | Date) = do { | |
not (["1","7"] contains ((d as Date) as String { format: "c"})) | |
} | |
var startDate = |2023-11-01| | |
var endDate = |2023-11-30| | |
// Array of String converted to Date | |
var holidays = ["2023-11-02", "2023-11-15"] map $ as Date | |
// Array of Date from startDate until endDate | |
var dateRange = (0 to daysBetween(startDate, endDate)) as Array map( startDate + ("P$($$)D" as Period) ) | |
--- | |
dateRange filter ( | |
// Get position of Date inside holidays Array, it will return -1 when do not exist | |
(holidays indexOf $ ) == -1 | |
and | |
// | |
( isWeekday($) ) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment