Closed ArnyminerZ closed 1 year ago
Thanks! I have added some preprocessor generalization.
Could you please change the FixInvalidDayOffsetPreprocessor
accordingly (see FIXME) and add tests similar to FixInvalidUtcOffsetPreprocessorTest
?
I really like the generalization. Take a look at the tests just in case I've missed something, or tell me if you prefer to do them in another way 😉
Mmmh... I'm not sure that the implementation really works out. It does for individual strings, but since we are processing the whole string, something like this:
Only the wrong data should be updated DURATION:-PT1D sure
Would not be fixed.
Removing ^
and $
should do the trick, I'll check now
Edit: is does seem to work however with ICalPreprocessorTest.testFixInvalidDurationTPrefixOffset
so I guess Regex.findAll
does indeed find this because the string is passed in different lines, and regex inspects them line by line.
Mmmh... I'm not sure that the implementation really works out. It does for individual strings, but since we are processing the whole string, something like this:
Only the wrong data should be updated DURATION:-PT1D sure
Would not be fixed.
Removing
^
and$
should do the trick, I'll check now
Which is what we want. When someone writes the above text as a SUMMARY (for instance when this issue would be converted to an iCalendar 😄), the text shouldn't change. It should only change for DURATION
and TRIGGER
properties. With ^(DURATION|TRIGGER):…$
we can make sure that only lines beginning with DURATION
or TRIGGER
will be modified.
Edit: is does seem to work however with
ICalPreprocessorTest.testFixInvalidDurationTPrefixOffset
so I guessRegex.findAll
does indeed find this because the string is passed in different lines, and regex inspects them line by line.
I think this is what RegexOption.MULTILINE
does.
Two other things:
groupValues
? Then we wouldn't have to juggle with substrings and String indexes.The duration of a week or a day depends on its position in the calendar. In the case of discontinuities in the time scale, such as the change from standard time to daylight time and back, the computation of the exact duration requires the subtraction or addition of the change of duration of the discontinuity.
With DST, one day in the year has 23 hours, and another day has 25 hours. This is relevant for calculating events, and I think it's the reason why the "T" is not used for days and weeks in the iCalendar duration syntax.
So I'd suggest to rewrite PTxD
to PxD
instead of PT<x*24>H
.
So I'd suggest to rewrite
PTxD
toPxD
instead ofPT<x*24>H
.
Yup, I think this would be the easiest approach. Also simplifies parsing.
Context is in icsx5#100.
Changes
fixInvalidDayOffset
fixInvalidDayOffset
->testFixInvalidDurationTPrefixOffset
Duration
s withfixInvalidDayOffset
->testFixInvalidDuration
fixInvalidDayOffset
The logic for doing the replacements is:
-?PT-?\d+D
, this is all the matches that start optionally with a-
, followed byPT
, then optionally a-
(this is because the negative indicator can be beforePT
or in the number properly), followed by a number, and the letterD
.PT
or-PT
) followed by the amount of hours found, and thenH
.Extra considerations
Right now all matches of the "PT pattern" are replaced. This might cause issues with descriptions or other fields that for any reason have that format. Maybe we should list all the properties that have the Duration type, which as far as I'm concerned are:
DURATION
TRIGGER