-
-
Save atskimura/6f33086e745b1d222efe294deafa1770 to your computer and use it in GitHub Desktop.
This file contains 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 | |
input records application/java | |
output application/json | |
--- | |
{ | |
users: records map (record) -> | |
record | |
filterObject (not $$ ~= "Id") | |
update { | |
case createdDate at .CreatedDate -> ((createdDate >> "UTC") as String { format: "hh:mm:ss a, MMMM dd, uuuu" }) | |
} | |
} |
This file contains 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
List<Contact> data = [SELECT FirstName, LastName, CreatedDate FROM Contact ORDER BY LastName ASC LIMIT 5]; | |
Assert.isFalse(data.isEmpty(), 'Contacts required for input data'); | |
DataWeave.Script script = new DataWeaveScriptResource.jsonDateFormat(); | |
DataWeave.Result result = script.execute(new Map<String, Object>{ 'records' => data }); | |
// Note that DW uses Java 8 java.time.format, so uuuu is the year. vs. yyyy for Apex. | |
String expected = '{\n'+ | |
' "users": [\n'+ | |
' {\n'+ | |
' "FirstName": "John",\n'+ | |
' "LastName": "Doe",\n'+ | |
' "CreatedDate": "' + data[0].CreatedDate.formatGMT('hh:mm:ss a, MMMM dd, yyyy') + '"\n'+ | |
' }\n'+ | |
' ]\n'+ | |
'}'; | |
Assert.areEqual(expected, result.getValueAsString(), 'Expected custom DateTime format in UTC'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment