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

[discovery] Refactor java.util.Date usages to java.time.Instant #4026

Merged
merged 1 commit into from Jan 7, 2024

Conversation

jlaur
Copy link
Contributor

@jlaur jlaur commented Jan 7, 2024

This refactors some java.util.Date usages to the more modern time API.

The API is preserved as epoch milliseconds, so this is a non-breaking change.

There is two user-facing changes, though.

  1. This console command has changed formatting:
openhab> openhab:inbox list
NEW [mydevice]: My Device [thingId=my:device:0, bridgeId=null, properties={ipAddress=192.168.0.1}, representationProperty=null, timestamp=2024-01-07T15:33:15.500Z, timeToLive=UNLIMITED]

Previously this would be displayed like this:

openhab> openhab:inbox list
NEW [mydevice]: My Device [thingId=my:device:0, bridgeId=null, properties={ipAddress=192.168.0.1}, representationProperty=null, timestamp=Sat Nov 11 16:33:15 CET 2023, timeToLive=UNLIMITED]

Since this is already quite technical, I didn't see a reason to invest in preserving the old formatting.

  1. Changed debug logging

This is now UTC-formatted:

Removed thing 'mydevice' from inbox because it was older than 2024-01-07T15:33:15.500Z

@jlaur jlaur requested a review from a team as a code owner January 7, 2024 16:01
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@J-N-K J-N-K added the enhancement An enhancement or new feature of the Core label Jan 7, 2024
@J-N-K J-N-K added this to the 4.2 milestone Jan 7, 2024
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

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

Thanks. IMO the new formatting is even an improvement compression to the one before.

@J-N-K J-N-K merged commit 6b2182d into openhab:main Jan 7, 2024
3 checks passed
@jlaur jlaur deleted the config-discovery-date branch January 7, 2024 20:54
@@ -43,7 +43,7 @@ public class DiscoveryResultImpl implements DiscoveryResult {
private @Nullable String representationProperty;
private @NonNullByDefault({}) DiscoveryResultFlag flag;
private @NonNullByDefault({}) String label;
private long timestamp;
private Instant timestamp = Instant.MIN;
Copy link
Contributor Author

@jlaur jlaur Jan 8, 2024

Choose a reason for hiding this comment

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

@J-N-K - unfortunately I ran into this nasty regression today a moment ago:

2024-01-08 21:43:22.754 [ERROR] [re.storage.json.internal.JsonStorage] - Couldn't deserialize value 'org.openhab.core.storage.json.internal.StorageEntry@3df4a8fa'. Root cause is: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was NUMBER at path $.timestamp

so now realize that this object is deserialized from the JSON file userdata/org.openhab.core.config.discovery.DiscoveryResult.json.

The easy solution is to revert this variable back to long. Alternately we can keep Instant, but implement custom deserialization that can handle both. WDYT? Right at this moment I'm not sure where this is deserialized.

jlaur added a commit to jlaur/openhab-core that referenced this pull request Jan 8, 2024
Partially revert openhab#4026

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@J-N-K
Copy link
Member

J-N-K commented Jan 8, 2024

Write a converter for the JSON storage.

cipianpascu pushed a commit to cipianpascu/openhab-core that referenced this pull request Jan 17, 2024
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
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.

None yet

2 participants