Results 1 to 2 of 2

Thread: Date not being passed to functions in Ext.Date.formatFunctions

    Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-2968 in a recent build.
  1. #1
    Ext JS Premium Member
    Join Date
    Nov 2009
    Vote Rating

    Default Date not being passed to functions in Ext.Date.formatFunctions

    I'm trying to add some custom date formatters to be used inside of XTemplates, and according to the API documentation for Ext.Date.formatFunctions, custom formatting functions added to this object will be passed the date to be formatted as an argument.

    This doesn't actually appear to be the case, since the underlying code that calls the format function looks like:

     * Formats a date given the supplied format string.
     * @param {Date} date The date to format
     * @param {String} format The format string
     * @return {String} The formatted date
    format: function(date, format) {
        if (utilDate.formatFunctions[format] == null) {
        var result = utilDate.formatFunctions[format].call(date);
        return result + '';
    So the custom formatter is actually being called in the scope of the date instead of it being passed as a parameter. Are the API docs just wrong or something?

    Here's a little example:

    Ext.Date.formatFunctions['customFormat'] = function() { console.log(arguments); console.log(this); return 'test'; }
    (new Ext.XTemplate('date: {start:date("customFormat")}')).apply({ start: new Date() });
    You'll see the arguments of the function are empty, but the scope is of the Date object to be formatted.

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    Simple documentation update. The date can be resolved by the scope.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:

Posting Permissions

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