This project is archived and is in readonly mode.

#1166 ✓invalid
neilime

Date.parse() => use a specific parser

Reported by neilime | February 3rd, 2011 @ 04:37 PM

For a specific reason, i have to user Date.parse with a specific parser :

Date.parse('10/12/2010');
With this parser : '%d/%m/%Y( %H:%M)?';

So i have to do this code :

Date.defineParser('%d/%m/%Y( %H:%M)?');
var oPattern = Date.parsePatterns[Date.parsePatterns.length-1];
bits = oPattern.re.exec('10/12/2010');
var oDateDebut = (bits) ? (oPattern.handler(bits)) : false;

It would be easier to do it like this : Date.parse('10/12/2010','%d/%m/%Y( %H:%M)?');

Comments and changes to this ticket

  • KalNex

    KalNex February 11th, 2011 @ 04:18 PM

    Hi,

    I have a similar problem, I don't know if I must create a new ticket or not...

    I want to use a specific parser too, I define it in Date class using Date.defineParser(...) method but I noticed that my parser was put on parsePatterns variable at the end of the list. When I want to parse a date (date.parse(...)) the method take another parser because it test it before mine.

    I found a solution in modify the Date.defineParser(...) method :
    defineParser: function(pattern){

    parsePatterns.unshift((pattern.re && pattern.handler) ? pattern : build(pattern));
    

    },

    I replace the push in parsePatterns by a unshift (it put to the first place the new parser).

    But I don't want to modify MooTools More source, this modification can be taken in account for a next release ?

    MooTools More 1.3.0.1

  • Arian

    Arian February 15th, 2011 @ 10:19 PM

    • Assigned user set to “Arian”

    Maybe we can add a second argument where you can define a pattern. I think using .unshift instead of (probably .push isn't really flexible either and doesn't really solve the problem.

    Anyway: this is a MooTools More ticket, so if you want to create a new ticket in the MooTools More bug tracker: https://mootools.lighthouseapp.com/projects/24057-mootoolsmore/over...

  • KalNex
  • Arian

    Arian February 16th, 2011 @ 03:48 PM

    • State changed from “new” to “invalid”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages