jirom
(jirom)
1
Hi, I’m trying to use Joda Time’s PeriodFormatterBuilder in a rule but it keeps giving me an error as soon as I try to instantiate one.
val periodFormatterBuilder = new org.joda.time.format.PeriodFormatterBuilder()
The logs just simply indicate
Rule ‘When dog was last fed’: An error occurred during the script execution: null
I thought maybe the class was not available or someting so I’ve tried installing Joda from maven using
bundle:install
bundle:start
but I still get the same error. Is there any way to get more details around why it’s failing?
rossko57
(Rossko57)
2
Have you actually pinned down the error to that particular line?
5iver
(Scott Rushworth)
3
This works in scripted automation using Jython…
from core.log import logging, LOG_PREFIX#, log_traceback
from org.joda.time.format import PeriodFormatterBuilder
from org.joda.time import Period
LOG = logging.getLogger("{}.TEST".format(LOG_PREFIX))
years_and_months = (PeriodFormatterBuilder()
.printZeroAlways()
.appendYears()
.appendSuffix(" year", " years")
.appendSeparator(" and ")
.printZeroRarelyLast()
.appendMonths()
.appendSuffix(" month", " months")
.toFormatter())
period_string = years_and_months.print(Period(5, 5, 5, 5, 5, 5, 5, 0))
LOG.warn(period_string)
It logs…
2019-12-22 11:08:35.865 [WARN ] [jsr223.jython.TEST] - 5 years and 5 months
jirom
(jirom)
4
Yes, I logged messages before and after this line.