public/javascripts/dateparse.js in merb-admin-0.5.1 vs public/javascripts/dateparse.js in merb-admin-0.5.2
- old
+ new
@@ -34,11 +34,11 @@
/* Takes a string, returns the index of the month matching that string, throws
an error if 0 or more than 1 matches
*/
function parseMonth(month) {
- var matches = monthNames.filter(function(item) {
+ var matches = monthNames.filter(function(item) {
return new RegExp("^" + month, "i").test(item);
});
if (matches.length == 0) {
throw new Error("Invalid month string");
}
@@ -59,26 +59,26 @@
throw new Error("Ambiguous weekday");
}
return weekdayNames.indexOf(matches[0]);
}
-/* Array of objects, each has 're', a regular expression and 'handler', a
- function for creating a date from something that matches the regular
- expression. Handlers may throw errors if string is unparseable.
+/* Array of objects, each has 're', a regular expression and 'handler', a
+ function for creating a date from something that matches the regular
+ expression. Handlers may throw errors if string is unparseable.
*/
var dateParsePatterns = [
// Today
{ re: /^tod/i,
- handler: function() {
+ handler: function() {
return new Date();
- }
+ }
},
// Tomorrow
{ re: /^tom/i,
handler: function() {
- var d = new Date();
- d.setDate(d.getDate() + 1);
+ var d = new Date();
+ d.setDate(d.getDate() + 1);
return d;
}
},
// Yesterday
{ re: /^yes/i,
@@ -87,19 +87,19 @@
d.setDate(d.getDate() - 1);
return d;
}
},
// 4th
- { re: /^(\d{1,2})(st|nd|rd|th)?$/i,
+ { re: /^(\d{1,2})(st|nd|rd|th)?$/i,
handler: function(bits) {
var d = new Date();
d.setDate(parseInt(bits[1], 10));
return d;
}
},
// 4th Jan
- { re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+)$/i,
+ { re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+)$/i,
handler: function(bits) {
var d = new Date();
d.setDate(parseInt(bits[1], 10));
d.setMonth(parseMonth(bits[2]));
return d;
@@ -114,11 +114,11 @@
d.setYear(bits[3]);
return d;
}
},
// Jan 4th
- { re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?$/i,
+ { re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?$/i,
handler: function(bits) {
var d = new Date();
d.setDate(parseInt(bits[2], 10));
d.setMonth(parseMonth(bits[1]));
return d;
@@ -207,10 +207,10 @@
}
function magicDate(input) {
var messagespan = input.id + 'Msg';
try {
var d = parseDateString(input.value);
- input.value = d.getFullYear() + '-' + (fmt00(d.getMonth() + 1)) + '-' +
+ input.value = d.getFullYear() + '-' + (fmt00(d.getMonth() + 1)) + '-' +
fmt00(d.getDate());
input.className = '';
// Human readable date
if (document.getElementById(messagespan)) {
document.getElementById(messagespan).firstChild.nodeValue = d.toDateString();