Skip to content

UTC Date format not recognized #6756

Closed
Closed
@web265p3

Description

@web265p3

Bug

I am trying to bind a property with the value "2008-10-28T00:00:00+01:00" to my material datepicker. I configured it like that:

                    <md-input-container>
                        <input mdInput 
                                [mdDatepicker]="picker2"                              
                                [formControl] = "myForm.get('MyDate')" 
                                placeholder="My date" 
                                [(ngModel)]="myDate">
                        <md-datepicker-toggle mdSuffix [for]="picker2"></md-datepicker-toggle>
                        <md-datepicker #picker2></md-datepicker>  
                    </md-input-container> 

So "myDate" has a UTC Timestamp value. I am receiving the error message:

Datepicker: value not recognized as a date object by DateAdapter

I tried to fix this, with configuring my own Date adapter:


        export class AppDateAdapter extends NativeDateAdapter { 
                format(date: Date, displayFormat: Object): string {
                    console.log(date);
                    if (displayFormat === 'input') {
                        const day = date.getDate();
                        const month = date.getMonth() + 1;
                        const year = date.getFullYear();
                        return `${day}-${month}-${year}`;
                    } else {
                        return date.toDateString();
                    }
                }
            }
         export const APP_DATE_FORMATS =
         {
             parse: {
                 dateInput: { month: 'short', year: 'numeric', day: 'numeric' },
             },
             display: {
                 dateInput: 'input',
                 monthYearLabel: { year: 'numeric', month: 'numeric' },
                 dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
                 monthYearA11yLabel: { year: 'numeric', month: 'long' },
             }
         };


@Component({
    selector: "",
    templateUrl: "my-form.component.html",
    styles: [":host /deep/ .ui-dropdown{ width: 100% !important;}"],
    providers: [{provide: DateAdapter, useClass: AppDateAdapter}, 
                {provide: MD_DATE_FORMATS, useValue : APP_DATE_FORMATS }]

})

In my "format"-function I tried to output the value the adapter receives, but the error is thrown even before. Anybody knows what I could do? Is there even a way for UTC Timestamp? I do not need the time. It should be ignored by the picker.

What is the expected behavior?

Support for UTC Datetime

What are the steps to reproduce?

Trying to bind the value "2008-10-28T00:00:00+01:00" to the datepicker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions