title: Unable to get Timestamp document field from Firestore
body: <p>When getting data from Firestore, I am unable to get a timestamp field.</p>
  
  <p>My Room document is structured like this:</p>
  
  <p><a href="https://i.stack.imgur.com/2BdpK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2BdpK.png" alt="enter image description here"></a></p>
  
  <p>and I'm getting the rooms from Firestore like below.</p>
  
  <p>Helper class:</p>
  
  <pre><code>    fun getRooms(userId: String): Task&lt;QuerySnapshot&gt; {
          return FirebaseFirestore.getInstance()
                  .collection(KEY_USERS).document(userId)
                  .collection(KEY_ROOMS).get()
      }
  </code></pre>
  
  <p>Interactor class:</p>
  
  <pre><code>private fun getRooms(): Task&lt;List&lt;Room&gt;&gt; {
      val source = TaskCompletionSource&lt;List&lt;Room&gt;&gt;()
      val listener = OnCompleteListener&lt;QuerySnapshot&gt; {
          if (it.isSuccessful) {
              val roomSnapshots = it.result
              if (!roomSnapshots.isEmpty) {
                  val rooms = ArrayList&lt;Room&gt;()
                  for (roomSnapshot in roomSnapshots) {
                      rooms.add(Room(roomSnapshot))
                  }
                  source.setResult(rooms)
              }
          } else {
              source.setException(it.exception!!)
          }
      }
      FirebaseFireStoreHelper.getRooms(mUserId).addOnCompleteListener(listener)
      return source.task
  }
  </code></pre>
  
  <p>My <code>Room</code> model class:</p>
  
  <pre><code>class Room(document: DocumentSnapshot) {
  
      companion object {
          private const val KEY_DATE_CREATED = "dateCreated"
          private const val KEY_TITLE = "title"
      }
  
      private lateinit var mId: String
      private lateinit var mDateCreated: Date
      private lateinit var mTitle: String
  
      init {
          if (document.exists()) {
              mId = document.id
              mDateCreated = document.getDate(KEY_DATE_CREATED)!!
              mTitle = document.getString(KEY_TITLE)!!
          }
      }
  
      fun getId(): String = mId
  
      fun getDateCreated(): Date? = mDateCreated
  
      fun getTitle(): String = mTitle
  
  }
  </code></pre>
  
  <p>The issue is that <code>document.getDate(KEY_DATE_CREATED)</code> is always returning <code>null</code>. I've tried using <code>get(KEY_DATE_CREATED)</code> and <code>getString(KEY_DATE_CREATED)</code> just to see if I could get any value, but to no avail.</p>
  
  <p>After a few more tries, I tested printing out the whole object and was able to get this:</p>
  
  <pre><code>DocumentSnapshot{
      key=users/kCKkmgLmLGfvbPFK09qyZ5uoyw32/rooms/R35Bj56rda7pkkYWH1MQ,
      metadata=SnapshotMetadata{
          hasPendingWrites=false,
          isFromCache=false
      },
      doc=Document{
          key=users/kCKkmgLmLGfvbPFK09qyZ5uoyw32/rooms/R35Bj56rda7pkkYWH1MQ,
          data=zza{
              (title=&gt;Sample Room)
          };,
      version=SnapshotVersion(seconds=1523285961, nanos=350799000),
      hasLocalMutations=false
      }
  }
  </code></pre>
  
  <p>So apparently, the <code>dateCreated</code> field is not being retrieved in the first place, which explains the null value. From the code I have, I believe I'm handling the parsing properly. What's confusing is I also have a <code>Message</code> object that has a <code>dateCreated</code> timestamp field and I'm able to get it properly.</p>
  
  <p>P.S.: The sample codes are in Kotlin, I could post a Java code version if it could help make things more clear.</p>
  
  <hr>
  
  <p>Update: Here's a screenshot of the Message document from Firestore.</p>
  
  <p><a href="https://i.stack.imgur.com/cNkKS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cNkKS.png" alt="enter image description here"></a></p>
  
  <p>And here's the my <code>Message</code> model class:</p>
  
  <pre><code>class Message(document: DocumentSnapshot) {
  
      companion object {
          private const val KEY_CONTENT = "content"
          private const val KEY_DATE_CREATED = "dateCreated"
      }
  
      private lateinit var mId: String
      private lateinit var mContent: String
      private lateinit var mDateCreated: Date
  
      // TODO: Figuring out why getDate doesn't seem to work for Rooms
  
      init {
          if (document.exists()) {
              mId = document.id
              mContent = document.getString(KEY_CONTENT)!!
              mDateCreated = document.getDate(KEY_DATE_CREATED)!!
          }
      }
  
      fun getId(): String = mId
  
      fun getContent(): String = mContent
  
      fun getDateCreated(): Date = mDateCreated
  
      fun getStringFormattedDateCreated() = FormatterUtil.getFormattedTimestamp(mDateCreated)
  
  }
  </code></pre>
  
  <p>Making the Date nullable (<code>?</code>) for <code>Room</code> does nothing.</p>