Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented missing Journal constructor so Initialize method is called. #310

Merged
merged 5 commits into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 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();
ExtrapolateTimes(nameof(DtEnd));
}
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public virtual TimeSpan Duration
if (!Equals(Duration, value))
{
Properties.Set("DURATION", value);
ExtrapolateTimes();
ExtrapolateTimes(nameof(Duration));
}
}
}
Expand Down Expand Up @@ -266,20 +266,36 @@ protected override void OnDeserialized(StreamingContext context)
ExtrapolateTimes();
}

private void ExtrapolateTimes()
/// <summary>
/// Flag to check if ExtrapolaTimes is currently invoking to prevent multi extrapolating
/// </summary>
private bool _isExtrapolating;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this solve a problem that you have a test case for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will open another Pull Request incl. description to separate this from the current request.

private void ExtrapolateTimes(string propertyName = null)
{
if (_isExtrapolating) return;
_isExtrapolating = true;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use braces for conditionals.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

Duration = TimeSpan.Zero;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't commit commented-out code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood!

{
if (propertyName == nameof(Duration))
DtEnd = DtStart.Add(Duration);
else
Duration = DtEnd.Subtract(DtStart);
}

_isExtrapolating = false;
}

protected bool Equals(Event other)
Expand Down
34 changes: 25 additions & 9 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();
ExtrapolateTimes(nameof(DtStart));
}
}

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

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

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

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

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

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

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

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

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

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

_isExtrapolating = false;
}

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

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

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

Expand Down