Skip to content

Optimize ZonedDateTime.now().toInstant()#5303

Merged
holgerfriedrich merged 1 commit into
openhab:mainfrom
jlaur:zoneddatetime-now-instant
Jan 25, 2026
Merged

Optimize ZonedDateTime.now().toInstant()#5303
holgerfriedrich merged 1 commit into
openhab:mainfrom
jlaur:zoneddatetime-now-instant

Conversation

@jlaur

@jlaur jlaur commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

Creating a ZonedDateTime just to get its Instant is unnecessary.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes unnecessary ZonedDateTime allocations where only an Instant (or epoch millis) is required, and modernizes day-of-week formatting in a test.

Changes:

  • Replace ZonedDateTime.now().toInstant() with Instant.now() where only epoch millis are needed.
  • Replace legacy Date/SimpleDateFormat usage with DateTimeFormatter in the day-of-week test setup.
  • Make locale handling for day-of-week uppercasing explicit.

Reviewed changes

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

File Description
itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/DayOfWeekConditionHandlerTest.java Switches to DateTimeFormatter for day-of-week derivation and removes legacy date APIs.
bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java Uses Instant.now() for timestamp comparisons instead of creating ZonedDateTime instances.
bundles/org.openhab.core.io.rest.log/src/main/java/org/openhab/core/io/rest/log/internal/LogHandler.java Uses Instant.now().toEpochMilli() for log timestamps instead of ZonedDateTime conversion.

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

@holgerfriedrich holgerfriedrich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks.
Use of default locale is gone now, too.

@holgerfriedrich holgerfriedrich merged commit c543c21 into openhab:main Jan 25, 2026
13 of 15 checks passed
@holgerfriedrich holgerfriedrich added the enhancement An enhancement or new feature of the Core label Jan 25, 2026
@holgerfriedrich holgerfriedrich added this to the 5.2 milestone Jan 25, 2026
@jlaur jlaur deleted the zoneddatetime-now-instant branch January 25, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or new feature of the Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants