Week OF Year

Dear all,

I tried to identify the current week of the year but I don’t understand why it doesn’t work.

import java.util.Calendar

rule "Testregel"
   when
		Item PRA_tst changed
   then
		var Calendar cal = Calendar::instance
		var int test = cal.getWeekYear()
		logWarn("Test","Woche" + test)
end

This returns “Woche2017”

If I check the reference it should work: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html

Thanks
chr1s

According to


The result you get is correct.

I guess you need

var int test = cal.get(WEEK_OF_YEAR)

to get the result you wanted.

thanks :slight_smile:

working code

import java.util.Calendar

rule "Testregel"
   when
		Item PRA_tst changed
   then
		var Calendar cal = Calendar.getInstance()
		var int test = cal.get(Calendar.WEEK_OF_YEAR)
		logWarn("Test","Woche " + test)
end

This can also be accomplished with org.joda.time.DateTime

import org.joda.time.DateTime

rule "Testregel"
when
    Item PRA_tst changed
then
    val Integer test = now.getWeekOfWeekyear
    logWarn("Test","Woche=[{}]",test)
end

seems to be the better solution and even the import … is not needed

Correct… if one is using 2.x :smiley:

1 Like