Skip to content

Commit

Permalink
Revert "Modified ExtrapolateTimes():"
Browse files Browse the repository at this point in the history
This reverts commit 2971e35.
Reason: Not intended for current pull request.
  • Loading branch information
HitTheDrum committed Aug 22, 2017
1 parent 2971e35 commit 3aaf539
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 74 deletions.
32 changes: 8 additions & 24 deletions v2/ical.NET/Components/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public virtual IDateTime DtEnd
if (!Equals(DtEnd, value))
{
Properties.Set("DTEND", value);
ExtrapolateTimes(nameof(DtEnd));
ExtrapolateTimes();
}
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public virtual TimeSpan Duration
if (!Equals(Duration, value))
{
Properties.Set("DURATION", value);
ExtrapolateTimes(nameof(Duration));
ExtrapolateTimes();
}
}
}
Expand Down Expand Up @@ -266,36 +266,20 @@ protected override void OnDeserialized(StreamingContext context)
ExtrapolateTimes();
}

/// <summary>
/// Flag to check if ExtrapolaTimes is currently invoking to prevent multi extrapolating
/// </summary>
private bool _isExtrapolating;
private void ExtrapolateTimes(string propertyName = null)
private void ExtrapolateTimes()
{
if (_isExtrapolating) return;
_isExtrapolating = true;

if (DtEnd == null && DtStart != null && Duration != default(TimeSpan))
{
if (propertyName == nameof(DtEnd))
Duration = TimeSpan.Zero;

if (propertyName != nameof(DtEnd))
DtEnd = DtStart.Add(Duration);
DtEnd = DtStart.Add(Duration);
}
else if (DtStart == null && Duration != default(TimeSpan) && DtEnd != null)
else if (Duration == default(TimeSpan) && DtStart != null && DtEnd != null)
{
DtStart = DtEnd.Subtract(Duration);
Duration = DtEnd.Subtract(DtStart);
}
else if (/*Duration == default(TimeSpan) && */ DtStart != null && DtEnd != null)
else if (DtStart == null && Duration != default(TimeSpan) && DtEnd != null)
{
if (propertyName == nameof(Duration))
DtEnd = DtStart.Add(Duration);
else
Duration = DtEnd.Subtract(DtStart);
DtStart = DtEnd.Subtract(Duration);
}

_isExtrapolating = false;
}

protected bool Equals(Event other)
Expand Down
34 changes: 9 additions & 25 deletions v2/ical.NET/Components/Todo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override IDateTime DtStart
set
{
base.DtStart = value;
ExtrapolateTimes(nameof(DtStart));
ExtrapolateTimes();
}
}

Expand All @@ -49,7 +49,7 @@ public virtual IDateTime Due
set
{
Properties.Set("DUE", value);
ExtrapolateTimes(nameof(Due));
ExtrapolateTimes();
}
}

Expand All @@ -72,7 +72,7 @@ public virtual TimeSpan Duration
set
{
Properties.Set("DURATION", value);
ExtrapolateTimes(nameof(Duration));
ExtrapolateTimes();
}
}

Expand Down Expand Up @@ -198,36 +198,20 @@ protected override void OnDeserializing(StreamingContext context)
base.OnDeserializing(context);
}

/// <summary>
/// Flag to check if ExtrapolaTimes is currently invoking to prevent multi extrapolating
/// </summary>
private bool _isExtrapolating;
private void ExtrapolateTimes(string propertyName = null)
private void ExtrapolateTimes()
{
if (_isExtrapolating) return;
_isExtrapolating = true;

if (Due == null && DtStart != null && Duration != default(TimeSpan))
{
if (propertyName == nameof(Due))
Duration = TimeSpan.Zero;

if (propertyName != nameof(Due))
Due = DtStart.Add(Duration);
Due = DtStart.Add(Duration);
}
else if (DtStart == null && Duration != default(TimeSpan) && Due != null)
else if (Duration == default(TimeSpan) && DtStart != null && Due != null)
{
DtStart = Due.Subtract(Duration);
Duration = Due.Subtract(DtStart);
}
else if (DtStart != null && Due != null)
else if (DtStart == null && Duration != default(TimeSpan) && Due != null)
{
if (propertyName == nameof(Duration))
Due = DtStart.Add(Duration);
else
Duration = Due.Subtract(DtStart);
DtStart = Due.Subtract(Duration);
}

_isExtrapolating = false;
}
}
}
34 changes: 9 additions & 25 deletions v2/ical.NET/DataTypes/Period.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,36 +106,20 @@ public override string ToString()
return periodSerializer.SerializeToString(this);
}

/// <summary>
/// Flag to check if ExtrapolaTimes is currently invoking to prevent multi extrapolating
/// </summary>
private bool _isExtrapolating;
private void ExtrapolateTimes(string propertyName = null)
private void ExtrapolateTimes()
{
if (_isExtrapolating) return;
_isExtrapolating = true;

if (EndTime == null && StartTime != null && Duration != default(TimeSpan))
{
if (propertyName == nameof(EndTime))
Duration = TimeSpan.Zero;

if (propertyName != nameof(EndTime))
EndTime = StartTime.Add(Duration);
EndTime = StartTime.Add(Duration);
}
else if (StartTime == null && Duration != default(TimeSpan) && EndTime != null)
else if (Duration == default(TimeSpan) && StartTime != null && EndTime != null)
{
StartTime = EndTime.Subtract(Duration);
Duration = EndTime.Subtract(StartTime);
}
else if (StartTime != null && EndTime != null)
else if (StartTime == null && Duration != default(TimeSpan) && EndTime != null)
{
if (propertyName == nameof(Duration))
EndTime = StartTime.Add(Duration);
else
Duration = EndTime.Subtract(StartTime);
StartTime = EndTime.Subtract(Duration);
}

_isExtrapolating = false;
}

private IDateTime _startTime;
Expand All @@ -151,7 +135,7 @@ public virtual IDateTime StartTime
return;
}
_startTime = value;
ExtrapolateTimes(nameof(StartTime));
ExtrapolateTimes();
}
}

Expand All @@ -166,7 +150,7 @@ public virtual IDateTime EndTime
return;
}
_endTime = value;
ExtrapolateTimes(nameof(EndTime));
ExtrapolateTimes();
}
}

Expand All @@ -190,7 +174,7 @@ public virtual TimeSpan Duration
return;
}
_duration = value;
ExtrapolateTimes(nameof(Duration));
ExtrapolateTimes();
}
}

Expand Down

0 comments on commit 3aaf539

Please sign in to comment.