Date Conversion from Arabic to English in IBM WCM

When you display the dates, it get displayed according to the locales. For example, 8/7/2005 06:15:33 will be ٨/٧/٢٠٠٥   ٠٦:١٥:٣٣ for Arabic locale.  This is usually not a problem except when you use the date in a script like an event calendar that only understands English numbers. In this case, it becomes an issue since you want the date to be in English. I ran into this problem several times, so I expect that you could face it too. To counteract this problem in IBM WCM 7.0, 8.0 and 8.5, you can use the below code

[Plugin:Matches pattern=”en(.*)” text=”[Plugin:Locale]”][Element context=”autofill” type=”content” key=”End” format=”MM/dd/yyyy hh:mm:ss”][/Plugin:Matches][Plugin:Matches pattern=”ar(.*)” text=”[Plugin:Locale]”][Plugin:Matches pattern=”(.)(.)/(.)(.)/(.)(.)(.)(.) (.)(.):(.)(.):(.)(.)” text=”[Element context=’autofill’ type=’content’ key=’End’ format=’MM/dd/yyyy hh:mm:ss’]”][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’1′]”]0[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’1′]”]1[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’1′]”]2[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’1′]”]3[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’1′]”]4[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’1′]”]5[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’1′]”]6[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’1′]”]7[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’1′]”]8[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’1′]”]9[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’2′]”]0/[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’2′]”]1/[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’2′]”]2/[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’2′]”]3/[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’2′]”]4/[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’2′]”]5/[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’2′]”]6/[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’2′]”]7/[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’2′]”]8/[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’2′]”]9/[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’3′]”]0[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’3′]”]1[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’3′]”]2[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’3′]”]3[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’3′]”]4[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’3′]”]5[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’3′]”]6[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’3′]”]7[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’3′]”]8[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’3′]”]9[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’4′]”]0/[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’4′]”]1/[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’4′]”]2/[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’4′]”]3/[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’4′]”]4/[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’4′]”]5/[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’4′]”]6/[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’4′]”]7/[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’4′]”]8/[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’4′]”]9/[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’5′]”]0[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’5′]”]1[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’5′]”]2[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’5′]”]3[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’5′]”]4[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’5′]”]5[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’5′]”]6[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’5′]”]7[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’5′]”]8[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’5′]”]9[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’6′]”]0[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’6′]”]1[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’6′]”]2[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’6′]”]3[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’6′]”]4[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’6′]”]5[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’6′]”]6[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’6′]”]7[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’6′]”]8[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’6′]”]9[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’7′]”]0[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’7′]”]1[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’7′]”]2[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’7′]”]3[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’7′]”]4[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’7′]”]5[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’7′]”]6[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’7′]”]7[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’7′]”]8[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’7′]”]9[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’8′]”]0 [/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’8′]”]1 [/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’8′]”]2 [/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’8′]”]3 [/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’8′]”]4 [/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’8′]”]5 [/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’8′]”]6 [/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’8′]”]7 [/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’8′]”]8 [/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’8′]”]9 [/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’9′]”]0[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’9′]”]1[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’9′]”]2[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’9′]”]3[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’9′]”]4[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’9′]”]5[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’9′]”]6[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’9′]”]7[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’9′]”]8[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’9′]”]9[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’10’]”]0:[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’10’]”]1:[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’10’]”]2:[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’10’]”]3:[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’10’]”]4:[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’10’]”]5:[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’10’]”]6:[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’10’]”]7:[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’10’]”]8:[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’10’]”]9:[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’11’]”]0[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’11’]”]1[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’11’]”]2[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’11’]”]3[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’11’]”]4[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’11’]”]5[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’11’]”]6[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’11’]”]7[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’11’]”]8[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’11’]”]9[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’12’]”]0:[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’12’]”]1:[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’12’]”]2:[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’12’]”]3:[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’12’]”]4:[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’12’]”]5:[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’12’]”]6:[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’12’]”]7:[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’12’]”]8:[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’12’]”]9:[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’13’]”]0[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’13’]”]1[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’13’]”]2[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’13’]”]3[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’13’]”]4[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’13’]”]5[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’13’]”]6[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’13’]”]7[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’13’]”]8[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’13’]”]9[/Plugin:Equals][Plugin:Equals text2=”٠” text1=”[Plugin:MatchedGroup group=’14’]”]0[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’14’]”]1[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’14’]”]2[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’14’]”]3[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’14’]”]4[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’14’]”]5[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’14’]”]6[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’14’]”]7[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’14’]”]8[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’14’]”]9[/Plugin:Equals][/Plugin:Matches]

This code looks complicated, but it is quite easy to understand. Once you follow the logic, it becomes very simple. You take as the input, the date field and you match it against the pattern which is the same pattern as the date field. (.) in a regular expression means a single character. Then, each character you check the number in Arabic and you put it’s equivalent in English.

As this code is painful to look at and painful to rewrite, put it in an HTML component and reuse it when you want.

One thing to note that for certain matched groups, you are going to have to add slashes or spaces or you will get only numbers. Something like: 872005061533 which is not what you want.  This is why if you notice, for example for matchedGroup 2 there is a slash after the number.

[Plugin:MatchedGroup group=’2′]”]0/[/Plugin:Equals][Plugin:Equals text2=”١” text1=”[Plugin:MatchedGroup group=’2′]”]1/[/Plugin:Equals][Plugin:Equals text2=”٢” text1=”[Plugin:MatchedGroup group=’2′]”]2/[/Plugin:Equals][Plugin:Equals text2=”٣” text1=”[Plugin:MatchedGroup group=’2′]”]3/[/Plugin:Equals][Plugin:Equals text2=”٤” text1=”[Plugin:MatchedGroup group=’2′]”]4/[/Plugin:Equals][Plugin:Equals text2=”٥” text1=”[Plugin:MatchedGroup group=’2′]”]5/[/Plugin:Equals][Plugin:Equals text2=”٦” text1=”[Plugin:MatchedGroup group=’2′]”]6/[/Plugin:Equals][Plugin:Equals text2=”٧” text1=”[Plugin:MatchedGroup group=’2′]”]7/[/Plugin:Equals][Plugin:Equals text2=”٨” text1=”[Plugin:MatchedGroup group=’2′]”]8/[/Plugin:Equals][Plugin:Equals text2=”٩” text1=”[Plugin:MatchedGroup group=’2′]”]9/[/Plugin:Equals]

This will not work for all formats. It would work only for this format: MM/dd/yyyy hh:mm:ss.

Make sure that your code is in a single line. Multiple lines will cause you a problem in your output as dates are expected to be a single line.

Leave a Reply

Your email address will not be published. Required fields are marked *


*