-
Notifications
You must be signed in to change notification settings - Fork 231
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
Introduce Duration
type to keep apart nominal vs exact durations.
#680
Conversation
04917a4
to
19e98d7
Compare
I'll be waiting until this PR gets merged before submitting a PR for |
6462038
to
9922efc
Compare
@axunonb I think the PR should be ready for review, would be great if you'd find some time for it. It's quite some code that has changed, but all in all not too complex, once the basics regarding nominal vs. exact are understood. Probably it makes sense to review the code commit by commit. I tried to keep the commits reasonably separated, but probably not perfectly everywhere. There are certainly some smaller issues around nonexistent times remaining as outlined in #681. |
The plan for a next PR re
|
if (this.TzId is not null) | ||
return SubtractExact(dt).ToDurationExact(); | ||
|
||
if (dt.HasTime != HasTime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I also tried throwing if IsFloating != dt.IsFloating
, but then all kinds of tests fail. Obviously there are quite some cases where DTSTART
has a tzid set but DTEND
hasn't, which isn't allowed by the RFC though. We should double-check whether we still want to support this case (probably yes, if its used in the wild). If so, we should probably deal with the case in a different place, probably during deserialization, and be more strict here, because the current implementation is somewhat unclear regarding that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent.
See some minor remarks.
{Edit] Just forgot to mention the nullability warnings like Possible null reference argument for parameter 'dt' in 'Duration IDateTime.Subtract(IDateTime dt)' et al
9922efc
to
8c9dba2
Compare
…onSerializer` in preparation of using the type throughout the lib.
…written as `CalDateTime.Add(-d)`.
…from `TimeSpan` to `Duration`.
…> `Duration CalendarEvent.GetEffectiveDuration()`.
…olation and introduce `GetEffectiveDuration()`, `GetEffectiveEndTime()`.
…oesn't exist in the target tz.
…ccording to RFC 5545 3.3.5
8c9dba2
to
07a55e6
Compare
bc558ea
to
6566285
Compare
Quality Gate passedIssues Measures |
@axunonb Thanks for the review! Tried to improve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, thanks a lot
This PR addresses shortcomings of the lib regarding the different requirements of nominal vs exact duration as specified by RFC 5545. It introduces the new
Duration
type that replacesTimeSpan
in most places. In contrast to the latter,Duration
stores the individual duration parts (weeks, days, hours, minutes, seconds) individually. This is required because according to the RFC weeks and days are considered nominal values while hours, minutes, seconds are considered exact (see https://www.rfc-editor.org/rfc/rfc5545#section-3.3.6, https://www.rfc-editor.org/rfc/rfc5545#section-3.8.5.3).Most relevant changes:
CalendarEvent.Duration
et al andPeriod.Duration
changed fromTimeSpan
toDuration
CalendarEvent.GetTimeSpanToAddToPeriodStartTime
replaced byCalendarEvent.GetEffectiveDuration
, which takes care of keeping apart nominal vs. exact durations. I.e. if the duration is specified via DTEND, then the returned duration only uses time-related fields, so it is considered exact. If specified viaDURATION
, the duration is returned as specified by the caller.CalDateTime.Add(Duration)
and.Subtract()
handle the different parts ofDuration
conformant to the RFC.