Angular / Firebase - Extracting date and time from timestamp

Viewed 78

I have an angular form where there’s a date input (using Angular materials date picker) and a time picker (using https://github.com/IliaIdakiev/angular-material-timepicker). When i create a new item, the date is pre-populated with a Firestore timestamp. In my edit form, both the date and time are referencing the same field. Both seem to be read correctly.

If i change the time, the time aspect of the field is updated and the date is left alone. That’s good. However, whenever I change the date, it overwrites the date AND time aspects. Looking at my save button for the form (which will update the date) I have the following:

let formValue = { ...this.form.value };
for (let prop in formValue) {
  if (!formValue[prop] && formValue[prop] != 0) {
    delete formValue[prop];
  }
}

this.doc.update(formValue)

What i'd like to achieve

  1. When updating the time from the angular-material-timepicker, it updates only the time for the existing timestamp (this currently works!)
  2. When updating the date from the Angular Material Date Picker, that it only updates the date, not the time. (Right now, changing the date will reset the value to something like January 20, 2021 at 12:00:00 AM UTC)
0 Answers
Related