I am trying to figure out the best approach to a problem. I have a firebase cloud function that listens to changes made on a firebase database path. Once a change in the database path is made, the cloud function gets triggered and sends a notification to a user.
Within this cloud function, I am storing details of the notification in the database (another path) so the user can come back and view their past notifications within my app.
The problem I am facing is storing the correct date and time. Currently, I am using the new Date() function to capture this information within the cloud function but this is obviously wrong as it is returning the server time. I need to capture the client time (the person who is receiving the notification) and store that value in the database.
The thing is, the client can be in any country so I need to account for different time zones. How do I do this? I feel like there must be a simple approach to this but I'm just not seeing it.
===
For anyone who comes across this post looking for a solution, I found the solution on this post:
Convert UTC date time to local date time
It works just the fine on Firebase Cloud Function code :-)