I never knew about withTime. That can eliminate a lot of the withTimeAtStartOfDay.plusHours stuff. Iām surprised there isnāt a with date that works the same.
Thought I brought it up in a DST conversation in the ToD DP thread as an alternative to withTimeAtStartOfDay, since it is DST safe. Sorry for being OT, but this is very handy with Intervalsā¦
import org.joda.time.Interval
import org.joda.time.Days
if (new Interval(now.withTime(9,0,0,0), now.withTime(17,0,0,0)).contains(now)) {
// do stuff between 9am and 5pm
Another use of Interval with a DateTime Itemā¦
if (new Interval(Days.days(7), new DateTime(Sun_Eclipse_Total.toString)).contains(now)) {
// do eclipse stuff
I want to get the time into a datetime item, so it would be #1 i think? No variable with joda-datetime.
But my given string is in the format ā2018-10-25 11:00ā. So there is no āTā and no ā+02:00ā inside itā¦ So how can i change this given string-item into a datetime-item?
Looks like it will be affected. Thank you for that information.
I would not update this threat until the new version 2.4 is released.
What do you think?
Because the breakage is bigger than expected there is discussion of going back to joda for the time being or figuring out a way to get those missing methods back. Watch the pr thread for details. I wouldnāt do anything until that gets resolved.
I have searched and searched, but need some help. Maybe somebody ( @rlkoshak? ) knows the trick I need or what Iām doing wrongā¦
Trying to instantiate a DateTime with the epoch milliseconds not from calendar or now.millis but from a number item (set by Android HAAS app). I am multiplying by 1000 to get milliseconds first and storing result as a Number. When I try to use DateTime constructor though I get an Error. I have tried to explicitly set the āalarmTimeā variable as a long and other things, but nothing seems to work. Here is the relevant code:
val Number milliseconds = (Bedside_Light_Alarm_DateTime.state as Number) * 1000
logInfo("Debugging DateTime crap...", "The milliseconds is: " + milliseconds)
val DateTime alarmTime = new DateTime(milliseconds)
logInfo("Debugging DateTime crap...", "The alarmTime Calender/DateTime is: " + alarmTime.toString)
2019-01-14 10:26:38.786 [INFO ] [el.script.Debugging DateTime crap...] - The milliseconds is: 1547506800000
2019-01-14 10:26:38.789 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Bedroom Light Alarm Updated': No instant converter found for type: java.math.BigDecimal
Number AlarmClock
DateTime Alarmzeit "Alarmzeit [%1$tH:%1$tM]"
This ruleā¦
rule "Alarmzeit"
when
Item AlarmClock changed
then
val DateTimeType MyDateTimeTypeFromEpoch = new DateTimeType(new DateTime(AlarmClock).toString)
logInfo("Algemein.rules",MyDateTimeTypeFromEpoch.toString)
end
causes this errorā¦
2019-05-01 19:47:28.139 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Alarmzeit': No instant converter found for type: org.eclipse.smarthome.core.library.items.NumberItem
What is wrong in my converting? Maybe someone can help.
rule "Alarmzeit"
when
Item AlarmClock changed
then
val DateTimeType MyDateTimeTypeFromEpoch = new DateTime(AlarmClock.state.toString)
logInfo("Algemein.rules",MyDateTimeTypeFromEpoch.toString)
end
Now there is a differnt error:
2019-05-01 22:03:56.828 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Alarmzeit': Invalid format: "1556769600000" is malformed at "0000"
Sorry Rich,
still not working. How hard could it be to convert a ordinary number.
rule "Alarmzeit"
when
Item AlarmClock changed
then
val DateTimeType MyDateTimeTypeFromEpoch = new DateTime((AlarmClock.state as Number).longValue)
logInfo("Algemein.rules",MyDateTimeTypeFromEpoch.toString)
end
2019-05-04 14:10:14.611 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Alarmzeit': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.core.library.types.DateTimeType.toString() on instance: 2019-05-04T14:20:17.795+02:00
DateTime and DateTimeType are not the same thing. Youāve declared the available to be DateTimeType but you are creating a DateTime to store in the variable.