I am dealing with a specific problem related to the processing of the date and time in my application. I am using .NET with C# as the backend and ReactNative with TypeScript as the frontend for my Mobile Application.
Currently, the way I am storing the date and time is,
- The user enters the Date and Time which is captured in the TypeScript's
Date
object. This date is as per the user's timezone. - This date is converted to string using
dayjs
. The string format is2019-01-25T10:30:00.000Z
. When converting to string,dayjs
converts the date from the user's timezone to UTC. - This date in UTC is then stored in the database through an API call.
- When requested, the API returns the date in UTC.
- This date string is again converted into TypesScript's
Date
object usingdayjs
and while converting,dayjs
converts it back into the user's timezone.
I am facing a problem when I need to use the date and time directly from the backend. One example is sending push notifications.
I trigger the push notifications from the backend. And in one of the notifications, I want to send the date and time. The problem is when I prepare the message of notification in the backend, I have the date in UTC and I don't have any information regarding the actual timezone of the user.
What should I do to solve this problem? Currently, I am dealing with notifications but in the future, I am also planning to send text or WhatsApp messages. So, I am looking for solutions that can be used with future requirements also.
Also, there can be a case where there is communication between two users of different time zones. So, one user enters the time as per his/her timezone and when sending a notification to the other user, the system should send a notification as per that user's timezone.