Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time Zone Problem #368

Open
Nicding opened this issue Dec 6, 2019 · 11 comments
Open

Time Zone Problem #368

Nicding opened this issue Dec 6, 2019 · 11 comments
Labels

Comments

@Nicding
Copy link

Nicding commented Dec 6, 2019

When I forwarding the mail, in mail content history, the sent time of the last mail is always shown in UTC time zone.
image

The correct time is:
image

I have tried to change my local time zone, change time zone of my email account and change param timezone in Account class. But none of them worked.

Do you have any suggestion on this?
Thank you so much for your time.

@alejcas
Copy link
Member

alejcas commented Dec 10, 2019

I don't know what your problem is. Maybe you have to explain this in more detail.

Read #364

@Nicding
Copy link
Author

Nicding commented Dec 11, 2019

Thank you very much for your reply.

Let me explain this issue in more detail with an example:
I received a mail at 10:19 AM (UTC+8). And if I replied this mail manually, in mail content history, the receiving time of this original mail is shown correctly in my local time zone (UTC+8).
image

But if I replied the same mail by python-o365, in mail content history, receiving time is shown in time zone UTC+0
image

If there is any concern, please feel free to let me know.
Thank you very much.

@alejcas
Copy link
Member

alejcas commented Dec 11, 2019

Ok! I understand it now. Let me do some tests

@alejcas
Copy link
Member

alejcas commented Dec 17, 2019

Ok, this library saves the datetimes always in UTC.

I was supposing that the Outlook interface convert datetimes to your local timezone but it seems that when replying from OWA it's not doing it.

I test this on the Outlook desktop app and it shows all datetimes in your local timezone.

Maybe we should save the datetimes on the local timezone defined instead of UTC.

I'll meditate this further.

@Narcolapser what do you think?

@Nicding
Copy link
Author

Nicding commented Dec 18, 2019

Thanks for your reply.

I also did some further investiagtion during last few days.
I tried to use outlook REST API directly, and found the receiving time had already become wrong in body.content in reponse.
So I thought this issue might be an issue of Office 365 API.
I read the API document and found very little information about the time zone. I tried to added the header Prefer: outlook.timezone="Asia/Shanghai", and it also didn't work.

Hope above information could help.

@alejcas
Copy link
Member

alejcas commented Dec 18, 2019

@Nicding thanks! That’s very useful

@Narcolapser
Copy link
Member

I to will have to think a bit. Presumably, there wouldn't be any harm in saving in the local time zone as long as you mark it as such. It will need to be in the hands of the app developer though. Since we don't know what application someone is making we don't know if timezone could change on us or not.

Digging into the code, it looks like all interactions with the API are assuming UTC, is that what you were referring to with "I was supposing that the Outlook interface converts datetimes"? In such a case, would it be hard to add some sort of check on whether to set the "__received" value to local or utc?

@alejcas
Copy link
Member

alejcas commented Dec 19, 2019

The library gets datetimes in any timezone and converts to the local timezone.
The library saves datetimes only in UTC (it converts from local timezone to UTC).

What I was supposing is that the Outlook interface should convert any saved datetime to the local timezone before showing the datetime to the user.

And in fact it does this at least when using the Outlook desktop app.

I think this is because of this... but I'm not sure.

# when saving or sending drafts:

if self.created:
    message[cc('createdDateTime')] = self.created.astimezone(pytz.utc).isoformat()
if self.received:
    message[cc('receivedDateTime')] = self.received.astimezone(pytz.utc).isoformat()
¡if self.sent:
    message[cc('sentDateTime')] = self.sent.astimezone(pytz.utc).isoformat()

Should we save always in the user defined timezone?

@Narcolapser
Copy link
Member

I think that's going to be the behavior that the user expects. As in, if I'm not working with multiple time zones then everything should be in mine. Would it be difficult to have that as the default behavior with the option to specify your timezone?

@alejcas
Copy link
Member

alejcas commented Jan 10, 2020

I think that's going to be the behavior that the user expects. As in, if I'm not working with multiple time zones then everything should be in mine. Would it be difficult to have that as the default behavior with the option to specify your timezone?

Then we should implement this change.
This is a breaking change.

I'll see how to achieve that.

@alejcas alejcas added the bug label Apr 30, 2020
@alejcas
Copy link
Member

alejcas commented Apr 30, 2020

After analysing this, the library should not send UTC datetimes to the server.
I'll change this soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants