Currently, the Google's version of ServerValue.TIMESTAMP
returns {".sv":"timestamp"}
which is used as a directive for Firebase to fill that field with the server timestamp once you save the data to the Firebase server.
When you create your data on the client side however, you don't have the actual timestamp to play with yet (ie. use as the creation date). You only will have an access to the timestamp after the initial save and consequent retrieval, which - I imagine - is sometimes too late and not very elegant.
Before Google:
Update: Ignore this section as it is incorrect - I misunderstood the examples. ServerValue.TIMESTAMP
always returned the {".sv":"timestamp"}
.
As far as I understand in pre-google Firebase there seemed to be a server-generated timestamp available that allowed you to acquire the actual timestamp:
import com.firebase.client.ServerValue;
ServerValue.TIMESTAMP // eg. 1466094046
Questions:
- Is such save/retrieval the only way to get the server-generated creation date on my model instances?
- If yes can you propose a method of implementing such pattern?
- Am I understanding correctly ServerValue.TIMESTAMP has changed with Google's acquisition of Firebase? Update: No, @FrankvanPuffelen replied that nothing's changed during acquisition.
Note:
I'm not considering using new Date()
on client side as I've been reading it's not safe, though please share your thoughts if you think different.