Ignore:
Timestamp:
Feb 3, 2010, 2:49:30 PM (13 years ago)
Author:
jahn
Message:

Events have a convenience method for formating Durations Strings now.

String getPerttyDuration()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/studycapturing/Event.groovy

    r162 r167  
    2424        ]
    2525
    26         // static constraints = { }
    2726
    28         def getDuration() {
    2927                // time diff between end and start date
    3028                // thus, do this manually as follows
    31 
     29        def getDuration() {
    3230                def timeMillis = (endTime.getTime() - startTime.getTime()).abs()
    3331                def days = (timeMillis / (1000 * 60 * 60 * 24)).toInteger()
     
    4139
    4240
     41             // return a string that prints the duration sensibly.
     42             // the largest date unit (sec, min, h, day, week, month, or year)
     43             // is output
    4344        def getPrettyDuration() {
    44              // return a string that prints the duration sensibly.
    45              // the largest date unit (sec, min, h, day, month, or year)
    46              // is output
     45             def duration = getDuration()
     46             if( duration.getYears()   > 0 ) return duration.getYears()   + " years"
     47             if( duration.getMonths()  > 0 ) return duration.getMonths()  + " months"
     48             if( duration.getWeeks()   > 0 ) return duration.getWeeks()   + " weeks"
     49             if( duration.getDays()    > 0 ) return duration.getDays()    + " days"
     50             if( duration.getHours()   > 0 ) return duration.getHours()   + " minutes"
     51                                             return duration.getSeconds() + " seconds"
    4752        }
    4853
Note: See TracChangeset for help on using the changeset viewer.