Remove Moment.js dependency
Author: wojciechczerniakCreated Oct 30, 2018Updated Nov 28, 2023
Labelsbreaking change
Checklist
- Remove
momentfrom UMD: https://github.com/Pikaday/Pikaday/blob/master/pikaday.js#L29 - Remove
hasMomentflag and everyting that is releated to it: https://github.com/Pikaday/Pikaday/blob/master/pikaday.js#L36 - Remove
formatStrictoption: https://github.com/Pikaday/Pikaday/blob/master/pikaday.js#L215 - Remove
getMomentmethod: https://github.com/Pikaday/Pikaday/blob/master/pikaday.js#L761 - Remove
setMomentmethod: https://github.com/Pikaday/Pikaday/blob/master/pikaday.js#L787 - Remove moment from
toStringmethod: https://github.com/Pikaday/Pikaday/blob/master/pikaday.js#L752 - Remove moment from
parsemethod: https://github.com/Pikaday/Pikaday/blob/master/pikaday.js#L553 - Remove moment from
_parseFieldValuemethod: https://github.com/Pikaday/Pikaday/blob/master/pikaday.js#L547 - Remove
momentfrom the Readme - Refactor
momentexample withparseandtoStringfunctions: https://github.com/Pikaday/Pikaday/blob/master/examples/moment.html
How to update from 1.x to 2.x
getMoment
Use getDate.
let momentDate = moment(pikadayInstance.getDate());setMoment
Use setDate.
pikadayInstance.setDate(momentDate.toDate(), preventOnSelect);toString
Define custom toString function in Pikaday options.
let pikaday = new Pikaday({
...
toString(date, format) {
return moment(date).format(format);
},
});parse
Define custom parse function in Pikaday options.
let pikaday = new Pikaday({
...
parse(dateString, format) {
let date = moment(dateString, format, formatStrict);
return (date && date.isValid()) ? date.toDate() : null;
},
});formatStrict
See parse section above.
Advanced Moment integration example
You can use moment js to localize Pikaday!
moment.locale('nl');
var pikadayLocale = {
previousMonth: 'Previous Month',
nextMonth: 'Next Month',
months: moment.months(),
weekdays: moment.weekdays(),
weekdaysShort: moment.weekdaysShort()
};Source: https://github.com/Pikaday/Pikaday/issues/472#issuecomment-172789904
Source: Pikaday/Pikaday