(function ($) {
$.fn.datepickerParser = function (options) {
/// <summary>
/// Parses text within the jquery datepicker that's not quite a date;
/// to handle date changes, use the "onSelect" event that's built into the
/// datepicker API, or the "dateChange" event that I've added here.
/// </summary>
/// <param name="options">parser: a function that takes text input
/// and returns null or a date;
/// if no year is passed, defaults to the next occurrence of the
/// m/d part. ex. on 2/10/1990, '1/1' will return '1/1/1991'; '3/1' will return '3/1/1990'
/// </param>
/// <events>
/// jQueryUI onSelect (dateText, element)
/// jQuery dateChange (dateVal (or null), element)
/// </events>
this.each(function () {
var self = this;
// default parser:
var settings = {
parser: function (text) {
// try M/D/Y and/or Y-M-D
var retVal;
var parts = text.replace("-", "/").split('/');
var now = new Date();
var m, d, y;
if (parts.length === 3 && parseInt(parts[0] || 0) > 31) {
// must be y/m/d
var newParts = [parts[2], parts[0], parts[1]];
parts = newParts;
}
if (parts.length === 1) {
// day only: assume this month/year
parts.unshift(now.getMonth() + 1);
parts.push(now.getFullYear());
}
if (parts.length === 2 || parts.length === 3) {
m = parseInt(parts[0] ? parts[0] - 1 : 0);
d = parseInt(parts[1]); // day
}
if (parts.length === 3) {
y =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.