Update to @date-io v1.0 caused breaking changes to Calendar
The update in this commit: #846
Seems to have caused a breaking change in Calendar due to the name change of the util method from startOfMonth to getStartOfMonth.
Looks like this update requires users to also manually update their @date-io version (since that dependency isn't included in the package).
Just wanted to point this out as something you might want to mention in docs and changelogs!
We had to spend a morning debugging a break to one of our deployed instances, and it would have helped to find some documentation here about it.
It is mentioned in changlog
Ah, I see now. It's listed as a "Feature".
It probably would be nice to mention that it is a breaking change. Most people don't expect minor version updates to cause their production apps to crash
Exactly, a breaking change is a breaking change, should result in major version bump
@mattgbrich Can you please explain how you solved this problem? I have updated both packages and am still crashing the app when I try to open the calendar, also getting the same missing function error.
My material-ui-pickers version is 2.1.1 and @date-io/moment version is 1.0.1
@adnanba Yesterday, I just reverted back to the old versions I was using before.
Just tried updating and it looks like everything is working for me. Have you checked to see if it is being cached somewhere? Are you using any service workers for offline support?
@mattgbrich
So far I've tried removing the packages, reinstalling them, and also clearing npm cache in the process and nothing worked.
Looking at the source code of the @date-io packages, all 3 of them have only the startOfMonth method implemented and not the getStartOfMonth one, so I am kind of confused right now. Am I missing something?
Have you updated to the most recent version of pickers? That used startOfMonth method?
My material-ui-pickers version is 2.1.1 and @date-io/moment version is 1.0.1. Is there anything else I need to update?
It seems I messed up something with my node_modules, I've got it working on a different branch.
You can resolve this problem following these steps:
after importing your dependency utils
import MomentUtils from '@date-io/moment';
Add these lines before bootstrapping your app :
MomentUtils.prototype.getStartOfMonth=MomentUtils.prototype.startOfMonth
import React, {Component} from 'react'
import {withStyles} from '@material-ui/core/styles/index'
import {ChevronLeft, ChevronRight} from '@material-ui/icons'
import DateFnsUtils from '@date-io/date-fns'
import format from 'date-fns/format'
import frLocale from 'date-fns/locale/fr'
import {DatePicker, MuiPickersUtilsProvider} from 'material-ui-pickers'
import moment from 'moment'
class FrDateFnsUtils extends DateFnsUtils {
startOfMonth(date) {
return moment(date).startOf('month').toDate();
}
getDatePickerHeaderText(date) {
return format(date, 'd MMMM', {locale: this.locale})
}
}
[.....]
<MuiPickersUtilsProvider
locale={frLocale}
utils={FrDateFnsUtils}
>
<DatePicker
format="d MMMM yyyy"
leftArrowIcon={<ChevronLeft/>}
onChange={this.onChangeHandler.bind(this, name)}
rightArrowIcon={<ChevronRight/>}
value={this.state.value}
/>
</MuiPickersUtilsProvider>
This works for me.
With typescript this works for me.
`import MomentUtils from "@date-io/moment";
export class PickerMomentUtils extends MomentUtils { constructor(props) { super(props); }
startOfMonth(date) { return this.getStartOfMonth(date); } }`