New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Moment.js dependency #815

Open
wojciechczerniak opened this Issue Oct 30, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@wojciechczerniak
Copy link
Collaborator

wojciechczerniak commented Oct 30, 2018

Checklist

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: #472 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment