Skip to content
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

bug: MD_DATE_FORMATS is not exported - cannot customize date time formats #4534

Closed
davidgabrichidze opened this issue May 13, 2017 · 10 comments · Fixed by #4541
Closed

bug: MD_DATE_FORMATS is not exported - cannot customize date time formats #4534

davidgabrichidze opened this issue May 13, 2017 · 10 comments · Fixed by #4541
Assignees

Comments

@davidgabrichidze
Copy link
Contributor

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Customizing the parse and display formats by example:

@NgModule({
  imports: [MdDatepickerModule],
  providers: [
    {provide: DateAdapter, useClass: NativeDateAdapter},
    {provide: MD_DATE_FORMATS, useValue: MY_NATIVE_DATE_FORMATS},
  ],
})
export class MyApp {}

What is the current behavior?

MD_DATE_FORMATS const is not exported by datetime/index.ts, so it is not available in @angular/material

@crisbeto crisbeto self-assigned this May 14, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue May 14, 2017
* Makes the MD_DATE_FORMATS and MD_NATIVE_DATE_FORMATS public.
* Fixes some trailing whitespace in the datepicker readme.

Fixes angular#4534.
jelbourn pushed a commit that referenced this issue May 15, 2017
…4541)

* Makes the MD_DATE_FORMATS and MD_NATIVE_DATE_FORMATS public.
* Fixes some trailing whitespace in the datepicker readme.

Fixes #4534.
@Yeradon Yeradon mentioned this issue May 24, 2017
@linuradu
Copy link

linuradu commented Jun 2, 2017

Could someone help me how can I customize date format with md-datepicker?

I'm using:

            <md-input-container class="whole-width">
            <input mdInput [mdDatepicker]="picker"  [(ngModel)]="contact.birthDate" 
                   placeholder="Birthdate">
                <button mdSuffix [mdDatepickerToggle]="picker"></button>
            </md-input-container>
            <md-datepicker #picker></md-datepicker>

And the date format that is sent to the backend is: 2017-06-14T21:00:00.000Z
I need to send like "MM/dd/yyyy"
Does someone have any idea?

@webplease
Copy link

same problem here! :(

@spd-e-gonzales
Copy link

Having the same problem in beta.6. At a loss for why I'm getting the following

ERROR in [at-loader] ./origin/app/monitor/xxxxxx.module.ts:94:20
TS2304: Cannot find name 'MD_DATE_FORMATS'.

even though i've imported in module.ts

import { MaterialModule, MdNativeDateModule, DateAdapter, MdDatepickerModule } from "@angular/material";

defined MY_DATE_FORMATS:

const MY_DATE_FORMATS = {
parse: {
dateInput: { month: 'short', year: 'numeric', day: 'numeric' }
},
// dateInput: { month: 'short', year: 'numeric', day: 'numeric' },
dateInput: 'input',
monthYearLabel: { year: 'numeric', month: 'short' },
dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
monthYearA11yLabel: { year: 'numeric', month: 'long' },
};

@NgModule({
imports: [
MdDatepickerModule,
MaterialModule,
MdNativeDateModule
],
SNIPPED
providers: [
{ provide: DateAdapter, useClass: NativeDateAdapter },
{ provide: MD_DATE_FORMATS, useValue: MY_DATE_FORMATS }
]

@karolmie1
Copy link

@spd-e-gonzales I think that you need to import MD_DATE_FORMATS explicitely, so:
import { MaterialModule, MdNativeDateModule, DateAdapter, MdDatepickerModule, MD_DATE_FORMATS } from "@angular/material";

@Ronald-13
Copy link

Kinda stuck with similar issue. Can someone post a working solution?
import{ MdDatepickerModule,MdNativeDateModule,DateAdapter, MD_DATE_FORMATS } from '@angular/material';
import { MyDateAdapter,MY_DATE_FORMATS } from '../providers/MyDateAdapter';
providers: [
{ provide: DateAdapter, useClass: MyDateAdapter },
{ provide: MD_DATE_FORMATS, useValue: MY_DATE_FORMATS }
]

@ghost
Copy link

ghost commented Jun 30, 2017

@Bhawna14
Copy link

Bhawna14 commented Aug 8, 2017

Hi @crisbeto , i am trying to import 'MY_NATIVE_DATE_FORMATS' from "@angular/material" and it throws error as "it has no exported member 'MY_NATIVE_DATE_FORMATS'.
using "@angular/material": "^2.0.0-beta.8",
Please suggest.

@MarcoGomesr
Copy link

MarcoGomesr commented Aug 8, 2017

@Bhawna14 'MY_NATIVE_DATE_FORMATS' is class that you create is not imported from "@angular/material" .... what you import from material is MD_DATE_FORMATS

import { MdNativeDateModule,
         DateAdapter,
         MD_DATE_FORMATS } from '@angular/material';

@sadhac
Copy link

sadhac commented Apr 17, 2019

@spd-e-gonzales I think that you need to import MD_DATE_FORMATS explicitely, so:
import { MaterialModule, MdNativeDateModule, DateAdapter, MdDatepickerModule, MD_DATE_FORMATS } from "@angular/material";

Its now MAT_DATE_FORMAT

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants