diff --git a/net-core/Ical.Net/Ical.Net/DataTypes/Period.cs b/net-core/Ical.Net/Ical.Net/DataTypes/Period.cs index 3d1e18ef7..6676c8288 100644 --- a/net-core/Ical.Net/Ical.Net/DataTypes/Period.cs +++ b/net-core/Ical.Net/Ical.Net/DataTypes/Period.cs @@ -1,7 +1,7 @@ -using System; using Ical.Net.Interfaces.DataTypes; using Ical.Net.Interfaces.General; using Ical.Net.Serialization.iCalendar.Serializers.DataTypes; +using System; namespace Ical.Net.DataTypes { @@ -11,7 +11,7 @@ public class Period : EncodableDataType, IComparable public Period() { } public Period(IDateTime occurs) - : this(occurs, default(TimeSpan)) {} + : this(occurs, default(TimeSpan)) { } public Period(IDateTime start, IDateTime end) { @@ -60,21 +60,30 @@ public override void CopyFrom(ICopyable obj) Duration = p.Duration; } - protected bool Equals(Period other) => Equals(StartTime, other.StartTime) && Equals(EndTime, other.EndTime) && Duration.Equals(other.Duration); + protected bool Equals(Period other) => IsSameInstant(StartTime, other.StartTime) && IsSameInstant(EndTime, other.EndTime) && Duration.Equals(other.Duration); public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Period) obj); + return obj.GetType() == GetType() && Equals((Period)obj); + } + + public static bool IsSameInstant(IDateTime a, IDateTime b) + { + if (a == null || b == null) + { + return a == b; + } + return Equals(a.AsUtc, b.AsUtc); } public override int GetHashCode() { unchecked { - var hashCode = StartTime?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ (EndTime?.GetHashCode() ?? 0); + var hashCode = StartTime?.AsUtc.GetHashCode() ?? 0; + hashCode = (hashCode * 397) ^ (EndTime?.AsUtc.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ Duration.GetHashCode(); return hashCode; }