-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
[core] Use Instant
internally for DateTimeType
#3583
base: main
Are you sure you want to change the base?
Conversation
ab14428
to
81c3dc0
Compare
I hit a wall with this when realizing that I don't know if any @openhab/webui-maintainers can throw some light at what may be a possible way forward? |
4ec7437
to
229ee4e
Compare
229ee4e
to
266b055
Compare
@mherwege - seeing your work in #4169 I'm wondering if you can advise how to accomplish decoupling the time-zone + formatting of Currently it's formatted like this: |
@jlaur Main UI works with what it gets from the REST API.
The formatted state comes from the
So, to understand where Line 953 in cbb458e
state is added through the EnrichedItemDTOMapper here: Line 81 in cbb458e
So it is simply using the toFullString() method on the state of the item.
|
@mherwege - many thanks for your insights. I will have a closer look at this soon. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
0829630
to
d007aa1
Compare
@openhab/core-maintainers - I don't have permission to remove the "work in progress" label since I'm not in the contributors team, so perhaps someone can do that for me? I consider this PR ready for review now after finally fixing the returned @mherwege - perhaps you'd also like to have a look? |
What about bindings setting a DateTimeType state with a particular time zone? |
They can still do that, but the time-zone will be stripped, so it's really not needed anymore.
It should be, but there can be unit tests failing if they expect a certain time-zone: DateTimeType dt = new DateTimeType(ZonedDateTime.now());
ZonedDateTime zdt = dt.getZonedDateTime(); Previously this would return a |
d007aa1
to
6f47d07
Compare
@joerg1985 - perhaps you would also like to have a look? I saw some of your recent related comments and enhancements, e.g. #4384. |
This will call Line 300 in 3bc9ae3
which is probably the reason for system time-zone being used in some places. I don't know how to improve this, since Keeping it "as is", in current version of the code I have provided, will be correct in all cases where system time-zone is the same as the time-zone configured in openHAB. When they are different and a state is provided using the correct time-zone from |
8a820be
to
7df4b06
Compare
@wborn - can you help me by removing the "work in progress" label to signal this is now ready for the review process? 🙂 |
@@ -51,6 +56,10 @@ public class EnrichedItemDTOMapper { | |||
|
|||
private static final Pattern EXTRACT_TRANSFORM_FUNCTION_PATTERN = Pattern.compile("(.*?)\\((.*)\\):(.*)"); | |||
|
|||
private static final String DATE_FORMAT_PATTERN_WITH_TZ_RFC = "yyyy-MM-dd'T'HH:mm[:ss[.SSSSSSSSS]]Z"; | |||
private static final DateTimeFormatter FORMATTER_TZ_RFC = DateTimeFormatter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this pattern identical to DateTimeFormatter.ISO_OFFSET_DATE_TIME? In any case the .SSSSSSSSS is incorrect, should be .nnnnnnnnn in my mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to admit this was duplicated from DateTimeType
itself, thinking I would later remove it there - which didn't happen. I'll see if it can be refactored while maintaining backwards compatiblity, and also get rid of the duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In DateTimeType
I have now exposed a method overload of toFullString
taking a ZoneId
- and added full test coverage for this. As a consequence, this duplicated method and DateTimeFormatter
was removed.
For now, I have left the method and DateTimeFormatter
as it was before this PR, but we now have test coverage to make sure refactoring will not break the backwards compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems DateTimeFormatter.ISO_OFFSET_DATE_TIME
does not provide the same output:
[ERROR] Failures:
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T10:58:47.033+0000> but was: <2014-03-30T10:58:47.033Z>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T12:58:47.033+0200> but was: <2014-03-30T12:58:47.033+02:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T12:58:47.033+0200> but was: <2014-03-30T12:58:47.033+02:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T05:58:47.033-0200> but was: <2014-03-30T05:58:47.033-02:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T12:58:47.033-0200> but was: <2014-03-30T12:58:47.033-02:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <1970-01-01T10:58:47.000+0000> but was: <1970-01-01T10:58:47Z>
[ERROR] DateTimeTypeTest.createDate:360 expected: <1970-01-01T10:58:00.000+0000> but was: <1970-01-01T10:58:00Z>
[ERROR] DateTimeTypeTest.createDate:360 expected: <1970-01-01T10:58:47.000+0100> but was: <1970-01-01T10:58:47+01:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <1970-01-01T10:58:00.000+0100> but was: <1970-01-01T10:58:00+01:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T00:00:00.000+0000> but was: <2014-03-30T00:00:00Z>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T10:58:47.033+0000> but was: <2014-03-30T10:58:47.033Z>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T08:58:47.033+0000> but was: <2014-03-30T08:58:47.033Z>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T10:58:47.230+0000> but was: <2014-03-30T10:58:47.23Z>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T10:58:47.000+0000> but was: <2014-03-30T10:58:47Z>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T12:58:47.033+0200> but was: <2014-03-30T12:58:47.033+02:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T10:58:47.033+0200> but was: <2014-03-30T10:58:47.033+02:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T10:58:47.000+0200> but was: <2014-03-30T10:58:47+02:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T15:58:47.000+0500> but was: <2014-03-30T15:58:47+05:00>
[ERROR] DateTimeTypeTest.createDate:360 expected: <2014-03-30T10:58:47.000+0200> but was: <2014-03-30T10:58:47+02:00>
[ERROR] DateTimeTypeTest.toFullStringWithZone:412
Expected: is "2024-11-11T20:39:00.000+0000"
but: was "2024-11-11T20:39:00Z"
[ERROR] DateTimeTypeTest.toFullStringWithZone:412
Expected: is "2024-11-11T20:39:00.000+0000"
but: was "2024-11-11T20:39:00Z"
[ERROR] DateTimeTypeTest.toFullStringWithZone:412
Expected: is "2024-11-11T20:39:00.000000001+0000"
but: was "2024-11-11T20:39:00.000000001Z"
[ERROR] DateTimeTypeTest.toFullStringWithZone:412
Expected: is "2024-11-11T20:39:00.123+0000"
but: was "2024-11-11T20:39:00.123Z"
[ERROR] DateTimeTypeTest.toFullStringWithZone:412
Expected: is "2024-11-11T20:39:00.123456+0000"
but: was "2024-11-11T20:39:00.123456Z"
[ERROR] DateTimeTypeTest.toFullStringWithZone:412
Expected: is "2024-11-11T20:39:00.123456789+0000"
but: was "2024-11-11T20:39:00.123456789Z"
[ERROR] DateTimeTypeTest.toFullStringWithZone:412
Expected: is "2024-11-11T21:39:00.123+0100"
but: was "2024-11-11T21:39:00.123+01:00"
[ERROR] DateTimeTypeTest.toFullStringWithZone:412
Expected: is "2024-11-10T23:59:59.999-0500"
but: was "2024-11-10T23:59:59.999-05:00"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parser test does accept the format above as valid input, so why should this be invalid output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With da2b50a this duplicated method was removed, so what is left is the original implementation of toString()
/toFullString()
. This is unchanged by this PR to remain backwards compatible. The DateTimeType
String constructor supports many different inputs, but toFullString()
can only provide one specific output. Other outputs are supported by the format
methods.
if (!sign.isEmpty()) { | ||
// the formatted string contains 9 fraction-of-second digits | ||
// truncate at most 2 trailing groups of 000s | ||
return formatted.replace("000" + sign, sign).replace("000" + sign, sign); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the formater mentioned above this should not be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #3583 (comment)
Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Jacob Laursen <[email protected]>
9ec455c
to
da2b50a
Compare
Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Jacob Laursen <[email protected]>
This was not the case. I finally figured it out and fixed this inconsistent behavior, so that configured time-zone rather than system time-zone is now used for SSE item events and sitemaps as well. |
Related to openhab/openhab-core#3583 Signed-off-by: Jacob Laursen <[email protected]>
Related to openhab/openhab-core#3583 Signed-off-by: Jacob Laursen <[email protected]>
d691ee3
to
be50c88
Compare
Signed-off-by: Jacob Laursen <[email protected]>
be50c88
to
82466b3
Compare
I have now checked all bindings by recompiling main against changes of this PR and fixed those tests having that assumption: openhab/openhab-addons#17764. |
@jlaur I looked at the code, and there is nothing I can add to this. I agree this will simplify addon development and make things more consistent. From my perspective LGTM. |
@openhab/core-maintainers - WDYT? |
Proposal for switching
DateTimeType
to useInstant
internally rather thanZonedDateTime
.This will effectively discard time-zone information from the source of the
DateTimeType
and leave it to consumers to apply time-zone at the moment of presentation, according to the configured time-zone in openHAB regional settings or in the browser.Configured time-zone is now applied for:
Consequential changes because
DateTimeType
is now "zone-less":timezone
forTimestampOffsetProfile
has been removed. Remove time-zone parameter from profiletimestamp-offset
openhab-docs#2403 has been prepared.toZone
andtoLocaleZone
have been marked as deprecated and all usages have been refactored. I would suggest to remove them in 5.0 (or maybe even before when all bindings are refactored, see SimplifyDateTimeType
handling openhab-addons#17725).getZonedDateTime
have been refactored.The following demonstrates the difference between old and new behavior.
REST API calls are for
http://localhost:8080/rest/items/DateTimeTest
and the returnedstate
is shown in the comparison table:Updates are made in Karaf using commands like:
As it can be seen from the table, we now have consistent results.
Example DSL rule:
Previous result with system time-zone CET/DST:
New result with same system time-zone:
Summary of benefits for developers:
TimeZoneProvider
is used only to generate aDateTimeType
with the correct time-zone, this can now be completely removed. This simplifies the code. See SimplifyDateTimeType
handling openhab-addons#17725 for examples.DateTimeType
constructor can now be used (without losing correct time-zone).toZone
andtoLocaleZone
. I will go through usages and remove them, since they no longer make sense. See SimplifyDateTimeType
handling openhab-addons#17725.DateTimeType
usingTimeZoneProvider
.And for users:
DateTimeType
(which could be either depending on binding) and other parts used system time-zone.And finally limitations:
DateTimeType
command to a binding with a specified time-zone. The bindings will have to provide a time-zone if needed (e.g. time-zone from device, openHAB configuration or system time-zone). I have not found any bindings using this possibility, so I don't think this will cause any issues.Resolves #2898