Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[automation] Add basic time-related classes for usage in script and rules #2587

Merged
merged 1 commit into from
Dec 10, 2021

Conversation

cweitkamp
Copy link
Contributor

@cweitkamp cweitkamp commented Dec 3, 2021

  • Added basic time-related classes for usage in script and rules

This allows to use DateTime functions a lot easier for users without defining additional imports. We have public methods in different types which makes use of these classes e.g.

public DateTimeType toZone(ZoneId zoneId) throws DateTimeException {

org.joda.time API has a method DateTime.now().withTimeAtStartOfDay() which was used by many users. The replacement is ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS).

Duration class allows easy calculation of differences between two timestamps (Duration.between(Temporal startInclusive, Temporal endExclusive) - ZonedDateTime implemets Temporal interface).

Signed-off-by: Christoph Weitkamp [email protected]

@cweitkamp cweitkamp added enhancement An enhancement or new feature of the Core automation DSL rules Domain-Specific Language rules labels Dec 3, 2021
@cweitkamp cweitkamp requested a review from a team as a code owner December 3, 2021 09:23
@cweitkamp cweitkamp changed the title [automation] Added basic time-related classes for usage in script and ruled [automation] Added basic time-related classes for usage in script and rules Dec 4, 2021
@kaikreuzer
Copy link
Member

The replacement that I am actually using in my rules is

now.toLocalDate.atStartOfDay.atZone(ZoneId.systemDefault)

but it all isn't as nice as the withTimeAtStartOfDay from old Jodatime. 😞

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@kaikreuzer kaikreuzer merged commit 793ced6 into openhab:main Dec 10, 2021
@kaikreuzer kaikreuzer changed the title [automation] Added basic time-related classes for usage in script and rules [automation] Add basic time-related classes for usage in script and rules Dec 10, 2021
@kaikreuzer kaikreuzer added this to the 3.2 milestone Dec 10, 2021
@cweitkamp cweitkamp deleted the feature-automation-time-classes branch December 11, 2021 10:05
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation DSL rules Domain-Specific Language rules enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants