Reputation: 197
I am working on a problem where date must be converted to the desired format. And if the format is yyyy/MMM/dd then the month should be converted to the language which is fetched from db. eg. For 2021-01-12 the desired format is yyyy/MMM/dd and desired language is Spanish.
I have tried:
'2021-01-12' as :date{format :'yyyy-MM-dd', locale :'es'} as :string{format : 'yyyy/MMM/dd'}
As well as :
`2021-01-12' as :date{format :`yyyy-MM-dd`} as :string{format : `yyyy/MMM/dd' ,locale :'es'}
The output must be 2021/ene/12 but everytime I am getting is 2021/Jan/12.
Upvotes: 0
Views: 55
Reputation: 25812
It seems like a bug. It works with the full month name format MMMM
. I suggest create a function in DataWeave to do the translations manually, or alternatively try to implement it in a flow with MEL functions, Groovy scripts or Java and call the flow from DataWeave with lookup().
Example of using MMMM:
"2021-01-12"
as :date{format : "yyyy-MM-dd"}
as :string {format: "dd, MMMM, yyyy", locale: "ES"}
Output:
"12, enero, 2021"
DataWeave 2/Mule 4 seems to handle the same case better:
"2021-01-12"
as Date {format: "yyyy-MM-dd"}
as String {format: "yyyy/MMM/dd", locale: "ES"}
Output:
"2021/ene./12"
Upvotes: 0