Skip to content

Add Temporal.toInstant() and simplify androidTimeZoneId() to simplify temporal conversion logic#310

Merged
rfc2822 merged 8 commits intoical4j-3to4from
androidtimeutils-timestamp-uts
Apr 7, 2026
Merged

Add Temporal.toInstant() and simplify androidTimeZoneId() to simplify temporal conversion logic#310
rfc2822 merged 8 commits intoical4j-3to4from
androidtimeutils-timestamp-uts

Conversation

@rfc2822
Copy link
Copy Markdown
Member

@rfc2822 rfc2822 commented Apr 6, 2026

This pull request includes several improvements to the temporal conversion logic:

  • Adds Temporal.toInstant() method and improves exception handling
  • Replaces Instant.ofEpochMilli(toTimestamp()) with toInstant() for cleaner conversions
  • Refactors androidTimezoneId() to use a when expression for better readability
  • Simplifies recurrence date conversion logic

No test changes required because the logic is only simplified, but not changed.

@rfc2822 rfc2822 self-assigned this Apr 6, 2026
@rfc2822 rfc2822 added the refactoring Quality improvement of existing functions label Apr 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors temporal conversion utilities and recurrence-date conversion logic to improve readability and reduce boilerplate when converting between Temporal, Instant, timestamps, and time zones.

Changes:

  • Introduces Temporal.toInstant() and refactors other conversions to use it.
  • Refactors androidTimezoneId() to a clearer when-style flow and simplifies recurrence date mapping.
  • Updates tests to use JUnit’s expected exceptions instead of manual try/catch.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
lib/src/main/kotlin/at/bitfire/synctools/util/AndroidTimeUtils.kt Adds toInstant(), refactors timestamp + timezone conversion logic, and updates exception type.
lib/src/main/kotlin/at/bitfire/synctools/mapping/calendar/builder/AndroidRecurrenceMapper.kt Simplifies recurrence date conversion via map/when and new conversion helpers.
lib/src/main/kotlin/at/bitfire/synctools/mapping/calendar/builder/DurationBuilder.kt Switches duration alignment helpers to use toInstant() instead of constructing instants from timestamps.
lib/src/test/kotlin/at/bitfire/synctools/util/AndroidTimeUtilsTest.kt Updates exception assertions and aligns tests with the new exception types/conversion approach.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rfc2822 rfc2822 changed the title Refactor temporal conversion logic for improved readability Simplify temporal conversion logic Apr 6, 2026
@rfc2822 rfc2822 changed the title Simplify temporal conversion logic Simplify temporal conversion logic by adding Temporal.toInstant() Apr 6, 2026
@rfc2822 rfc2822 changed the title Simplify temporal conversion logic by adding Temporal.toInstant() Add Temporal.toInstant() and simplify androidTimeZoneId() to simplify temporal conversion logic Apr 6, 2026
@rfc2822 rfc2822 marked this pull request as ready for review April 6, 2026 14:12
@rfc2822 rfc2822 requested a review from cketti April 6, 2026 14:17
@rfc2822 rfc2822 merged commit 34fbcb8 into ical4j-3to4 Apr 7, 2026
3 of 4 checks passed
@rfc2822 rfc2822 deleted the androidtimeutils-timestamp-uts branch April 7, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Quality improvement of existing functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants