Hello,
I need your help because I’m disastrous with java.
I need to convert the openhab 2 instruction now.getWeekOfWeekyear
which return the number of the week (business speaking is very used to comunicate delivery estimation etc…) to OH3.
Hello,
I had already try to copy-paste the istruction on these page. I’m not able to understand Java, so i’m not able to manage eventual little adaptation.
I try inside a script these without success:
ZoneId zoneId = ZoneId.of ( "America/Montreal" );
ZonedDateTime now = ZonedDateTime.now ( zoneId );
int week = now.get ( IsoFields.WEEK_OF_WEEK_BASED_YEAR );
int weekYear = now.get ( IsoFields.WEEK_BASED_YEAR );
test.postUpdate(weekYear)
Or
ZoneId zoneId = ZoneId.of ( "America/Montreal" );
ZonedDateTime now = ZonedDateTime.now ( zoneId );
int week = now.get ( WEEK_OF_WEEK_BASED_YEAR );
int weekYear = now.get ( WEEK_BASED_YEAR );
test.postUpdate(weekYear)
logs gives
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘test’ failed: var weekYear = now.get( ___ WEEK_BASED_YEAR)
I Think this is the implementation based on the stackoverflow example:
import java.time.temporal.IsoFields
rule "Test"
when
Item swTestSwitch changed from OFF to ON
then
val int week = now.get ( IsoFields.WEEK_OF_WEEK_BASED_YEAR )
val int weekYear = now.get ( IsoFields.WEEK_BASED_YEAR )
logInfo("Test", "Now = " + now.toString)
logInfo("Test", "Week = " + week.toString)
logInfo("Test", "WeekYear = " + weekYear.toString)
end
For your own Timezone it should be so ok. Hope it’s helpful.