Skip to content

Commit

Permalink
AsUtc should return the right UTC time associated with the CalDateTim…
Browse files Browse the repository at this point in the history
…e, even if the TzId property has changed #387
  • Loading branch information
Rian Stockbower committed May 21, 2018
1 parent d84cc39 commit 84ad5ae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions net-core/Ical.Net.CoreUnitTests/CalDateTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,19 @@ public static IEnumerable<ITestCaseData> AsDateTimeOffsetTestCases()
.SetName($"Summer DateTime with no time zone information returns the system-local's UTC offset ({currentSystemOffset})")
.Returns(new DateTimeOffset(summerDate, currentSystemOffset));
}

[Test(Description = "Calling AsUtc should always return the proper UTC time, even if the TzId has changed")]
public void TestTzidChanges()
{
var someTime = DateTimeOffset.Parse("2018-05-21T11:35:00-04:00");

var someDt = new CalDateTime(someTime.DateTime) { TzId = "America/New_York" };
var firstUtc = someDt.AsUtc;
Assert.AreEqual(someTime.UtcDateTime, firstUtc);

someDt.TzId = "Europe/Berlin";
var berlinUtc = someDt.AsUtc;
Assert.AreNotEqual(firstUtc, berlinUtc);
}
}
}
14 changes: 14 additions & 0 deletions net-core/Ical.Net.FrameworkUnitTests/CalDateTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,19 @@ public static IEnumerable<ITestCaseData> AsDateTimeOffsetTestCases()
.SetName($"Summer DateTime with no time zone information returns the system-local's UTC offset ({currentSystemOffset})")
.Returns(new DateTimeOffset(summerDate, currentSystemOffset));
}

[Test(Description = "Calling AsUtc should always return the proper UTC time, even if the TzId has changed")]
public void TestTzidChanges()
{
var someTime = DateTimeOffset.Parse("2018-05-21T11:35:00-04:00");

var someDt = new CalDateTime(someTime.DateTime) { TzId = "America/New_York" };
var firstUtc = someDt.AsUtc;
Assert.AreEqual(someTime.UtcDateTime, firstUtc);

someDt.TzId = "Europe/Berlin";
var berlinUtc = someDt.AsUtc;
Assert.AreNotEqual(firstUtc, berlinUtc);
}
}
}
2 changes: 2 additions & 0 deletions net-core/Ical.Net/DataTypes/CalDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ public string TzId
return;
}

_asUtc = DateTime.MinValue;

var isEmpty = string.IsNullOrWhiteSpace(value);
if (isEmpty)
{
Expand Down

0 comments on commit 84ad5ae

Please sign in to comment.