-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
[time] Time Utils #101
[time] Time Utils #101
Conversation
Signed-off-by: Richard Koshak <rlkoshak@gmail.com>
Signed-off-by: Richard Koshak <rlkoshak@gmail.com>
Signed-off-by: Richard Koshak <rlkoshak@gmail.com>
Second attempt at this capability. I believe I've addressed all the comments from the previous PR and probably introduced all sorts of new ones since it's pretty much a complete rewrite. I removed some functions as they probably are not that useful overall (toYesterday, toTomorrow) and which I no longer needed because I used a different implementation for betweenTimes. I added a new monkey patched |
I didn't say it which was a mistake. This is ready for review. |
README.md
Outdated
Argumen Type | Rule | Examples | ||
-|-|- | ||
`null` or `undefined` | `time.ZonedDateTime.now()` | `time.toZDT();` | ||
`time.ZonedDateTime` | passed through unmodified | | ||
`java.time.ZonedDateTime` | converted to the `time.ZonedDateTime` equivalent | ||
JavaScript native `Date` | converted to the equivalent `time.ZonedDateTime` using `SYSTEM` as the timezone | ||
`number`, `bingint`, `java.lang.Number`, `DecimalType` | rounded to the nearest integer and added to `now` as milliseconds | `time.toZDT(1000);` | ||
`QuantityType` | if the units are `Time`, that time is added to `now` | `time.toZDT(item.getItem('MyTimeItem').rawState);` | ||
`items.Item` or `org.openhab.core.types.Item` | if the state is supported (see the `Type` rules in this table, e.g. `DecimalType`), the state is converted | `time.toZDT(items.getItem('MyItem'));` | ||
`String`, `java.lang.String`, `StringType` | parsed based on the following rules | | ||
RFC String (output from a Java `ZonedDateTime.toString()`) | parsed | `time.toZDT(new DateTimeType().getZonedDateTime().toString());` | ||
`"HH:MM[:ss]"` (24 hour time) | today's date with the time indicated, seconds is optional | `time.toZDT('13:45:12');` | ||
`"kk:mm[:ss][ ]a"` (12 hour time) | today's date with the time indicated, the space between the time and am/pm and seconds are optional | `time.toZDT('1:23:45 PM');` | ||
Duration String | any duration string supported by `time.Duration` added to `now()`, see [the docs](https://js-joda.github.io/js-joda/class/packages/core/src/Duration.js~Duration.html#static-method-parse) for details | `time.toZDT('PT1H4M6.789S');` |
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.
Argumen Type | Rule | Examples | |
-|-|- | |
`null` or `undefined` | `time.ZonedDateTime.now()` | `time.toZDT();` | |
`time.ZonedDateTime` | passed through unmodified | | |
`java.time.ZonedDateTime` | converted to the `time.ZonedDateTime` equivalent | |
JavaScript native `Date` | converted to the equivalent `time.ZonedDateTime` using `SYSTEM` as the timezone | |
`number`, `bingint`, `java.lang.Number`, `DecimalType` | rounded to the nearest integer and added to `now` as milliseconds | `time.toZDT(1000);` | |
`QuantityType` | if the units are `Time`, that time is added to `now` | `time.toZDT(item.getItem('MyTimeItem').rawState);` | |
`items.Item` or `org.openhab.core.types.Item` | if the state is supported (see the `Type` rules in this table, e.g. `DecimalType`), the state is converted | `time.toZDT(items.getItem('MyItem'));` | |
`String`, `java.lang.String`, `StringType` | parsed based on the following rules | | |
RFC String (output from a Java `ZonedDateTime.toString()`) | parsed | `time.toZDT(new DateTimeType().getZonedDateTime().toString());` | |
`"HH:MM[:ss]"` (24 hour time) | today's date with the time indicated, seconds is optional | `time.toZDT('13:45:12');` | |
`"kk:mm[:ss][ ]a"` (12 hour time) | today's date with the time indicated, the space between the time and am/pm and seconds are optional | `time.toZDT('1:23:45 PM');` | |
Duration String | any duration string supported by `time.Duration` added to `now()`, see [the docs](https://js-joda.github.io/js-joda/class/packages/core/src/Duration.js~Duration.html#static-method-parse) for details | `time.toZDT('PT1H4M6.789S');` | |
| Argument Type | Rule | Examples | | |
|------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------| | |
| `null` or `undefined` | `time.ZonedDateTime.now()` | `time.toZDT();` | | |
| `time.ZonedDateTime` | passed through unmodified | | | |
| `java.time.ZonedDateTime` | converted to the `time.ZonedDateTime` equivalent | | | |
| JavaScript native `Date` | converted to the equivalent `time.ZonedDateTime` using `SYSTEM` as the timezone | | | |
| `number`, `bingint`, `java.lang.Number`, `DecimalType` | rounded to the nearest integer and added to `now` as milliseconds | `time.toZDT(1000);` | | |
| `QuantityType` | if the units are `Time`, that time is added to `now` | `time.toZDT(item.getItem('MyTimeItem').rawState);` | | |
| `items.Item` or `org.openhab.core.types.Item` | if the state is supported (see the `Type` rules in this table, e.g. `DecimalType`), the state is converted | `time.toZDT(items.getItem('MyItem'));` | | |
| `String`, `java.lang.String`, `StringType` | parsed based on the following rules | | | |
| RFC String (output from a Java `ZonedDateTime.toString()`) | parsed | `time.toZDT(new DateTimeType().getZonedDateTime().toString());` | | |
| `"HH:MM[:ss]"` (24 hour time) | today's date with the time indicated, seconds is optional | `time.toZDT('13:45:12');` | | |
| `"kk:mm[:ss][ ]a"` (12 hour time) | today's date with the time indicated, the space between the time and am/pm and seconds are optional | `time.toZDT('1:23:45 PM');` | | |
| Duration String | any duration string supported by `time.Duration` added to `now()`, see [the docs](https://js-joda.github.io/js-joda/class/packages/core/src/Duration.js~Duration.html#static-method-parse) for details | `time.toZDT('PT1H4M6.789S');` | | |
FYI , I use http://markdowntable.com to format tables like this
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'll fix it. Thanks for the link to markdowntable.com. That's a great resource!
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.
Done
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.
Thanks @rkoshak ! See comments.
* @returns time.ZonedDateTime | ||
* @throws error if the type, format, or contents of when are not supported | ||
*/ | ||
time.toZDT = function(when) { |
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.
This would be a really easy and awesome method to have some tests around, so pass in each of the listed dates in the comment and verify you get the right zdt time back.
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.
lol, i just re-read your original post and saw you had a lot of testing! Can you add those tests to this library ? There is a test directory with some tests around the rule builder, but should provide a good template for adding the testing logic you have already written for the time classes
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's not clear to me how tests are handled in the library. I've just got my tests as a Script in MainUI and I use a couple of functions from my openhab-rules-tools library to do 'assert` and such. I'll look more into how the rule builder tests work and see if I can figure out how to convert to that format.
I always write tests as I go. ;-) I'm more than happy to get them checked in to the repo. (As an aside I've tests for toggle too which I'll see if I can get added to that PR).
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.
Still trying to figure out how to make Mocha work. I've installed the libraries as global but they are not showing up. In short I've not even managed to run the tests that are already there. I'm still muddling through but I've held this PR up long enough already. Maybe it's worth coming back later with a new PR.
time.js
Outdated
} | ||
|
||
// Pass through if already a time.ZonedDateTime | ||
else if(when instanceof time.ZonedDateTime) { |
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.
else if(when instanceof time.ZonedDateTime) { | |
if(when instanceof time.ZonedDateTime) { |
since each of these if
statements return if matched, there no need for else
in any of them
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 wasn't sure. I've used StandardJS as a style guide but it seemed to be silent on this topic. I don't have an opinion either way so have no problem removing the unnecessary else statements.
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.
Done
time.js
Outdated
} | ||
|
||
/** | ||
* Tests to see if the difference betwee this and the passed in ZoneDateTime is |
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.
* Tests to see if the difference betwee this and the passed in ZoneDateTime is | |
* Tests to see if the difference between this and the passed in ZoneDateTime is |
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.
Done
time.js
Outdated
/** | ||
* Tests to see if the difference betwee this and the passed in ZoneDateTime is | ||
* within the passed in maxDur. | ||
* @param {time.ZonedDateTime} zdt the date tiem to compare to this |
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.
* @param {time.ZonedDateTime} zdt the date tiem to compare to this | |
* @param {time.ZonedDateTime} zdt the date time to compare to this |
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.
Done
time.js
Outdated
time.ZonedDateTime.prototype.millisFromNow = function () { | ||
return time.Duration.between(time.ZonedDateTime.now(), this).toMillis(); | ||
}; | ||
time.ZonedDateTime.prototype.betweenTimes = function(start, end) { |
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.
time.ZonedDateTime.prototype.betweenTimes = function(start, end) { | |
time.ZonedDateTime.prototype.isBetweenTimes = function(start, end) { |
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.
Done
* @param {time.Duration} maxDur the duration to test that the difference between this and zdt is within | ||
* @returns {Boolean} true if the delta between this and zdt is within maxDur | ||
*/ | ||
time.ZonedDateTime.prototype.isClose = function(zdt, maxDur) { |
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'm struggling with this method a bit, it seems pretty hard to explain (maybe is needs a better name and better named parameters?) , and also seems very niche in its use case. I'm wondering how frequently something like this will be used by others? I think we should strive to only add in whats really going to be useful to a broader audience, otherwise our library will start to seem inconsistent and unfocused.
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've seen a number of users struggle with the fact that you'll probably never end up with two timestamps that are actually equal. They are surprised that something like time.ZonedDateTime.now() == time.ZonedDateTime.now()
will be false. This was. an attempt to give them a function I could point them to to help them make such similar comparisons as well as kind of explain what's going on.
It's also handy in cases where you want to see how far apart two time stamps are (for example, if a motion detector triggered within five minutes of a light switch flipping).
I use the heck out of this function in the tests and originally it was only in my test code. But I ran into a few use cases where it seemed useful in general. I can definitely move it to the tests, though will probably also reimplement it in my openhab-rules-tools since I've already two rules I've identified that can benefit from it.
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 haven't removed this function. I personally find it useful. But if you feel strongly about it I will remove it.
time.js
Outdated
} | ||
|
||
// ISO8601 | ||
else if(isISO8601(str)) { |
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.
else if(isISO8601(str)) { | |
if(isISO8601(str)) { |
since each of these if statements return if matched, there no need for else in any of them
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.
Done
Signed-off-by: Richard Koshak <rlkoshak@gmail.com>
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.
Overall looks really good, please have a look at my comments.
I have not tested the changes, but if @digitaldan wants me to do so, I can do.
Anywhere that a native Java `ZonedDateTime` or `Duration` is required, the runtime will automatically convert a JS-Joda `ZonedDateTime` or `Duration` to its Java counterpart. | ||
|
||
#### openHAB-JS extensions to JS-Joda |
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.
Maybe we can keep that overview of our additions/changes to JSJoda and you can add your changes from this PR here?
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 don't have a problem with that except much of what I've implemented is outside of JS-Joda and not extensions to it. So that heading as written is incorrect, or at least there would need to be two sections, one for the additions to JS-Joda and another one for toZDT().
But my branch doesn't have the millisFromNow. I suspect that was added after I opened this PR. I removed that heading because all that was under it was "Examples:" on down. There wasn't anything there to preserve and the bulk of the content was no longer references to JS-Joda.
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.
Okay, leave it as it is.
I will have a look what happens when this gets merged. If millisFromNow
is removed, I will add it back.
Examples: | ||
```javascript | ||
var now = time.ZonedDateTime.now(); | ||
var yesterday = time.ZonedDateTime.now().minusHours(24); | ||
var millis = now.plusSeconds(5).millisFromNow(); |
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.
Please do not remove this!
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 didn't. It was never there in the first place. See below, it wasn't supposed to be there and I accidentally pulled it in when I erroneously rebaselined my branch and was asked to back those out (see above).
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.
Okay, leave it as it is.
|
||
var item = items.getItem("Kitchen"); | ||
console.log("averageSince", item.history.averageSince(yesterday)); | ||
console.log("5 seconds in the future is " + millis + " milliseconds."); |
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.
Please do not remove!
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 didn't, it wasn't supposed to be there in the first place. I didn't remove anything from the README except that heading. Everything else was an addition. Though I had inadvertently rebaselined my branch and those were probably pulled in when I made that mistake. Dan asked me to back those out.
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.
Okay, leave it as it is.
README.md
Outdated
Examples: | ||
|
||
```javascript | ||
time.toZDT().beteenTimes('22:00', '05:00') // currently between 11:00 pm and 5:00 am |
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.
time.toZDT().beteenTimes('22:00', '05:00') // currently between 11:00 pm and 5:00 am | |
time.toZDT().betweenTimes('22:00', '05:00') // currently between 11:00 pm and 5:00 am |
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.
Fixed in the next commit.
README.md
Outdated
```javascript | ||
time.toZDT().beteenTimes('22:00', '05:00') // currently between 11:00 pm and 5:00 am | ||
time.toZDT().betweenTimes(items.getItem('Sunset'), '11:30 PM') // is now between sunset and 11:30 PM? | ||
time.toZDT(items.getItem('StartTime')).bewteenTimes(time.toZDT(), 'PT1H'); // is the state of StartTime between now and one hour from now |
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.
time.toZDT(items.getItem('StartTime')).bewteenTimes(time.toZDT(), 'PT1H'); // is the state of StartTime between now and one hour from now | |
time.toZDT(items.getItem('StartTime')).betweenTimes(time.toZDT(), 'PT1H'); // is the state of StartTime between now and one hour from now |
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.
Fixed in the next commit
* | ||
* @memberof time | ||
* @returns {number} duration from now to the ZonedDateTime in milliseconds | ||
* Moves the date portion of the date time to today, accounting for DST |
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.
We need the @memberof time
tag for JSDoc here.
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.
This is a monkey patch of ZonedDateTime. If it's a member of anything it's a member of time.ZonedDateTime
, not time
. This @memberof time
tag makes absolutely no sense to me.
Change made in next commit.
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 above, you can remove @memberof time
.
time.js
Outdated
* | ||
* time.ZonedDateTime.now().betweenTimes(items.getItem('Sunset'), "23:30:00") // is now between sunset and 11:00 pm? | ||
* time.toZDT(items.geItem('MyDateTimeItem')).betweenTimes(time.toZDT(), time.toZDT(1000)) // is the state of MyDateTimeItem between now and a second from now? | ||
* |
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.
We need @memberof time
.
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.
Change made in next commit.
time.js
Outdated
* @returns {Boolean} true if this is between start and end | ||
*/ | ||
time.ZonedDateTime.prototype.isBetweenTimes = function(start, end) { | ||
startTime = time.toZDT(start).toLocalTime(); |
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.
startTime = time.toZDT(start).toLocalTime(); | |
const startTime = time.toZDT(start).toLocalTime(); |
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.
Fixed in next commit.
time.js
Outdated
*/ | ||
time.ZonedDateTime.prototype.isBetweenTimes = function(start, end) { | ||
startTime = time.toZDT(start).toLocalTime(); | ||
endTime = time.toZDT(end).toLocalTime(); |
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.
endTime = time.toZDT(end).toLocalTime(); | |
const endTime = time.toZDT(end).toLocalTime(); |
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.
Fixed in next commit
time.js
Outdated
time.ZonedDateTime.prototype.isBetweenTimes = function(start, end) { | ||
startTime = time.toZDT(start).toLocalTime(); | ||
endTime = time.toZDT(end).toLocalTime(); | ||
currTime = this.toLocalTime(); |
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.
currTime = this.toLocalTime(); | |
const currTime = this.toLocalTime(); |
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.
fixed in next commit
Signed-off-by: Richard Koshak <rlkoshak@gmail.com>
The requested changes have been made except for adding back in stuff that shouldn't have been in this PR in the first place. |
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.
Looks good to me, thank you very much.
I am sorry for the wrong @memberof time
tags, you can remove them if you wish to, except for toZDT
, toToday
, isBetweenTimes,
isClose
. Right??
* Adds millis to the passed in ZDT as milliseconds. The millis is rounded | ||
* first. If millis is negative they will be subtracted. | ||
* @param {number|bigint} millis number of milliseconds to add | ||
*/ |
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.
Oh sorry, I just checked, it is not exported.
You are totally right, @memberof time
makes no sense here. I am not sure why I wrote that yesterday, must have been a misthought.
/** | ||
* Converts the passed in when to a time.ZonedDateTime based on the following | ||
* set of rules. | ||
* |
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.
You are right, it only needs @private
but does not need @memberof time
.
*/ | ||
time.ZonedDateTime.prototype.millisFromNow = function () { |
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.
Okay, then leave it as it is.
* | ||
* @memberof time | ||
* @returns {number} duration from now to the ZonedDateTime in milliseconds | ||
* Moves the date portion of the date time to today, accounting for DST |
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 above, you can remove @memberof time
.
Signed-off-by: Richard Koshak <rlkoshak@gmail.com>
I'm still confused about why it's |
Yes, that would make more sense, but I do not know if that works with the JSDoc htmls generated. You can give it a try and run |
Interestingly, neither |
I would‘t remove them as they are at least helpful when scrolling through the source code, but yes, the README seems to be the only place where the monkey-patched functions can be documented (outside the source code). |
In that case I'd say let's just leave them as is and consider this PR good to go. |
Some conflicts popped up from an earlier PR that was merged, can you fix those? Thanks! |
Fixing the conflict was easy for README.MD but it's marking everything I've added to time.js as a conflict. How to I fix this without basically reversing everything I've added? I don't have write access so I can't tell it to use my version instead of main. I'm not sure what to do. |
Your PR is all that needs to be changed. Fetch the |
I went ahead and fixed the conflicts , so all is merged now. |
Thanks! I thought I wasn't supposed to fetch from main because last time I did that in the toggle PR I ended up with someone else's PR mixed in and it appears to have caused all sorts of problems. Sometimes I miss the simplicity of good old CVS. I feel like a bull in a china shop every time I mess with a PR on Github. The good news is I think I've figured out Mocha so I'll be able to add some unit tests in a separate PR when I can implement them. I'll look into what it would take to create tests for as much in the library as we can. |
[time] Time Utils
Description
Implements a number of utilities for working with date times.
time.toZDT()
: converts almost anything that can reasonably be converted to a date time to a ZonedDateTime. See the docs for the rules used when converting (e.g. a number is added to now as milliseconds, '1:23 PM' returns a date time with today's date and 13:23:00 for the time, etc.).zdt.toToday()
: returns a newtime.ZonedDateTime
withzdt
's time and today's date, accounting for DST changes.zdt.betweenTimes(start, end)
: returnstrue
ifzdt
's time is between the times (ignoring date) represented bystart
andend
. If theend
time is beforestart
, the time range is assumed to span midnight.start
andend
can be anything supported bytime.toZDT()
, for examplenow.betweenTimes(items.getItem('Sunset'), '05:00');
.zdt.isClose(otherZDT, maxDuration)
: returns true if the difference betweenzdt
andotherZDT
is withinmaxDuration
.Testing
I used the following in a MainUI Script to test this library .
The functions used from
testUtils
are:These are a part of openhab_rules_tools.