vincentlowe

Normalize Dates - three formats to Date

Jul 20th, 2021
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. %dw 2.0
  2. output application/dw
  3. var cle = readUrl("classpath://examples/flightsAllAirlinesCLE.json", "application/json")
  4.  
  5. fun shortform(list: Array) = list map {
  6. id: $.flightCode,
  7. when: $.departureDate,
  8. where: $.destination
  9. }
  10.  
  11. fun normalizeDate (d: String) = d match {
  12. case amer if (d matches /[A-Z][a-z]{2}.*/) ->
  13. d as Date {format: "MMM dd, yyyy"}
  14. case science if (d matches /\d{4}\/\w{2}\/\w{2}/) ->
  15. d as Date {format: "yyyy/MM/dd"}
  16. else -> d as Date
  17. }
  18.  
  19. ---
  20. shortform(cle.flights) map (f) -> (f - "when") ++
  21. {when: normalizeDate(f.when)}
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment