silfverorg / duns.js

Javascript schema validator
5 stars 2 forks source link

Added method for formatting date. #20

Closed silfverstrom closed 9 years ago

silfverstrom commented 9 years ago

Date has two formatting alternatives, a callback method defined in returns, or a moment-js valid date-format.

Examples,

//Callback method.
Duns.date().returns(function(val) {
  //return custom reformatting
}).init('2015-01-01').format();

//Will return 2015-01
Duns.date().returns('YYYY-MM').init('2015-01-01').format();

//Note that in this example 20150101 is not a valid moment-format, but defining an explicit pattern allows us to use the shorthand notation either way.
Duns.date().pattern('YYYYMMDD').returns('YYYY-MM').init('20150101').format();
silfverstrom commented 9 years ago

This closes #19