Skip to content

Commit

Permalink
Merge pull request Pikaday#2 from duckysherwood/master
Browse files Browse the repository at this point in the history
Made to have (optional) input format(s) as well as an output format.
  • Loading branch information
owenmead committed Oct 30, 2014
2 parents 27fb639 + bab826c commit fd985c6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pikaday.js
Expand Up @@ -189,6 +189,11 @@
// set in `config` based on if showTime is set
format: null,

// an array giving the allowable input format(s). As with moment,
// the input formats may be either a single string or an array of strings.
// Usually set in `config`
inputFormats: null,

// the initial date to view when first opened
defaultDate: null,

Expand Down Expand Up @@ -516,7 +521,7 @@
return;
}
if (hasMoment) {
date = moment(opts.field.value, opts.format);
date = moment(opts.field.value, opts.inputFormats);
date = (date && date.isValid()) ? date.toDate() : null;
}
else {
Expand Down Expand Up @@ -591,7 +596,7 @@

if (!opts.defaultDate) {
if (hasMoment && opts.field.value) {
opts.defaultDate = moment(opts.field.value, opts.format).toDate();
opts.defaultDate = moment(opts.field.value, opts.inputFormats).toDate();
} else {
opts.defaultDate = new Date(Date.parse(opts.field.value));
}
Expand Down Expand Up @@ -690,6 +695,10 @@
}
}

if(!opts.inputFormats) {
opts.inputFormats = opts.format;
}

return opts;
},

Expand Down

0 comments on commit fd985c6

Please sign in to comment.