Microsoft Graph 事件资源类型:更新开始和结束日期时间问题 [英] Microsoft Graph Event Resource type: Updating Start and End datetime issue

查看:96
本文介绍了Microsoft Graph 事件资源类型:更新开始和结束日期时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Microsoft Graph .NET SDK更新 Outlook 事件.以下代码正确更新日期,但它更新 StartEnd 时间为四个小时后.当我转到 Outlook 日历时,它显示更改时间为 04:30 开始和 05:30 结束 而不是 显示 08:30 表示开始,09:30 表示结束.问题:为什么?备注:我在美国东部时区,但我认为这段代码与此无关,除非我在这里遗漏了一些东西.

I'm using Microsoft Graph .NET SDK to update outlook events. Following code updates the dates correctly, but it updates the Start and End times as four hours behind. When I go to my Outlook Calendar, it shows the changed times as 04:30 for Start and 05:30 for End instead of showing 08:30 for Start and 09:30 for End. Question: Why? Remark: I'm in US East time zone but I don't think this code has anything to do with it unless I'm missing something here.

代码:

authProvider"{id}" 变量的值与问题无关,因为具有实际值的代码在更新时可以正常工作事件没有错误.

The values of authProvider and "{id}" varibles are not that relevant to the issue as the code with the real values works fines as it does update the event without error.

.....
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
    
var @event = new Event
{
    Subject = "Test subject",
    Body= new ItemBody { Content = "Test body content"}
    Start = new DateTimeTimeZone { DateTime = "2020-08-29T08:30:00.0000000", TimeZone = "UTC" }
    End = new DateTimeTimeZone { DateTime = "2020-08-29T09:30:00.0000000", TimeZone = "UTC" }
};
await graphClient.Me.Events["{id}"]
    .Request()
    .UpdateAsync(@event);

推荐答案

如果您更新约会并将时区设置为 UTC,然后查看与东部 Outlook 时区相同的约会,那么这种行为听起来是正确的.作为一般规则,您应该检查约会的时区(或您修改的邮箱),然后在您的更新中匹配它(特别是如果您处理多个时区).可能影响时区的另一件事是 Outlook.Prefer 标头 https://docs.microsoft.com/en-us/graph/api/user-list-events?view=graph-rest-1.0&tabs=http 例如设置这个

If your updating the appointments and setting the TimeZone to UTC and then viewing the same appointment where the Outlook timezone in Eastern then that behavior sounds correct. As a general rule you should check the TimeZone of the appointment (or the Mailbox your modifying) and then match that in your update (especially if your dealing with multiple timezone). The other thing that can affect Time Zones is the Outlook.Prefer Header https://docs.microsoft.com/en-us/graph/api/user-list-events?view=graph-rest-1.0&tabs=http eg to set this

        List<Option> options = new List<Option> { new HeaderOption("Prefer", "outlook.timezone=\"Eastern Time\"") };

        await graphClient.Me.Events["{id}"]
            .Request(options)
            .UpdateAsync(@event);

附加

好的,这是我创建的一个快速单元测试,它创建一个约会然后更新它.在 Outlook 中,这向我显示了东部标准时间的更正更新日期时间.如果我在活动详细信息中将 UTC 替换为东部标准时间,那么它将会议时区更改为 UTC,因此时间也会改变(如果您在活动中使用 UTC,我认为这是您的问题).我建议您使用 Outlook 桌面客户端查看约会,它会向您显示与约会关联的时区,而 Web 客户端只是为您提供调整后的值.

Okay here's a quick unit test I created that creates an appointment and then updates it. In Outlook this shows me the corrected updated Datetime in Eastern Standard Time. If i substitute UTC for Eastern Standard Time in the Event details then it changes the Meeting Time Zone to UTC so will shift the time also (which i think is your issue if you are use UTC in the event). I would suggest you take a look at the appointment with the Outlook Desktop client as well as it will show you the TimeZone associated with the appointment where the web client just gives you the adjusted value.

            List<Option> options = new List<Option> { new HeaderOption("Prefer", "outlook.timezone=\"Eastern Standard Time\"") };
        DateTimeTimeZone start = new DateTimeTimeZone { DateTime = "2020-08-29T08:30:00.0000000", TimeZone = "UTC" };
        var @event = new Event
        {
            Subject = "Test subject",
            Body = new ItemBody { Content = "Test body content" },
            Start = new DateTimeTimeZone { DateTime = "2020-08-29T07:30:00.0000000", TimeZone = "Eastern Standard Time" },
            End = new DateTimeTimeZone { DateTime = "2020-08-29T08:30:00.0000000", TimeZone = "Eastern Standard Time" }
        };
        var newEvent = await GraphServiceClient.Me.Events
            .Request(options)
            .AddAsync(@event);
        @event = new Event
        {
            Subject = "Updated subject",
            Body = new ItemBody { Content = "Test body content" },
            Start = new DateTimeTimeZone { DateTime = "2020-08-29T08:30:00.0000000", TimeZone = "Eastern Standard Time" },
            End = new DateTimeTimeZone { DateTime = "2020-08-29T09:30:00.0000000", TimeZone = "Eastern Standard Time" }
        };
        await GraphServiceClient.Me.Events[newEvent.Id]
       .Request(options)
       .UpdateAsync(@event);

这篇关于Microsoft Graph 事件资源类型:更新开始和结束日期时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆