Home > Enterprise >  Is it possible to enforce that a Timestamp field is only updated if it is on the same day as the cur
Is it possible to enforce that a Timestamp field is only updated if it is on the same day as the cur

Time:03-27

I have a booking app where the user can change the time of their booking, but only if the new time is on the same day as the current day that they have booked. Is it technically possible to enforce this on firestore?

CodePudding user response:

You can compare the date in the document against the request.time variable, which is the timestamp on the server. Assuming that the field in your document is a Firestore Timestamp, you can compare year and dayOfYear properties of the two timestamps. If they're both the same, the value in the field is the current day.

  • Related