-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use local time zones instead of doing everything in terms of UTC - Set and compare DateTimeKind during serialization and deserialization - Get rid of IsUniversalTime property in IDateTime - IsUtc property is get-only - AsSystemLocal no longer needs to do contortions to answer the question - ToTimeZone returns local or UTC time zones for BCL, serialization, and IANA zones - Better heuristics for determining whether a CalDateTime is UTC or local - TzId setter now does all the state maintenance for UTC vs local bookkeeping, and all other related properties are get-only - Consistent, ordinal string comparison in GetZone - Truncating parts of DateTimes doesn't suck anymore - Slightly better intellisense documentation - Fixed a broken unit test - Better local vs UTC time zone handling for Unit RRULEs with unit tests - Fixed a bug in the RecurrencePatternEvaluator where tzId wasn't taking into account - MatchTimeZone is less awkward and shorter Issues: #331, #330, #332
- Loading branch information
Rian Stockbower
committed
Nov 7, 2017
1 parent
dd487ce
commit 20cb0c3
Showing
18 changed files
with
344 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Ical.Net.DataTypes; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Interfaces; | ||
|
||
namespace Ical.Net.UnitTests | ||
{ | ||
public class CalDateTimeTests | ||
{ | ||
private static readonly DateTime _now = DateTime.Now; | ||
private static readonly DateTime _later = _now.AddHours(1); | ||
private static CalendarEvent GetEventWithRecurrenceRules(string tzId) | ||
{ | ||
var dailyForFiveDays = new RecurrencePattern(FrequencyType.Daily, 1) | ||
{ | ||
Count = 5, | ||
}; | ||
|
||
var calendarEvent = new CalendarEvent | ||
{ | ||
Start = new CalDateTime(_now, tzId), | ||
End = new CalDateTime(_later, tzId), | ||
RecurrenceRules = new List<RecurrencePattern> { dailyForFiveDays }, | ||
Resources = new List<string>(new[] { "Foo", "Bar", "Baz" }), | ||
}; | ||
return calendarEvent; | ||
} | ||
|
||
[Test, TestCaseSource(nameof(ToTimeZoneTestCases))] | ||
public void ToTimeZoneTests(CalendarEvent calendarEvent, string targetTimeZone) | ||
{ | ||
var startAsUtc = calendarEvent.Start.AsUtc; | ||
|
||
var convertedStart = calendarEvent.Start.ToTimeZone(targetTimeZone); | ||
var convertedAsUtc = convertedStart.AsUtc; | ||
|
||
Assert.AreEqual(startAsUtc, convertedAsUtc); | ||
} | ||
|
||
public static IEnumerable<ITestCaseData> ToTimeZoneTestCases() | ||
{ | ||
const string bclCst = "Central Standard Time"; | ||
const string bclEastern = "Eastern Standard Time"; | ||
var bclEvent = GetEventWithRecurrenceRules(bclCst); | ||
yield return new TestCaseData(bclEvent, bclEastern) | ||
.SetName($"BCL to BCL: {bclCst} to {bclEastern}"); | ||
|
||
const string ianaNy = "America/New_York"; | ||
const string ianaRome = "Europe/Rome"; | ||
var ianaEvent = GetEventWithRecurrenceRules(ianaNy); | ||
|
||
yield return new TestCaseData(ianaEvent, ianaRome) | ||
.SetName($"IANA to IANA: {ianaNy} to {ianaRome}"); | ||
|
||
const string utc = "UTC"; | ||
var utcEvent = GetEventWithRecurrenceRules(utc); | ||
yield return new TestCaseData(utcEvent, utc) | ||
.SetName("UTC to UTC"); | ||
|
||
yield return new TestCaseData(bclEvent, ianaRome) | ||
.SetName($"BCL to IANA: {bclCst} to {ianaRome}"); | ||
|
||
yield return new TestCaseData(ianaEvent, bclCst) | ||
.SetName($"IANA to BCL: {ianaNy} to {bclCst}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
net-core/Ical.Net/Ical.Net.UnitTests/SimpleDeserializationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.