Dates in Cloud Firestore
Why you should use serverTimestamp and not local dates.

Just a guy who loves to write code and watch anime.
Search for a command to run...
Why you should use serverTimestamp and not local dates.

Just a guy who loves to write code and watch anime.
No comments yet. Be the first to comment.
Qualities that make outstanding builders.

Bipedal vs quadrupedal: how many legs This is about the number of legs the creature walks on. Bipedal. Two legs. Humans, ostriches, T-rex, kangaroos, most fantasy humanoids. Quadrupedal. Four legs. Do

Intro You hear "lerp" and "smoothstep" everywhere in game dev. They sound like math jargon. They're not. Both are small tools that do the same job: smoothly move from one value to another. The problem

What is Kinematics Kinematics is the math field. It's the study of how things move without worrying about forces (which would be dynamics). FK and IK are the two branches: forward kinematics and inver

Intro Textures are usually the biggest cost in a 3D scene. Memory, bandwidth, and load time all get eaten by them. Resizing them is the obvious lever. There's more. This post is about the less obvious

Looking back, learning Cloud Firestore and using it, one of the greatest confusions I had was how serverTimestamp worked, and why in some instances the timestamp of my document would be undefined for a split second.
When writing to Firestore documents, you shouldn't trust your local date, i.e. use new Date() for your dates. The date on the client could have a different date and time on it than what the server expects. A user's clock could be different, and they can even try to intercept and write malicious dates to the server.
You should instead use serverTimestamp(), which would act as a placeholder, and when the write operation is happening on the server, it then inserts what the server time is in that spot.
This way we can keep our dates properly synchronized.