Repository navigation
feat(datepicker): Add Moment.js adapter - #6860
Conversation
762a341 to
dba2aad
Compare
|
There's still something in the build configuration that isn't right. We get an error |
| this.setLocale(dateLocale || moment.locale()); | ||
| } | ||
|
|
||
| setLocale(locale: any) { |
There was a problem hiding this comment.
Can the type be more specific than any here since you know you're working with whatever moment supports?
|
|
||
| // Temporarily change the global locale to get the data we need, then change it back. | ||
| let globalLocale = moment.locale(); | ||
| moment.locale(locale); |
There was a problem hiding this comment.
Instead of changing the locale, can't you pass an argument to moment.localeData()?
const momentLocaleData = moment.localeData(locale);
this._localeData = {
firstDayOfWeek: momentLocaleData.firstDayOfWeek(),
longMonths: momentLocaleData.months(),
...
};There was a problem hiding this comment.
Somehow missed the fact that you can do that
| export class MomentDateAdapter extends DateAdapter<moment.Moment> { | ||
| // Note: all of the methods that accept a `moment.Moment` input parameter immediately call | ||
| // `this.clone` on it. This is to ensure that we're working with a `moment.Moment` that has the | ||
| // correct locale setting while avoiding mutating the original object passed to us. |
There was a problem hiding this comment.
Why is this necessary for things that read and return a primitive, e.g. getYear? How would the instance be mutated there? Might be helpful to include an example of what you're trying to avoid
| moment.locale(globalLocale); | ||
| } | ||
|
|
||
| getYear(date: moment.Moment): number { |
There was a problem hiding this comment.
Make an alias at the beginning of the file for brevity?
type Moment = moment.Moment;|
|
||
| createDate(year: number, month: number, date: number): moment.Moment { | ||
| // Check for invalid month and date (except upper bound on date which we have to check after | ||
| // creating the Date). |
There was a problem hiding this comment.
Mention what moment would otherwise do if the month is out of range?
There was a problem hiding this comment.
Moment actually does the right thing, just want to be able to give better errors to the user
| // Add some locales for testing. These definitions come from Moment.js's fr.js and ja.js locale | ||
| // files. (We don't want to the version of moment that comes with locales because it's a lot of | ||
| // extra bytes to include in our tests.) | ||
| moment.defineLocale('fr', { |
There was a problem hiding this comment.
Move this constant data into a separate file and import it?
0c59d70 to
cbeb48e
Compare
|
Comments addressed, PTAL. Super huge thank you to @devversion for helping with a bunch of build issues |
5d39384 to
a0e60b3
Compare
jelbourn
left a comment
There was a problem hiding this comment.
LGTM, just one more request for comment
| import {DateAdapter, MAT_DATE_LOCALE} from '@angular/material'; | ||
|
|
||
| // Depending on whether rollup is used, moment needs to be imported differently. | ||
| // TODO(mmalerba): See if we can clean this up at some point. |
There was a problem hiding this comment.
Can you expand this comment to explain more of what's happening?
a0e60b3 to
db1514d
Compare
devversion
left a comment
There was a problem hiding this comment.
Sorry for the trouble with the build system. Bazel 🔜
| { | ||
| "compilerOptions": { | ||
| // Needed for Moment.js since it doesn't have a default export. | ||
| "allowSyntheticDefaultImports": true, |
There was a problem hiding this comment.
I don't think we need that anymore right?
There was a problem hiding this comment.
We need it if we want webstorm to not complain about import {default as moment} from 'moment', not sure if we care about that or not...
|
Good morning, |
8e626c9 to
f46106f
Compare
back as a docs example in future PR).
f46106f to
bbdb0f9
Compare
* Revert "Revert "fix(menu): multiple close events for a single close" (#7036)" This reverts commit dcfe515. * Revert "feat(datepicker): Add Moment.js adapter (#6860)" This reverts commit 9545427. * Revert "fix(menu): multiple close events for a single close (#6961)" This reverts commit 1cccd4b. * Revert "fix(menu): nested trigger staying highlighted after click (#6853)" This reverts commit 04bf3d1. * Revert "feat(viewport-ruler): add common window resize handler (#6680)" This reverts commit 881630f.
|
While having a moment.js based date adapter is better than nothing, there are still little questions after reviewing the code. Was date-fns considered as an immutable alternative? Using it would help reducing the potential defect count, and would get rid of the necessity to manually My related post and a comment on the related subject got zero attention, even though I provided a code snippet with ISO8601 date adapter that is the first step to a pull request. |
|
@another-guy I'd certainly be open to adding a date-fns one as well, but last I checked it didn't support custom parsing formats which is the main thing lacking in the |
|
@mmalerba Good to know. I was sure there is a strong reason to use moment.js over the date-fns. Thanks for the answer! |
* create moment adapter * add Moment to karma.conf.js * use MAT_DATE_LOCALE * tests are now running * add in tests * WIP: demo * add synthetic default imports for moment * add locale switching to demo * fix moment import issues with tests * fix aot * address comments * fix closure issue * add additional explanation of rollup issue * remove moment adapter demo since it is preventing sync into g3 (will add back as a docs example in future PR). * fix bad rebase
…#7036) * Revert "feat(datepicker): Add Moment.js adapter (angular#6860)" This reverts commit 9545427. * Revert "fix(menu): multiple close events for a single close (angular#6961)" This reverts commit 1cccd4b.
…lar#7054) * Revert "Revert "fix(menu): multiple close events for a single close" (angular#7036)" This reverts commit dcfe515. * Revert "feat(datepicker): Add Moment.js adapter (angular#6860)" This reverts commit 9545427. * Revert "fix(menu): multiple close events for a single close (angular#6961)" This reverts commit 1cccd4b. * Revert "fix(menu): nested trigger staying highlighted after click (angular#6853)" This reverts commit 04bf3d1. * Revert "feat(viewport-ruler): add common window resize handler (angular#6680)" This reverts commit 881630f.
|
Thanks for the moment date adapter. This will come in handy. Are there examples on how to implement this? Thanks. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.