Skip to content

Conversation

HolgerHees
Copy link
Contributor

This fixes the mapping between a python timedelta to java Duration mapping

@jlaur can you please review?

@jlaur jlaur added bug An unexpected problem or unintended behavior of an add-on regression Regression that happened during the development of a release. Not shown on final release notes. labels May 10, 2025
Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

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

Thanks! I have proposed a small simplification, otherwise LGTM.

// picking two members to check as Duration has many common function names
v -> v.hasMember("total_seconds") && v.hasMember("total_seconds"),
v -> Duration.ofNanos(v.invokeMember("total_seconds").asLong() * 10000000),
v -> Duration.ofNanos(v.invokeMember("total_seconds").asLong() * 1000000000),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
v -> Duration.ofNanos(v.invokeMember("total_seconds").asLong() * 1000000000),
v -> Duration.ofSeconds(v.invokeMember("total_seconds").asLong()),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

another commit which fix the nano seconds accuracy and make it clear why we need "Duration.ofNanos"

Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

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

LGTM

@jlaur jlaur merged commit 4ea61d3 into openhab:main May 10, 2025
2 checks passed
@jlaur jlaur added this to the 5.0 milestone May 10, 2025
rprescott308y pushed a commit to rprescott308y/openhab-addons that referenced this pull request May 18, 2025
…hab#18671)

* fix python timedelta to java duration mapping

* fix duration accuracy
@HolgerHees HolgerHees deleted the datetimetoinstantfix branch June 26, 2025 18:30
phenix1990 pushed a commit to phenix1990/openhab-addons that referenced this pull request Jul 31, 2025
…hab#18671)

* fix python timedelta to java duration mapping

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

Labels

bug An unexpected problem or unintended behavior of an add-on regression Regression that happened during the development of a release. Not shown on final release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pythonscripting] Conversion from timedelta to Duration does not work correctly

2 participants