material-ui-pickers icon indicating copy to clipboard operation
material-ui-pickers copied to clipboard

Update to @date-io v1.0 caused breaking changes to Calendar

Open mattgbrich opened this issue 7 years ago • 12 comments

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.

mattgbrich avatar Jan 16 '19 18:01 mattgbrich

It is mentioned in changlog

dmtrKovalenko avatar Jan 16 '19 18:01 dmtrKovalenko

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

mattgbrich avatar Jan 16 '19 18:01 mattgbrich

Exactly, a breaking change is a breaking change, should result in major version bump

emirotin avatar Jan 17 '19 11:01 emirotin

@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 avatar Jan 17 '19 16:01 adnanba

@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 avatar Jan 17 '19 17:01 mattgbrich

@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?

adnanba avatar Jan 17 '19 20:01 adnanba

Have you updated to the most recent version of pickers? That used startOfMonth method?

dmtrKovalenko avatar Jan 17 '19 20:01 dmtrKovalenko

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?

adnanba avatar Jan 17 '19 20:01 adnanba

It seems I messed up something with my node_modules, I've got it working on a different branch.

adnanba avatar Jan 17 '19 22:01 adnanba

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

reemyrail avatar Feb 06 '19 14:02 reemyrail

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.

OnitiFR avatar Mar 19 '19 15:03 OnitiFR

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); } }`

fdepijper avatar May 17 '19 16:05 fdepijper