Skip to content

Commit

Permalink
Ignore timezone if two periods are compared for equality
Browse files Browse the repository at this point in the history
This solves the case where exception dates are ignored due to different time zone than the recurring event.
  • Loading branch information
rbuehlma committed Oct 23, 2017
1 parent 887adeb commit c2b6779
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions net-core/Ical.Net/Ical.Net/DataTypes/Period.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -11,7 +11,7 @@ public class Period : EncodableDataType, IComparable<Period>
public Period() { }

public Period(IDateTime occurs)
: this(occurs, default(TimeSpan)) {}
: this(occurs, default(TimeSpan)) { }

public Period(IDateTime start, IDateTime end)
{
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c2b6779

Please sign in to comment.