DateTime type problem?

Hi there,

I need your help - I want to parse use a timestamp which is the state of a String Item (my next alarm) as a timer.
However, I constantly struggle with types and I don’t understand why it doesn’t work:

Results in:
2017-02-09 08:47:30.714 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'set alarm': An error occured during the script execution: Could not invoke method: org.joda.time.base.AbstractDateTime.toString() on instance: Fri Feb 10 08:27:00 CET 2017

The time seems to be parsed correctly - can anyone tell me what I’m doing wrong?

Aren’t you trying .toString on something already a string?

No, this is needed apparently as openhab cannot infer the type.

As you can see in the error it also worked: Fri Feb 10 08:27:00 CET 2017
is the parsed input - input was “2017-02-10 8:27”

@Christoph_B I don’t think you need sdf. Can you try this:

rule "set alarm"
  when Item alarmtime received update
then

if(alarmtime.state != null) {
  var DateTime mydate = parse(alarmtime.state.toString)
  logInfo("test", mydate.toString)
  if(timer == null) {
...

I need the initial format to define how the incoming string looks like.

I created a workaround:

  1. parse timestamp in custom format using formatter
  2. output in ISO using iso formatter
  3. parse again with .parse

So it seems to me that formatter.parse() returns something different than .parse()
Can anyone explain this?