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

UTC issue #1

Closed
pgolebiowski opened this issue Nov 3, 2017 · 5 comments
Closed

UTC issue #1

pgolebiowski opened this issue Nov 3, 2017 · 5 comments

Comments

@pgolebiowski
Copy link

pgolebiowski commented Nov 3, 2017

Regarding the property Item.DueDateUtc, it does not seem to be in UTC when sent to Todoist. Here is your code for the converter:

public UtcDateTimeConverter()
{
    DateTimeFormat = "yyyy-MM-ddTHH:mm";
}

I think it is missing Z at the end: https://www.w3.org/TR/NOTE-datetime.

Even though I specifically assign a DateTime that has DateTimeKind set to Utc and hour=0 and minutes=0, it gets converted to 01:00, because the UtcDateTimeConverter does not specify UTC (missing Z).

olsh added a commit that referenced this issue Nov 3, 2017
@olsh
Copy link
Owner

olsh commented Nov 3, 2017

Hi @pgolebiowski,
Thank you for reporting.

This is strange, but according to the documentation we shouldn't pass the Z. Todoist API assumes that the time is UTC.
I've just written a test, and it seems like everything works as expected.

Please let me know if I'm wrong.

@pgolebiowski
Copy link
Author

Hi @olsh,

First, thank you for your continuous effort on providing the library. Much appreciated! 😄

Here is my code:

var client = new TodoistClient("here is my token");

var item1 = new Item("Test item with date string.")
{
    DateString = "2017-12-01"
};

var item2 = new Item("Test item with UTC DateTime.")
{
    DueDateUtc = new DateTime(2017, 12, 1, 0, 0, 0, DateTimeKind.Utc)
};

var id1 = client.Items.AddAsync(item1).Result;
var id2 = client.Items.AddAsync(item2).Result;

var retrieved1 = client.Items.GetAsync(id1).Result.Item.DueDateUtc.Value;
var retrieved2 = client.Items.GetAsync(id2).Result.Item.DueDateUtc.Value;

Console.WriteLine(retrieved1.ToString("u"));
Console.WriteLine(retrieved2.ToString("u"));

The result:

screen shot 2017-11-04 at 02 17 10

2017-12-01 22:59:59Z
2017-12-01 00:00:00Z

I understand -- Todoist converts dates to the local time instead of just showing what was assigned there. It totally makes sense.

However, the result is exactly the same when I change DateTimeKind.Utc to DateTimeKind.Local 😔 I suppose your code could detect that there is DateTimeKind.Local set and before truncating this information, use it to obtain DateTime in UTC.

When I type:

var item = new Item("Test item with UTC DateTime.")
{
	DueDateUtc = new DateTime(2017, 12, 1, 0, 0, 0, DateTimeKind.Local).ToUniversalTime()
};

var id = client.Items.AddAsync(item).Result;
var retrieved = client.Items.GetAsync(id).Result.Item.DueDateUtc.Value;
Console.WriteLine(retrieved.ToString("u"));

Then it works:

screen shot 2017-11-04 at 02 38 08

2017-11-30 23:00:00Z

Hope it helps.

@olsh
Copy link
Owner

olsh commented Nov 4, 2017

Ahh, I see the problem now.
Completely agree with you that it should convert local time to UTC. Will fix this soon.

@olsh olsh closed this as completed in fb4ceb6 Nov 4, 2017
@olsh
Copy link
Owner

olsh commented Nov 4, 2017

Thank you for the detail explanation! 👍
Just published 1.3.3 with the bugfix.

@pgolebiowski
Copy link
Author

@olsh Glad to help. Keep up the great work! 😄

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

No branches or pull requests

2 participants