Is there any way to define a specific parser when Date.parse is used ?

My solution if another not exists (But not effective as well because
of build function only exists in mootools.more file) :

Date.extend({
     parse: function(from,parser){
        var t = $type(from);
        if (t == 'number') return new Date(from);
        if (t != 'string') return from;
        from = from.clean();
        if (!from.length) return null;

        var parsed;
        if(parser == null){
            parsePatterns.some(function(pattern){
                var bits = pattern.re.exec(from);
                return (bits) ? (parsed = pattern.handler(bits)) :
false;
            });
        }
        else{
            partern = build(parser);
            var bits = pattern.re.exec(from);
            parsed  = (bits) ? (pattern.handler(bits)) : false;
        }

        return parsed || new Date(nativeParse(from));
    }
});

console.log(Date.parse('10/12/2010','%d/%m/%Y( %H:%M)?')

Reply via email to