Handling Date and Time in Backend and Frontend - c#

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 is 2019-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 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.

Related

How to send a push notification on app (andorid/ios) that uses webview and on the back-end is .NET WebAPI

I am working on a booking application, so I need to create a notification that will be displayed 24h before the booking as a reminder and asking in the notification is the client coming or not.
We use react(for android and ios it's a webview) on front, .NET on back as a WEB API and SQL Server for the database.
Bookings are on 1 hour, I had an idea of creating a webjob that will run every hour and query the database what are the bookings that are in one day ahead and to send to the specific users the message and ask them are they coming or not.
Is this possible or I need to switch from a webview to react native, and any suggestions about this idea of mine?
you sould use webserive and use time based timer for opening popup page for all users in other times.(and query the database what are the bookings that are in one day ahead and to send to the specific users the message and ask them are they coming or not. Is this possible or I need to switch from a webview to react native, and any suggestions about this idea of mine)

How to get UTC offset from Microsoft Graph API's timezone value returned from /me/mailboxSettings/timeZone?

I'm using the /me/mailboxSettings/timeZone Graph API to get a user's timezone information.
In attempt to figure out the expected return result format, I came across this documentation:
https://learn.microsoft.com/en-us/graph/api/resources/datetimetimezone?view=graph-rest-1.0
So it seems MS Graph's supported timezones are a mixture of Windows and IANA timezones.
But there is no doc that mentions what kind of timezone one should expect when calling the /me/mailboxSettings/timeZone API.
Does this mean I should expect to encounter both IANA and Windows timezones when calling this API?
If that is the case, is there a quick method to use this info to get the current UTC offset from the timezone, when the timezone could be in either Windows or IANA format at runtime?
From the documentation on get mailbox settings graph will support both IANA and Windows Timezones depending on the mailbox configuration. There are some questions on how to convert between IANA and Windows timezones see how-to-translate-between-windows-and-iana-time-zones - then you can use TimeZoneInfo to get the GetUtcOffset method.
I hope this helps,

How to prevent WebAPI and OData from sending timezone with query results?

In the odata documentation they state:
"By Default, converting between DateTimeOffset and DateTime will lose the Time Zone information. Therefore, Web API provides a API to config the Time Zone information on server side. For example:"
But when I write the code, my results are coming down with a Time Zone, I have not implemented the configuration identified in the documentation (as it is only meant to specify a time zone). Is it possible to send a property type of DateTime to the client without the time zone information? If not how is this accomplished without having to write code in the client to fix the data?

Get Current Time from Google using Google .NET client library?

Can I somehow request the current time from Google using the Google .NET Client library and C#?
I am migrating an older calendar application that syncs calendars using modification times. I realize there is a new sync token method, but everything is already working using the modification time method for syncing. My app remembers the last time it synced, so it uses this in future Events.List requests as the UpdatedMin value. Currently it uses the local computer's time, and if this is off, it can miss events posted in this short time period. Knowing the current time from Google will help here.

How to display records based on time for a particular TimeZone in web application

I have created a wcf which connects to crm and fetch records from crm.
I have some date base filter condition,which filter records based upon date and time.
If a user from US browse the application he should only see records based upon its timezone,similarly if user from India should only see records based upon Indian time.
what all should be considered for creating such a functionality
can anyone share some sample code
Thanks
CRM stores datetimes at the UTC Time Zone in the database. When a user access data through CRM, the application will calculate the difference between the user's Time Zone and UTC and change the time as appropriate. When a user saves a datetime though the CRM application, the application will convert that to UTC and save it in the database. Therefore, CRM already does this for you - so you don't have to.

Categories