Results 1 to 6 of 6

Thread: [FIXED-1475] DateField.safeParse and 'c' or 'U' format

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default [FIXED-1475] DateField.safeParse and 'c' or 'U' format

    DateField.safeParse determines if it should parse the time based on the format string containing 'g', 'G', 'h' or 'H', but it should also check for 'c' and 'U', because these formats contain time too.
    And to be complete, we should probably also add 'i', 's' and 'u'.

    Code:
    Ext.override(Ext.form.DateField, }
        safeParse : function(value, format) {
            if (/[gGhHisucU]/.test(format.replace(/(\\.)/g, ''))) {
                return Date.parseDate(value, format);
            } else {
                var parsedDate = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat);
                if (parsedDate) {
                    return parsedDate.clearTime();
                }
            }
        }
    });

  2. #2
    Sencha User
    Join Date
    Jun 2009
    Posts
    751

    Default

    Which Ext release or SVN revision were you overriding above?

  3. #3
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    Ah, it was already fixed in rev. 7321 (4 days before my post!).

    I do however don't like the current formatContainsHourInfo code:
    Code:
    Date.formatContainsHourInfo = function(format){
        var hourFormats = ['c', 'U', 'O', 'P', 'Z', 'M$']
        if (hourFormats.indexOf(format) > -1) {
            return true;
        }
        return /[gGhH]/.test(format.replace(/(\\.)/g, ''));
    };
    It doesn't detect 'O', 'P' or 'Z' as part of a dateFormat.

    IMHO it should be:
    Code:
    Date.formatContainsHourInfo = (function(){
        var stripEscapeRe = /(\\.)/g,
            hourInfoRe = /([gGhHisucUOPZ]|M$)/;
        return function(format){
            return hourInfoRe.test(format.replace(stripEscapeRe, ''));
        };
    })();
    (including regexp caching)

  4. #4
    Sencha User
    Join Date
    Jun 2009
    Posts
    751

    Default

    Doesn't M$ require the backslash here as it's part of the regex string?

    Code:
    Date.formatContainsHourInfo = (function(){
        var stripEscapeRe = /(\\.)/g,
            hourInfoRe = /([gGhHisucUOPZ]|M\$)/;
        return function(format){
            return hourInfoRe.test(format.replace(stripEscapeRe, ''));
        };
    })();

  5. #5
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    Quote Originally Posted by meroy View Post
    Doesn't M$ require the backslash here as it's part of the regex string?
    Completely correct. I forgot that $ is the EOL indicator in a RegExp.

  6. #6
    Sencha User
    Join Date
    Jun 2009
    Posts
    751

    Default

    The fix has been applied to SVN (3.3.x branch). Thanks Condor.

Similar Threads

  1. DateField.safeParse & M$ DateFormat
    By rooseveltdossantos in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 18 Sep 2010, 3:10 PM
  2. DateField format
    By g1_ in forum Ext GWT: Discussion
    Replies: 2
    Last Post: 10 May 2010, 6:28 AM
  3. [2.1][FIXED] Datefield format bug? d-M-Y not working
    By seymores in forum Ext 2.x: Bugs
    Replies: 31
    Last Post: 13 Jul 2008, 11:07 PM
  4. dateField format
    By trickytoad in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 11 Mar 2008, 5:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •