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

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?

Related

Handling Date and Time in Backend and Frontend

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.

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,

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.

Is there an alternative to C# Thread.CurrentThread.CurrentCulture in Java?

Is there an alternative to C# Thread.CurrentThread.CurrentCulture in Java? If not what is the best place to store user selected locale in Java?
Locale.setDefault() sets the default locale for the whole JVM, which is fine for a client application. For a web application, it's not a valid solution, but a thread-local is not either, since the same threads are used for all the users. In this case, the user locale is typically stored in the HTTP session.
If you have web SpringMVC based web application there's this class org.springframework.context.i18n.LocaleContextHolder (javadoc here), which gives you access to the current locale.
In webapplication this may be initialized on the basis of accept-language request header (javadoc here) in DispatcherServlet.

Categories