Skip to content

Conversation

@ArnyminerZ
Copy link
Member

@ArnyminerZ ArnyminerZ self-assigned this Nov 6, 2025
@ArnyminerZ ArnyminerZ requested a review from a team as a code owner November 6, 2025 12:25
@ArnyminerZ ArnyminerZ added the bug Something isn't working label Nov 6, 2025
@ArnyminerZ ArnyminerZ linked an issue Nov 6, 2025 that may be closed by this pull request
Signed-off-by: Arnau Mora <[email protected]>
Signed-off-by: Arnau Mora <[email protected]>
Signed-off-by: Arnau Mora <[email protected]>
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

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

See #135 (comment)

The "parse and catch exception" approach doesn't seem to be a proper solution, at least not in the handle().

I think we should define a separate parseStartDate() method that

  • has well-defined inputs and outputs,
  • supports the required input formats,
  • is tested separately.

Within that method, we should use other methods to determine the input format. If that's really not possible, we can still use the exception method.

Signed-off-by: Arnau Mora <[email protected]>
@ArnyminerZ ArnyminerZ marked this pull request as draft November 10, 2025 13:51
@ArnyminerZ ArnyminerZ requested a review from rfc2822 December 1, 2025 08:09
@ArnyminerZ
Copy link
Member Author

Should be ready. I've added tests for all formats from AOSP Contacts which should cover the original issue (bitfireAT/davx5-ose#1797 - 2013-11-06T00:00:00.000Z)

@ArnyminerZ ArnyminerZ marked this pull request as ready for review December 1, 2025 08:10
@ArnyminerZ ArnyminerZ requested a review from rfc2822 December 1, 2025 10:11
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

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

Looks good, a few small things

return OffsetDateTime.parse(dateString, formatter)
} catch (_: DateTimeParseException) {
// ignore: given date is not valid
continue
Copy link
Member

Choose a reason for hiding this comment

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

Can continue be omitted? I think it shouldn't change anything.

* @param dateString The date string to parse.
* @return The parsed [PartialDate] or `null` if parsing fails.
*/
internal fun parsePartialDate(dateString: String): PartialDate? {
Copy link
Member

Choose a reason for hiding this comment

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

Should be @VisibleForTesting, too

* @return The parsed [PartialDate] or `null` if parsing fails.
*/
internal fun parsePartialDate(dateString: String): PartialDate? {
var dateString = dateString // to allow modification
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer only constants. So maybe something like val withoutZ = ..., then val preparedDateStr = ... and then parse it.

dateString = dateString.removeSuffix("Z") + "+00:00"
}

val regex = "\\.\\d{3}".toRegex()
Copy link
Member

Choose a reason for hiding this comment

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

Shall we drop {1,3} or only with 3 decimal places?


val regex = "\\.\\d{3}".toRegex()
if (dateString.contains(regex)) {
// partial dates do not accept nanoseconds, so strip them if present
Copy link
Member

Choose a reason for hiding this comment

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

Nanoseconds or milliseconds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EventHandler doesn't handle start date with time

2 participants