1

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,

  1. 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.
  2. This date is converted to string using dayjs. The string format is 2019-01-25T10:30:00.000Z. When converting to string, dayjs converts the date from the user's timezone to UTC.
  3. This date in UTC is then stored in the database through an API call.
  4. When requested, the API returns the date in UTC.
  5. This date string is again converted into TypesScript's Date object using dayjs 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.

Hem Bhagat
  • 323
  • 3
  • 12
  • 2
    You will probably need to store the user's timezone as well and convert UTC to that specific timezone. The second requirement might not be logical, if you want to convert user A to user B timezones, you will either be delaying the message of trying to send it retrospectively, why not send it immediately, irrespective of user B's timezone? – b166er Feb 02 '23 at 05:45
  • 1
    You can use DateTimeOffset, see this answer on a similar question https://stackoverflow.com/a/14268167/13359090 – EspressoCode Feb 02 '23 at 06:33

0 Answers0