title: Angular Firebase retrieve Timestamps as Date
body: <p>I´m currently running an Angular project with Firebase as a serverless backend.
  There are two main models in the application <code>user</code> and <code>product</code>. Both of these models have several different timestamps such as <code>createdAt</code>, <code>updatedAt</code>, <code>lastPurchase</code>, ...
  </p>
  
  <pre><code>interface User {
      id: string;
      displayName: string;
      lastPurchase?: Date;
      createdAt: Date;
      updatedAt?: Date;
  }
  </code></pre>
  
  
  
  <pre><code>interface Product{
      id: string;
      title: string;
      pricing: number;
      category: string;
      user: User;
      createdAt: Date;
      updatedAt?: Date;
  }
  </code></pre>
  
  <p>The problem is that I´m working with the <code>Date</code> type, but Firebase deliveres stored dates like this <code>t {seconds: 1584540876, nanoseconds: 300000000}</code>.
  Therefore, I´m forced to convert all incoming Firebase timestamps to JavaScript <code>Date</code> types. Additionally, since Firebase´s Firestore is a NoSQL Database, I can never be certain which document contains which timestamp properties (for null checks).</p>
  
  <p>This is the current working code I use when retrieving data from Firestore, but it is quite a mess.</p>
  
  
  
  <pre><code>    // Iterate over all properties in product
      for (let key in data) {
        // Check if property is an object
        if (data[key] instanceof Object) {
          // Check if the object is Firebase Timestamp
          if (data[key].constructor.name === 't') {
            const property: string = key;
            console.log(data[key]);
            data[key] = data[property].toDate();
            // Check if property is an user
          } else if (key === 'user') {
            // Iterate over all user properties
            for (let userKey in data[key]) {
              // Check if user property is an object and the object is Firebase Timestamp
              if (data[key][userKey] instanceof Object &amp;&amp; data[key][userKey].constructor.name === 't') {
                const userProperty: string = userKey;
                data[key][userKey] = data[key][userProperty].toDate();
              }
            }
          }
        }
      }
  </code></pre>
  
  <p>Is there an alternative solution / method to achieve this with less computation?</p>