Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#14977 closed bug (worksforme)

Parse error, unexpected literal. parseDate fails to consider the format DD, for long name of day of week

Reported by: JeffMatthews2 Owned by:
Priority: minor Milestone: none
Component: ui.datepicker Version: 1.11.4
Keywords: Cc:
Blocked by: Blocking:

Description

JQ-UI Version: jquery-ui-1.11.4.js

Browser: Chrome 51

OS - Win 10


Occurs when you include a literal in the date format as follows:

dateFormat: "DD, MM d, yy'-'",

DD long day name (e.g., "Saturday") is not in the case/switch as a possible format.

parseDate: function (format, value, settings) {
		if (format == null || value == null) {
			throw "Invalid arguments";
		}

		value = (type...

for (iFormat = 0; iFormat < format.length; iFormat++) {
			if (literal) {
				if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
					literal = false;
				} else {
					checkLiteral();
				}
			} else {
				switch (format.charAt(iFormat)) {
					case "d":
						day = getNumber("d");
						break;
					case "D":
						getName("D", dayNamesShort, dayNames);
						break;
					case "o":
						doy = getNumber("o");
						break;
					case "m":
						month = getNumber("m");
						break;
					case "M":
						month = getName("M", monthNamesShort, monthNames);
						break;
					case "y":
						year = getNumber("y");
						break;
					case "@":
						date = new Date(getNumber("@"));
						year = date.getFullYear();
						month = date.getMonth() + 1;
						day = date.getDate();
						break;
					case "!":
						date = new Date((getNumber("!") - this._ticksTo1970) / 10000);
						year = date.getFullYear();
						month = date.getMonth() + 1;
						day = date.getDate();
						break;
					case "'":
						if (lookAhead("'")){
							checkLiteral();
						} else {
							literal = true;
						}
						break;
					default:
						checkLiteral();
				}
			}

Change History (3)

comment:1 Changed 3 years ago by Scott González

Component: ui.coreui.datepicker
Resolution: worksforme
Status: newclosed
Version: 1.11.31.11.4

comment:2 Changed 3 years ago by JeffMatthews2

I'm sorry. You are correct. I spent a lot of time figuring out a simple oversight on my part.

I had the input value formatted in a way which caused the parsing error.

Notice the dash (-):

itemTemplate: function (value) {
            // This is display mask for the date to be used in rows.            
            return new moment(value).format("dddd, MMMM D, YYYY  -  h:mm a");    

The parsing error triggered when clicking on the input element to invoke the datePicker selector dropdown. I finally figured out it was reading the input's value and that " - " will not work from within an input. It was an unescaped literal.

The following change was required. Notice the escape brackets:

return new moment(value).format("dddd, MMMM D, YYYY  [-]  h:mm a");    

After all that investigating, it turns out the input needs to be properly formatted so that the picker can parse it.

comment:3 Changed 3 years ago by JeffMatthews2

By the way, thanks for setting up that jsbin for me. I played with it until I got it right. You were very helpful.

Note: See TracTickets for help on using tickets.