date - Groovy TimeDuration Argument Types -
i'm quite new groovy (and haven't experience java) - i'm running problem doesn't make sense me. guess misunderstanding of how objects , classes work in these languages. question basic - appreciated.
i'm trying calculate number of weeks between 2 dates. code (it more succinct, i've expanded make each step more clear):
import groovy.time.timecategory start = new date(year: 2014, month: calendar.april, date: 1, hours: 12, minutes: 12, seconds: 0) finish = new date(year: 2014, month: calendar.may, date: 4, hours: 1, minutes: 12, seconds: 0) use ( timecategory ) { diff = finish - start println getweeks(diff) }
i error
groovy.lang.missingmethodexception: no signature of method: script1.getweeks() applicable argument types: (groovy.time.timeduration) values: [32 days, 13 hours]
however, if change print line println diff.getclass().name
my results output
groovy.time.timeduration
so question essentially: if diff
object of class groovy.time.timeduration
, getweeks requires arguments of class, why error?
you should using:
use ( timecategory ) { diff = finish - start println diff.weeks }
what see in groovy doc static duration getweeks(integer self)
how groovy system calls methods.
almost such static groovy methods have form: static dosmth( self, otherargs... )
, have call self.dosmth( otherargs... )
Comments
Post a Comment