views:

60

answers:

0

I've got some code to work with dates in javascript. This works in IE, FF, Safari (desktop versions win & mac), Chrome, Opera. In iPhone safari (mobile safari), i get a 'invalid date' response.

The code for managing dates is

    function fixDateFormat(dateText){
    var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/,
        newDate = new Date(NaN), month,
        parts = isoExp.exec(dateText);

    if(parts) {
      month = +parts[2];
      newDate.setFullYear(parts[1], month - 1, parts[3]);
      if(month != newDate.getMonth() + 1) {
        newDate.setTime(NaN);
      } else {
        newDate.setHours(0, 0, 0, 0);
      }
    }
    return newDate;
    }

Where the dateFormat is sent into this function as Y-m-d (though it was my understanding that this function would deal with a multitude of formats).