Skip to content

Commit 796853c

Browse files
authored
Revert "Fix DueDate.StringDate conversion to and from DateTime. (#37)" (#39)
This reverts commit 465061e.
1 parent 465061e commit 796853c

File tree

4 files changed

+10
-150
lines changed

4 files changed

+10
-150
lines changed

src/Todoist.Net.Tests/Helpers/FakeLocalTimeZone.cs

-37
This file was deleted.

src/Todoist.Net.Tests/Helpers/FakeLocalTimeZoneTests.cs

-37
This file was deleted.

src/Todoist.Net.Tests/Models/DueDateTests.cs

+2-73
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,13 @@
22

33
using Todoist.Net.Models;
44
using Todoist.Net.Tests.Extensions;
5-
using Todoist.Net.Tests.Helpers;
6-
75
using Xunit;
86

97
namespace Todoist.Net.Tests.Models
108
{
119
[Trait(Constants.TraitName, Constants.UnitTraitValue)]
12-
public class DueDateTests : IDisposable
10+
public class DueDateTests
1311
{
14-
15-
private readonly FakeLocalTimeZone _fakeLocalTimeZone;
16-
17-
public DueDateTests()
18-
{
19-
var timeZoneCollection = System.TimeZoneInfo.GetSystemTimeZones();
20-
21-
var randomIndex = new Random().Next(timeZoneCollection.Count);
22-
var fakeTimeZoneInfo = timeZoneCollection[randomIndex];
23-
24-
_fakeLocalTimeZone = new FakeLocalTimeZone(fakeTimeZoneInfo);
25-
}
26-
27-
public void Dispose()
28-
{
29-
_fakeLocalTimeZone.Dispose();
30-
GC.SuppressFinalize(this);
31-
}
32-
33-
3412
[Fact]
3513
public void DateTimeAssignment_FullDayEvent_Success()
3614
{
@@ -45,7 +23,7 @@ public void DateTimeAssignment_FullDayEvent_Success()
4523
[Fact]
4624
public void DateTimeAssignment_FloatingDueDateEvent_Success()
4725
{
48-
var date = new DateTime(2018, 2, 5, 0, 0, 0, DateTimeKind.Unspecified);
26+
var date = new DateTime(2018, 2, 5, 0, 0, 0, DateTimeKind.Utc);
4927

5028
var dueDate = new DueDate(date);
5129

@@ -63,54 +41,5 @@ public void DateTimeAssignment_FloatingDueDateWithTimezoneEvent_Success()
6341
Assert.Equal("2018-02-05T00:00:00Z", dueDate.StringDate);
6442
Assert.False(dueDate.IsFullDay);
6543
}
66-
67-
68-
[Fact]
69-
public void StringDateProperty_ShouldReturnExactAssignedValue_WhenValueIsFullDayDate()
70-
{
71-
// Arrange
72-
var dueDate = new DueDate();
73-
string initialValue = "2016-12-01";
74-
75-
// Act
76-
dueDate.StringDate = initialValue; // Set initial value.
77-
string returnedValue = dueDate.StringDate; // Get.
78-
dueDate.StringDate = returnedValue; // Set returned value.
79-
80-
// Assert
81-
Assert.Equal(returnedValue, dueDate.StringDate);
82-
}
83-
84-
[Fact]
85-
public void StringDateProperty_ShouldReturnExactAssignedValue_WhenValueIsFloatingDate()
86-
{
87-
// Arrange
88-
var dueDate = new DueDate();
89-
string initialValue = "2016-12-03T12:00:00";
90-
91-
// Act
92-
dueDate.StringDate = initialValue; // Set initial value.
93-
string returnedValue = dueDate.StringDate; // Get.
94-
dueDate.StringDate = returnedValue; // Set returned value.
95-
96-
// Assert
97-
Assert.Equal(returnedValue, dueDate.StringDate);
98-
}
99-
100-
[Fact]
101-
public void StringDateProperty_ShouldReturnExactAssignedValue_WhenValueIsFixedDate()
102-
{
103-
// Arrange
104-
var dueDate = new DueDate();
105-
string initialValue = "2016-12-06T13:00:00Z";
106-
107-
// Act
108-
dueDate.StringDate = initialValue; // Set initial value.
109-
string returnedValue = dueDate.StringDate; // Get.
110-
dueDate.StringDate = returnedValue; // Set returned value.
111-
112-
// Assert
113-
Assert.Equal(returnedValue, dueDate.StringDate);
114-
}
11544
}
11645
}

src/Todoist.Net/Models/DueDate.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Todoist.Net.Models
1010
/// </summary>
1111
public class DueDate
1212
{
13-
private const string DefaultEventDateFormat = "yyyy-MM-ddTHH:mm:ssK"; // Roundtrip without milliseconds.
1413
private const string FullDayEventDateFormat = "yyyy-MM-dd";
1514

1615
/// <summary>
@@ -125,7 +124,13 @@ internal string StringDate
125124
return Date.Value.ToString(FullDayEventDateFormat);
126125
}
127126

128-
return Date.Value.ToString(DefaultEventDateFormat);
127+
var date = Date.Value.ToUniversalTime();
128+
if (string.IsNullOrEmpty(Timezone))
129+
{
130+
return date.ToString("s");
131+
}
132+
133+
return date.ToString("s") + "Z";
129134
}
130135

131136
set
@@ -138,7 +143,7 @@ internal string StringDate
138143
return;
139144
}
140145

141-
Date = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
146+
Date = DateTime.Parse(value, CultureInfo.InvariantCulture);
142147
}
143148
}
144149
}

0 commit comments

Comments
 (0)