microsoft graph createreply wrong timezone - timezone

In our Angular 5 application, we are using Microsoft Graph to retrieve mail messages from a mailbox and then send a reply. For creating the reply, we use the REST API:
https://graph.microsoft.com/v1.0/me/messages/{message ID}/createReply
This creates a reply with a timezone that is UTC, but we expect it to be GMT+1. For example, in the mail body it says:
From: Melissa van Dijk
Sent: Friday, February 23, 2018 9:51:49 AM (wrong timestamp)
To: Melissa van Dijk
Subject: Meet for lunch?
We checked the settings in our Office 365 mail account and there it is specified that our local timezone is GMT+1 (Brussels, Amsterdam...).
(When replying via Outlook webmail, we get a correct timestamp).
Is this a bug or do we have to correct this timestamp ourselves? Or do we need to pass the timezone with the REST call somehow?
Thanks in advance!

I'm not sure if you can adjust the human-formatted timestamps in the HTML message body, but you can certainly use the ISO 8601 formatted timestamps in the other fields in the JSON of the response. For example, you'll find:
{
...
"sentDateTime": "2018-02-23T09:51:49Z",
...
}
While this is also in UTC (denoted by the Z), you can easily parse it by using a JavaScript Date object, or Angular's own datetime functions, or your favorite time library such as Luxon, Moment, or Date-fns. From there, displaying it in local time is trivial.

Related

Magento 2.3.4 Different hour in REST API

I send request via REST API
https://www.mysite.pl/rest/V1/orders/89
And have date and time:
"created_at": "2021-09-21 15:59:34",
When I go to Saels->Orders in admin there is different data and time:
"Sep 21, 2021, 5:59:34 PM"
So there is a 2 hours difference. I think this cause a problem with my payment module. In admin timezone is set to CET Warsaw. Why in REST API call there is other time ?
I fixed this issue for me by selecting the "Coordinated Universal time" in admin:
Store -> configuration -> General -> General -> Local Options

How to get Locale from userprofile information from TFS

How to get Locale from userprofile information from TFS? I couldnot find any information in MSDN and internet.
That's not documented, however you can track the API with third tools such as Fiddler or directly press F12 in Chrome.
You can use below REST API to get the user profile:
GET http://server:8080/tfs/DefaultCollection/_api/_common/GetUserProfile?__v=5
For the Locale information, seems we can only get the Language and Time zone by the "LCID" and "TimeZoneId" (Ctrl + F -> Enter the LCID or TimeZoneId to find out the locale info).
The Date pattern and Time pattern are not recorded in JSON response, the value is null for both of them.
See below example with the screenshot:
"TimeZoneId": "Central Asia Standard Time",
"LCID": 1033,

Apply DateTime filter for getting list messages in gmail using gmail API

I am using GMAIL API to get messages between a date range. My problem is for one of my client account the display datetime and actual received date/sent datetime differs. IS there a way to read messages in UTC time zone?
Thanks,
Haseena
There is an open issue that affects the timezone of dates in search queries. Unfortunately there is no workaround at the moment.
$newTime = strtotime('-15 day');
$after = strtotime(date('Y-m-d H:i:s', $newTime));
$opt_param = array();
$userId = 'me';
$opt_param['q'] = "after:$after";
$messagesResponse = $service->users_messages->listUsersMessages($userId, $opt_param);

Prevent JsonResult from auto-formatting Dates

I'm writing a cloud based program that utilizes UTC for date saving to the server, and convert it back on the round trip. Problem is, my instance in the cloud is autoconverting the JsonResult datetime values according to the localization settings on the browser obtaining the result.
I have gone through tons of steps to make sure the server side code on both levels is returning the proper data, and it is on all instances, and no Javascript code on my page is making the change either (even removed all my Javascript date formatting just in case), I have traced out with Firebug to determine the exact point that it changes, is when my page receives the Json Result from my JsonResult method. Like I said, I have debugged the values before being sent to the page, and they are proper, and on my response, they are modified based upon browser location....
Has anyone had a similar problem?
Value returned:Date(1341792000000) 07/08/2012 17:00
Should be: Date(1341817200000) (07/09/2012 12:00AM)
Thanks
I finally ended up getting the proper results, with many modifications to my application. I did a lot of stuff to make this happen... First, I implemented timezone.JS to get a listing of timezones that will be used within the application, and used jstz to get current timezone of browser loading the page. Next, I have to make (for mvc) an file get method that accesses the timezones to load into timezoneJS.
Next, on save of the timezone, I specified pst as the type, and then convert back to utc on roundtrip to update the interface.
On formatting of my Json date, I run the timezoneJS method and get the timezone name from jstz, and set the new date value like such:
var timezone = jstz.determine();
timezoneJS.timezone.zoneFileBasePath = '/Item/GetTz'; // get file method
var dt = new timezoneJS.Date(parseInt(jsonDate.substr(6), timezone.name())); // strips out date from json date
dt.setTimezone('America/Los_Angeles');
This allows on the cloud projects to be ran on any server, and displayed in any browser regardless of timezone, and allow the user to view and configure timezone sensitive data natively, and allow for users to see the start/end date of configurable database values.
Maybe using http://msdn.microsoft.com/en-us/library/system.datetime.specifykind.aspx
Did you try with,
date.toLocaleString()
Alternatively,
You can create a new Date object and use Date.setUTC
As the OP said:
Problem is, my instance in the cloud is autoconverting the JsonResult datetime values according to the localization settings on the browser obtaining the result.
Recently experienced something similar. Strange behavior coming from $.ajax response. Depending on the language setting of the browser, a date received in string format gets converted into whatever is set in the language setting.
For example, in Postman, Web API response is like so:
{
"id": "10057",
"d_date": "3/30/2017 3:00:00 AM",
"sum": 253.0
},
If the browser is set to english(en/en-us), response is the same as above.
If the browser is set to english-uk(en-gb), response becomes:
{
"id": "10057",
"d_date": "30/03/2017 03:00:00",
"sum": 253
}
If the browser is set to german(de), response becomes:
{
"id": "10057",
"d_date": "30.03.2017 03:00:00",
"sum": 253
}
So somehow, the browser or the $.ajax library is trying to be smart and formatting the dates automatically.
Probably, the best solution is that the Web API send the date in ISO date time format.
Another solution if you can't change the backend is to add accept-language: en in the AJAX header request. Something like so:
$.ajax({
type: 'POST',
url: '/endpoint/',
contentType: 'application/json',
data: JSON.stringify(body),
dataType: 'json',
async: false,
headers: {
'accept-language': 'en'
}
})

How to get twitter server time?

So I'm trying to build a real time monitoring tool for twitter key words using tweet sharp. I'm using the search API to collect queries every 10-15 seconds. When I make the calls, I only want to collect tweets that have appeared since the pervious update.
var twitter = FluentTwitter.CreateRequest().AuthenticateAs("username", "password").Search().Query().Containing("key word").Take(1000);
var response = twitter.Request();
currentResponseDateTime= Convert.ToDateTime(response.ResponseDate);
var messages = from m in response.AsSearchResult().Statuses
where m.CreatedDate > lastUpdateDateTime
select m;
lastUpdateDateTime = currentResponseDateTime;
My issue is that the twitter server time is different from the client times by a few seconds. I looked around and tried to get the datetime I recieved the response from the Response.ResponseDate property, but it looks like that is set based on the local computer time. I.e currentResponseDateTime is a few seconds ahead of the Twitter Server time. So I end up not collecting a few of the tweets.
Does anyone know how I can get the current server time from twitter search or REST API?
Thanks
I'm not sure how you would get the local server time of the twitter service, but one approach you could take is to store the date of the most recent twitter update seen in the "lastUpdateDateTime" field. That way, you're guaranteed to get all the messages since the last one you saw, regardless of the offset of the twitter server.
var twitter = FluentTwitter.CreateRequest().AuthenticateAs("username", "password").Search().Query().Containing("key word").Take(1000);
var response = twitter.Request();
currentResponseDateTime= Convert.ToDateTime(response.ResponseDate);
var messages = from m in response.AsSearchResult().Statuses
where m.CreatedDate > lastUpdateDateTime
select m;
lastUpdateDateTime = messages.Select(m => m.CreatedDate).Max();
Another approach (and one that Twitter recommends) is to pull the Date header from their API server's response, which provides Twitter's notion of time in GMT. This assumes that you can access the server response headers, and that depends on the method you're using to access the API.
For example, hitting https://api.twitter.com/1/help/test.json
$ lynx --dump --head https://api.twitter.com/1/help/test.json
HTTP/1.0 200 OK
Date: Tue, 22 Jan 2013 13:30:36 GMT
...
Reference: how to get the twitter server time (synchronize)? on dev.twitter.com support site.
Quoting Taylor Singletary:
The current time that Twitter "thinks" it is is returned in the "Date" HTTP header of every response to an API call you make. You can also issue a simple HTTP HEAD request to GET help/test to get the header as an initial syncing step for your app.

Resources