matheo / angular

Open Source Angular Libraries: MatDataSource, MatDatepicker
http://matheo.co/demos/
MIT License
60 stars 15 forks source link

Value for timepicker is a full date #27

Closed daboudii closed 3 years ago

daboudii commented 3 years ago

Describe the bug

Maybe I am expecting too much from this very nice lib but. When I'm selecting a time 13:27:45, the value of the form update to a full date like 2021-06-14T13:27:45.099Z

Expected behavior

The form should update the value with 13:27:45

Your Environment

Angular Version:


Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.3
@angular-devkit/build-angular   12.0.3
@angular-devkit/core            12.0.3
@angular-devkit/schematics      12.0.3
@angular/cdk                    12.0.4
@angular/material               12.0.4
@schematics/angular             12.0.3
rxjs                            6.6.7
typescript                      4.2.4
matheo commented 3 years ago

For this expected output, you will need to use your DateAdapter (or the Native one) to process the Date, like:

import { NativeDateAdapter } from '@matheo/datepicker/core';

constructor(private adapter: NativeDateAdapter) {}

save(): void {
  const myTime = this.adapter.format(this.form.value.time, { hour: 'numeric', minute: 'numeric', second: 'numeric' });
}

Note that the parameters of the format method depends on the Adapter; luxon or moment uses other kind of format expressions.