@@ -26,27 +26,6 @@ public class CalendarEvent : RecurringComponent, IAlarmContainer, IComparable<Ca
2626 {
2727 internal const string ComponentName = "VEVENT" ;
2828
29- /// <summary>
30- /// The start date/time of the event.
31- /// <note>
32- /// If the duration has not been set, but
33- /// the start/end time of the event is available,
34- /// the duration is automatically determined.
35- /// Likewise, if the end date/time has not been
36- /// set, but a start and duration are available,
37- /// the end date/time will be extrapolated.
38- /// </note>
39- /// </summary>
40- public override IDateTime DtStart
41- {
42- get => base . DtStart ;
43- set
44- {
45- base . DtStart = value ;
46- ExtrapolateTimes ( 2 ) ;
47- }
48- }
49-
5029 /// <summary>
5130 /// The end date/time of the event.
5231 /// <note>
@@ -66,7 +45,6 @@ public virtual IDateTime DtEnd
6645 if ( ! Equals ( DtEnd , value ) )
6746 {
6847 Properties . Set ( "DTEND" , value ) ;
69- ExtrapolateTimes ( 0 ) ;
7048 }
7149 }
7250 }
@@ -100,11 +78,24 @@ public virtual TimeSpan Duration
10078 if ( ! Equals ( Duration , value ) )
10179 {
10280 Properties . Set ( "DURATION" , value ) ;
103- ExtrapolateTimes ( 1 ) ;
10481 }
10582 }
10683 }
10784
85+ /// <summary>
86+ /// Calculates and returns the effective duration of this event.
87+ /// </summary>
88+ /// <remarks>
89+ /// If the 'DURATION' property iis set, this method will return it.
90+ /// Otherwise, if DTSTART and DTEND are set, it will calculate the duration from those.
91+ /// Otherwise it will return `default(TimeSpan)`.
92+ /// </remarks>
93+ /// <returns>The effective duration of this event.</returns>
94+ public virtual TimeSpan GetEffectiveDuration ( )
95+ => ( Properties . ContainsKey ( "DURATION" ) ) ? Duration
96+ : ( ( DtEnd != null ) && ( DtStart != null ) ) ? DtEnd . Subtract ( DtStart )
97+ : default ( TimeSpan ) ;
98+
10899 /// <summary>
109100 /// An alias to the DtEnd field (i.e. end date/time).
110101 /// </summary>
@@ -257,26 +248,6 @@ protected override void OnDeserializing(StreamingContext context)
257248 protected override void OnDeserialized ( StreamingContext context )
258249 {
259250 base . OnDeserialized ( context ) ;
260-
261- ExtrapolateTimes ( - 1 ) ;
262- }
263-
264- private void ExtrapolateTimes ( int source )
265- {
266- /*
267- * Source values, a fix introduced to prevent stack overflow exceptions from occuring.
268- * -1 = Anybody, stack overflow could maybe still occur in this case?
269- * 0 = End
270- * 1 = Duration
271- */
272- if ( DtEnd == null && DtStart != null && Duration != default ( TimeSpan ) && source != 0 )
273- {
274- DtEnd = DtStart . Add ( Duration ) ;
275- }
276- else if ( Duration == default ( TimeSpan ) && DtStart != null && DtEnd != null && source != 1 )
277- {
278- Duration = DtEnd . Subtract ( DtStart ) ;
279- }
280251 }
281252
282253 protected bool Equals ( CalendarEvent other )
@@ -289,6 +260,7 @@ protected bool Equals(CalendarEvent other)
289260 && string . Equals ( Summary , other . Summary , StringComparison . OrdinalIgnoreCase )
290261 && string . Equals ( Description , other . Description , StringComparison . OrdinalIgnoreCase )
291262 && Equals ( DtEnd , other . DtEnd )
263+ && Equals ( Duration , other . Duration )
292264 && string . Equals ( Location , other . Location , StringComparison . OrdinalIgnoreCase )
293265 && resourcesSet . SetEquals ( other . Resources )
294266 && string . Equals ( Status , other . Status , StringComparison . Ordinal )
@@ -348,6 +320,7 @@ public override int GetHashCode()
348320 var hashCode = DtStart ? . GetHashCode ( ) ?? 0 ;
349321 hashCode = ( hashCode * 397 ) ^ ( Summary ? . GetHashCode ( ) ?? 0 ) ;
350322 hashCode = ( hashCode * 397 ) ^ ( Description ? . GetHashCode ( ) ?? 0 ) ;
323+ hashCode = ( hashCode * 397 ) ^ Duration . GetHashCode ( ) ;
351324 hashCode = ( hashCode * 397 ) ^ ( DtEnd ? . GetHashCode ( ) ?? 0 ) ;
352325 hashCode = ( hashCode * 397 ) ^ ( Location ? . GetHashCode ( ) ?? 0 ) ;
353326 hashCode = ( hashCode * 397 ) ^ Status ? . GetHashCode ( ) ?? 0 ;
0 commit comments