Ext.Date.parse

  1. #1

    Ext.Date.parse

    it's possible to identify the cultures that use AM and PM designators by running the following code
    foreach (System.Globalization.CultureInfo ci in ResourceManager.SupportedCultures)
    {
        if (ci.DateTimeFormat.LongTimePattern.Contains("tt"))
        {
            var format = string.Format("{0} {1}", ci.DateTimeFormat.ShortDatePattern, ci.DateTimeFormat.LongTimePattern);
    
            var phpFormat = Ext.Net.Utilities.DateTimeUtils.ConvertNetToPHP(format);
    
            System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1} - {2} - {3} - (AM='{4}' PM ='{5}')", ci.EnglishName, ci.ToString(), format, phpFormat, ci.DateTimeFormat.AMDesignator, ci.DateTimeFormat.PMDesignator));
        }
    }
    Outputs:
    Afrikaans - af - yyyy/MM/dd hh:mm:ss tt - Y/m/d h:i:s a - (AM='VM.' PM ='NM.')
    Greek (Greece) - el-GR - d/M/yyyy h:mm:ss tt - j/n/Y g:i:s a - (AM='πμ' PM ='μμ')
    English - en - M/d/yyyy h:mm:ss tt - n/j/Y g:i:s a - (AM='AM' PM ='PM')
    English (Australia) - en-AU - d/MM/yyyy h:mm:ss tt - j/m/Y g:i:s a - (AM='AM' PM ='PM')
    Persian - fa - dd/MM/yyyy hh:mm:ss tt - d/m/Y h:i:s a - (AM='ق.ظ' PM ='ب.ظ')
    Korean - ko - yyyy-MM-dd tt h:mm:ss - Y-m-d a g:i:s - (AM='오ì*„' PM ='오후')
    Vietnamese - vi - dd/MM/yyyy h:mm:ss tt - d/m/Y g:i:s a - (AM='SA' PM ='CH')
    Chinese (Traditional, Taiwan) - zh-TW - yyyy/M/d tt hh:mm:ss - Y/n/j a h:i:s - (AM='上午' PM ='下午')
    Note: On ext-locale-zh-TW the attributes Ext.Date.formatCodes.a, Ext.Date.formatCodes.A, Ext.Date.parseCodes.a and Ext.Date.parseCodes.A are defined but on ext-locale-af, ext-locale-el-GR, ext-locale-fa, ext-locale-ko and ext-locale-vi those attributes are not defined.

    Parsing a date using Ext.Date.parse works on English, English (Australia) and Chinese (Traditional, Taiwan)

    English - en - M/d/yyyy h:mm:ss tt - n/j/Y g:i:s a - (AM='AM' PM ='PM')
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="en" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('12/28/2015 10:20:30 PM', 'n/j/Y g:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    English (Australia) - en-AU - d/MM/yyyy h:mm:ss tt - j/m/Y g:i:s a - (AM='AM' PM ='PM')
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="en-AU" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('28/12/2015 10:20:30 PM', 'j/m/Y g:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Chinese (Traditional, Taiwan) - zh-TW - yyyy/M/d tt hh:mm:ss - Y/n/j a h:i:s - (AM='上午' PM ='下午')
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="zh-TW" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler=" Ext.Msg.alert('Date', Ext.Date.parse('2015/12/28 下午 10:20:30', 'Y/m/d a h:i:s'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    But it doesn't work on Afrikaans, Greek (Greece), Persian, Korean and Vietnamese

    Afrikaans - af - yyyy/MM/dd hh:mm:ss tt - Y/m/d h:i:s a - (AM='VM.' PM ='NM.')
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="af" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('2015/12/28 10:20:30 NM.', 'Y/m/d h:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Greek (Greece) - el-GR - d/M/yyyy h:mm:ss tt - j/n/Y g:i:s a - (AM='πμ' PM ='μμ')
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="el-GR" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('28/12/2015 10:20:30 μμ', 'j/n/Y g:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Persian - fa - dd/MM/yyyy hh:mm:ss tt - d/m/Y h:i:s a - (AM='ق.ظ' PM ='ب.ظ')
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="fa" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('28/12/2015 10:20:30 ب.ظ', 'd/m/Y h:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Korean - ko - yyyy-MM-dd tt h:mm:ss - Y-m-d a g:i:s - (AM='오ì*„' PM ='오후')
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="ko" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('2015-12-28 오후 10:20:30', 'Y-m-d a g:i:s'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Vietnamese - vi - dd/MM/yyyy h:mm:ss tt - d/m/Y g:i:s a - (AM='SA' PM ='CH')
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="vi" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('28/12/2015 10:20:30 CH', 'd/m/Y g:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Thanks in advance
    Last edited by RaphaelSaldanha; Dec 29, 2015 at 1:05 AM.
  2. #2
    Note: On ext-locale-zh-TW the attributes Ext.Date.formatCodes.a, Ext.Date.formatCodes.A, Ext.Date.parseCodes.a and Ext.Date.parseCodes.A are defined but on ext-locale-af, ext-locale-el-GR, ext-locale-fa, ext-locale-ko and ext-locale-vi those attributes are not defined.
    Yes, it is related to the fact that those attributes are not defined.

    It's possible to fix the issue presented above by applying the following fixes.

    Afrikaans - apply to ext-locale-af.js and ext-locale-af-debug.js.
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <script type="text/javascript">
            Ext.onReady(function () {
                if (Ext.Date) {
    
                    Ext.Date.formatCodes.a = "(this.getHours() < 12 ? 'VM.' : 'NM.')";
                    Ext.Date.formatCodes.A = "(this.getHours() < 12 ? 'VM.' : 'NM.')";
    
                    var parseCodes = {
                        g: 1,
                        c: "if (/(VM.)/i.test(results[{0}])) {\n"
                            + "if (!h || h == 12) { h = 0; }\n"
                            + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
                        s: "(VM.|NM.)",
                        calcAtEnd: true
                    };
    
                    Ext.Date.parseCodes.a = Ext.Date.parseCodes.A = parseCodes;
                }
            });
        </script>
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="af" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('2015/12/28 10:20:30 NM.', 'Y/m/d h:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Greek (Greece) - apply to ext-locale-el-GR.js and ext-locale-el-GR-debug.js.
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <script type="text/javascript">
            Ext.onReady(function () {
                if (Ext.Date) {
    
                    Ext.Date.formatCodes.a = "(this.getHours() < 12 ? 'πμ' : 'μμ')";
                    Ext.Date.formatCodes.A = "(this.getHours() < 12 ? 'πμ' : 'μμ')";
    
                    var parseCodes = {
                        g: 1,
                        c: "if (/(πμ)/i.test(results[{0}])) {\n"
                            + "if (!h || h == 12) { h = 0; }\n"
                            + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
                        s: "(πμ|μμ)",
                        calcAtEnd: true
                    };
    
                    Ext.Date.parseCodes.a = Ext.Date.parseCodes.A = parseCodes;
                }
            });
        </script>
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="el-GR" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('28/12/2015 10:20:30 μμ', 'j/n/Y g:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Persian - apply to ext-locale-fa.js and ext-locale-fa-debug.js.
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <script type="text/javascript">
            Ext.onReady(function () {
                if (Ext.Date) {
    
                    Ext.Date.formatCodes.a = "(this.getHours() < 12 ? 'ب.ظ' : 'ق.ظ')";
                    Ext.Date.formatCodes.A = "(this.getHours() < 12 ? 'ب.ظ' : 'ق.ظ')";
    
                    var parseCodes = {
                        g: 1,
                        c: "if (/(ق.ظ)/i.test(results[{0}])) {\n"
                            + "if (!h || h == 12) { h = 0; }\n"
                            + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
                        s: "(ب.ظ|ق.ظ)",
                        calcAtEnd: true
                    };
    
                    Ext.Date.parseCodes.a = Ext.Date.parseCodes.A = parseCodes;
                }
            });
        </script>
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="fa" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('28/12/2015 10:20:30 ب.ظ', 'd/m/Y h:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Korean - apply to ext-locale-ko.js and ext-locale-ko-debug.js.
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <script type="text/javascript">
            Ext.onReady(function () {
                if (Ext.Date) {
    
                    Ext.Date.formatCodes.a = "(this.getHours() < 12 ? '오ì*„' : '오후')";
                    Ext.Date.formatCodes.A = "(this.getHours() < 12 ? '오ì*„' : '오후')";
    
                    var parseCodes = {
                        g: 1,
                        c: "if (/(오ì*„)/i.test(results[{0}])) {\n"
                            + "if (!h || h == 12) { h = 0; }\n"
                            + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
                        s: "(오ì*„|오후)",
                        calcAtEnd: true
                    };
    
                    Ext.Date.parseCodes.a = Ext.Date.parseCodes.A = parseCodes;
                }
            });
        </script>
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="ko" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('2015-12-28 오후 10:20:30', 'Y-m-d a g:i:s'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Vietnamese - apply to ext-locale-vi.js and ext-locale-vi-debug.js.
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <script type="text/javascript">
            Ext.onReady(function () {
                if (Ext.Date) {
    
                    Ext.Date.formatCodes.a = "(this.getHours() < 12 ? 'SA' : 'CH')";
                    Ext.Date.formatCodes.A = "(this.getHours() < 12 ? 'SA' : 'CH')";
    
                    var parseCodes = {
                        g: 1,
                        c: "if (/(SA)/i.test(results[{0}])) {\n"
                            + "if (!h || h == 12) { h = 0; }\n"
                            + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
                        s: "(SA|CH)",
                        calcAtEnd: true
                    };
    
                    Ext.Date.parseCodes.a = Ext.Date.parseCodes.A = parseCodes;
                }
            });
        </script>
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" Locale="vi" Theme="Crisp" runat="server">
            <Listeners>
                <DocumentReady Handler="Ext.Msg.alert('Date', Ext.Date.parse('28/12/2015 10:20:30 CH', 'd/m/Y g:i:s a'))" />
            </Listeners>
        </ext:ResourceManager>
    </body>
    </html>
    Last edited by RaphaelSaldanha; Dec 29, 2015 at 11:32 AM.
  3. #3
  4. #4
    Thank you very much for sharing this! Actually I've stumbled in an issue that is pretty much the exact one on this thread: DateField with Format 'MMMM yyyy' cannot set value to or get value from its MonthPicker.

    I can say to some extent of certainity that your suggestion addresses this exact issue!

    We have this logged on GitHub as well since then: #712
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Thank you very much for sharing this!
    You're welcome.

    is it gonna be fixed internally?
  6. #6
    is it gonna be fixed internally?
    Can't say that for sure now. A lot is going on with ExtJS 5.1.2 to Ext.NET 3.2.x and ExtJS 6.0.1 to Ext.NET 4.0 beta, so we will be fixing a LOT of things in the next days and can't really say we will have the opportunity to add this to the package or wait a while to see if Sencha is going to fix it by their side...

    Actually, that would be reasonable to give them some time to reply the thread you opened on their forums. There's a chance they may apply the fix quickly, as you not only pointed the bug, but presented its solution!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 8
    Last Post: May 20, 2013, 4:01 AM
  2. Replies: 2
    Last Post: Feb 07, 2013, 1:59 PM
  3. Replies: 2
    Last Post: Apr 23, 2012, 12:47 PM
  4. Replies: 1
    Last Post: Apr 13, 2012, 1:52 PM
  5. DateField parse February problem
    By pjdu in forum Bugs
    Replies: 1
    Last Post: Sep 30, 2009, 1:33 AM

Posting Permissions