3

I am trying to subtract 10 minutes from the current time, but I cant find the proper syntax in the documentation I have looked up

I have this so far

def deltaMinutes = 10
use(TimeCategory) {
    def nowTime = new Date() - deltaMinutes.minutes
    log.debug nowTime
}

and get this in the SmartThings IDE

java.lang.NullPointerException @ line 53

Perhaps the IDE doesnt support this library? What would be the next best method for calculating this?

Jeff Beck
  • 3,944
  • 3
  • 28
  • 45
Brian
  • 622
  • 10
  • 29
  • 2
    `deltaMinutes` is a number... I don't think it has a `minutes` property. – Andrew Jul 30 '14 at 21:05
  • gotcha. so I need to convert `deltaMinutes` to a time variable somehow – Brian Jul 30 '14 at 21:17
  • 2
    No, you don't, that should work fine. Are you sure that's where the NullPointerException is happening? Is it possible that `log` is actually null? When I copy and paste that into a groovyConsole and `println nowTime` it works just fine. – grantmcconnaughey Jul 30 '14 at 21:18
  • I have a feeling its the SmartThings IDE that I am using. Its based on groovy, but not sure it supports all of the libraries. Is there a better way to do this with a core library? – Brian Jul 30 '14 at 21:26
  • The `TimeCategory` class should come with Groovy. What exactly is on line 53? It says line 53 is the error but there is no way to tell which line that is from what you've posted. – grantmcconnaughey Jul 30 '14 at 22:30

1 Answers1

6

10.minutes.ago should give what you are looking for

use( groovy.time.TimeCategory ) {
    println 10.minutes.ago
}
dmahapatro
  • 49,365
  • 7
  • 88
  • 117