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

Different timezones don't work using C# #2147

Closed
kiragengis opened this issue Sep 29, 2023 · 2 comments
Closed

Different timezones don't work using C# #2147

kiragengis opened this issue Sep 29, 2023 · 2 comments

Comments

@kiragengis
Copy link

Describe the bug
When I use a Time zone different than the "Eastern Standard Time" I receive the error:
ServiceException: Code: BadRequest
Message: Invalid filter clause: The DateTimeOffset text '2023-09-28T21:14:43.4437014' should be in format 'yyyy-mm-ddThh:mm:ss('.'s+)?(zzzzzz)?' and each field value is within valid range.
Inner error:
AdditionalData:
date: 2023-09-29T15:45:02
request-id: ***
client-request-id: ***
ClientRequestId: ***

To Reproduce
Steps to reproduce the behavior:
This is how I create an instance of MicrosoftEmailHelper:

MicrosoftEmailHelper emailHelper = new MicrosoftEmailHelper();
TimeZoneInfo indiaTimeZone = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTimeOffset indiaTime = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, indiaTimeZone );

This is my request:

return client.Me.MailFolders.Inbox.Messages.Request()
                                  .Filter(filter) //can't use order by when use filters
                                  .Select(m => new { m.Subject, m.ReceivedDateTime, m.From, m.Body })
                                  .GetAsync().Result;

I create the date this way:
string filter = $"startswith(subject, '{subject}') and ReceivedDateTime ge {received_from.ToString("o")}";

As a result string within filter will be: startswith(subject, 'SUBJECT OF MY EMAIL') and ReceivedDateTime ge 2023-09-28T21:10:36.2266736+05:30

Expected behavior
I should be able to obtain the list of emails

Current results
Error:
ServiceException: Code: BadRequest
Message: Invalid filter clause: The DateTimeOffset text '2023-09-28T21:14:43.4437014' should be in format 'yyyy-mm-ddThh:mm:ss('.'s+)?(zzzzzz)?' and each field value is within valid range.
Inner error:
AdditionalData:
date: 2023-09-29T15:45:02
request-id: ***
client-request-id: ***
ClientRequestId: ***

@MartinM85
Copy link
Contributor

I think you need to encode + as %2B.

startswith(subject, 'SUBJECT OF MY EMAIL') and ReceivedDateTime ge 2023-09-28T21:10:36.2266736%2B05:30

You mentioned that you can't use orderby. I would recommend to follow the guideline in the documentation.

Using filter and orderby in the same query


When using $filter and $orderby in the same query to get messages, make sure to specify properties in the following ways:

  • Properties that appear in $orderby must also appear in $filter.
  • Properties that appear in $orderby are in the same order as in $filter.
  • Properties that are present in $orderby appear in $filter before any properties that aren't.

Failing to do this results in the following error:

  • Error code: InefficientFilter
  • Error message: The restriction or sort order is too complex for this operation.

@kiragengis
Copy link
Author

Thank you for your answer @MartinM85. You were totally right. That solved my problem. I will read the guideline in the documentation about orderby. This is a code I inherited :(

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

No branches or pull requests

3 participants