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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -