vincentlowe icon

Normalize Dates - three formats to Date

vincentlowe | PRO | 07/20/21 02:53:14 PM UTC | 0 ⭐ | 185 👁️ | Never ⏰ | []
text |

560 B

|

None

|

0 👍

/

0 👎

%dw 2.0
output application/dw
var cle = readUrl("classpath://examples/flightsAllAirlinesCLE.json", "application/json")
 fun shortform(list: Array) = list map {
	id: $.flightCode,
	when: $.departureDate,
	where: $.destination
}
 fun normalizeDate (d: String) = d match {
	case amer if (d matches /[A-Z][a-z]{2}.*/) -> 
		d as Date {format: "MMM dd, yyyy"}
	case science if (d matches /\d{4}\/\w{2}\/\w{2}/) -> 
		d as Date {format: "yyyy/MM/dd"}
	else -> d as Date
}
 ---
shortform(cle.flights) map (f) -> (f - "when") ++ 
	{when: normalizeDate(f.when)}
  

Comments