Reputation: 23
Hello I am new to FTL Code and I am trying to re format a date based on how a locale would display it.
The error I am getting: (Please look below for more info of the result we want)
The string doesn't match the expected date/time/date-time format. The string to parse was: "août 26, 2035". The expected format was: "MM dd, yyyy". The nested reason given follows: Unparseable date: "août 26, 2035"
<#assign locale = userPreferences.getLanguage()>
my locale ${locale}<br>
<#if locale = "en_AU">
original = ${couponData.expiration}<br>
<#assign expiryDate = couponData.expiration?date("dd MM, yyyy")?string("dd MM yyyy")>
format ${expiryDate} <br>
${sys.declare("dateMonthYear", expiryDate)}
<#elseif locale = "en_GB">
original = ${couponData.expiration}<br>
<#assign expiryDate = couponData.expiration?date("MM dd, yyyy")?string("dd MM yyyy")>
format ${expiryDate} <br>
${sys.declare("dateMonthYear", expiryDate)}
<#elseif locale = "fr_CA">
original = ${couponData.expiration}<br>
<#assign expiryDate = couponData.expiration?date("MMM dd, yyyy")?string("dd MM. yyyy")>
format ${expiryDate} <br>
${sys.declare("dateMonthYear", expiryDate)}
<#else>
${sys.declare("dateMonthYear", "${couponData.expiration}")}
</#if>
CA_FR Source:
Ends Jul 31, 2022
Actual:
Expire le juil. 31, 2022
Expected:
Expire le 31 juil. 2022
EN_GB Source:
Ends Jul 31, 2022.
Actual:
Ends Jul 31, 2022.
Expected:
Ends 31 Jul 2022.
enter code here
EN_AU Source:
Ends Jul 31, 2022. Actual:
Ends 31 Jul, 2022. Expected:
Ends 31 Jul 2022.
Upvotes: 1
Views: 221
Reputation: 23
I was able to solve my issue:
it seems in the string MM-DD-YY will format into something like 01/01/2022
Where as was proving three MMM-DD-YYYY will give me Jan 01, 2022
I can manipulate the dateformat inside the string also
<#setting locale="fr">
<#assign expirationDate = expiration?number_to_date?string("yyyy MMM. dd")>
Upvotes: 1