I am working with PHP and Outlook Calendar REST API
, I am able to create the events just fine except that the date I give API to create an events is getting incremented by 11 hours and something is wrong with end_date also, for example if i am telling the API to create the event from 2014-03-31T15:00:00-0000
to 2014-03-31T16:00:00-0000
it ends up creating the event from 2014-04-01T02:00:00+1100
to 2014-04-01T02:30:00+1100
This is what my API URL looks like
https://apis.live.net/v5.0/9898ef90931244e8/events?name=testing_event&description=event_description&start_time=2014-03-31T15:00:00-0000&end_time=2014-03-31T16:00:00-0000&access_token=token-goes-here&method=POST
if I remove the -0000
at the end, i get the following error
{
"error": {
"code": "request_parameter_invalid",
"message": "The value of input parameter 'start_time' isn't valid. The expected formats for this parameter are the following: '1970-01-01T00:00:00Z', '1970-01-01T00:00:00.000Z', '1970-01-01 00:00:00Z'. In all cases, 'Z' is interchangeable with a time zone offset of the form: '+00:00', '-00:00', '+0000' or '-0000'."
}
}
I will really appreciate any help as I have spent days trying to fix this and I am pretty much out of all ideas..
A while ago I posted this question at MSDN Forum and forgot about it, today i visited the question and this is the reply I got from Outlook team explaining how to understand UTC timezone, I hope this helps someone out there stuck at the same problem and I wish they included this in their documentation. This fixed the problem I was having
*The ISO 8601 format for dates can be a bit confusing. What you're seeing in your response is actually correct. The calendar service takes your date and maps it to the time zone of the user.
"2014-03-31T15:00:00-0000" means 3 PM on March 31, 2014, with an adjustment of 0 hours and 0 minutes to translate to UTC time. In other words, this basically IS UTC time. The calendar service then translates this into the local time zone of the user for whom you are creating the event. "2014-04-01T02:00:00+1100" means 2 AM on April 1, 2014, for whatever time zone your user is in. To translate back to UTC, you need to SUBTRACT the offset from the local time. So 2 AM, April 1, 2014 in your time maps to 11 hours earlier UTC, which is 3 PM March 31, 2014 (what you entered).
If you're using Z, that means that you are essentially specifying a UTC time. So to get the desired time for your event you need to take your desired time and figure out what the corresponding UTC time is. So if the UTC offset of your user is +1100 you would need to subtract that offset from the local time of your event to calculate the UTC time. In your case I believe this would be 2014-03-31T04:00:00Z. This is actually something that's best left to code instead of trying to figure out how to do yourself. If you take a look at the "Creating Calendar Events" sample at http://isdk.dev.live.com it shows you how to do this in JavaScript - maybe there's a PHP equivalent.*