Ignore:
Timestamp:
May 28, 2010, 4:19:06 PM (13 years ago)
Author:
roberth
Message:

Implemented RELTIME parsing and showing in the wizard.
Also made TEXT templatefields to show a textarea

File:
1 edited

Legend:

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

    r496 r497  
    1414 */
    1515class Event extends TemplateEntity implements Serializable {
    16         Date startTime
    17         Date endTime
     16        long startTime
     17        long endTime
    1818
    1919        /**
     
    4848                        new TemplateField(
    4949                                name: 'startTime',
    50                                 type: TemplateFieldType.DATE),
     50                                type: TemplateFieldType.RELTIME),
    5151                        new TemplateField(
    5252                                name: 'endTime',
    53                                 type: TemplateFieldType.DATE)
     53                                type: TemplateFieldType.RELTIME)
    5454                ]
    5555
    56         /**
    57          * get the event duration
    58          * @return Duration
    59          */
    60         static def getDuration(date1, date2) {
    61                 def timeMillis = (date2.getTime() - date1.getTime()).abs()
    62                 def days = (timeMillis / (1000 * 60 * 60 * 24)).toInteger()
    63                 def hours = (timeMillis / (1000 * 60 * 60)).toInteger()
    64                 def minutes = (timeMillis / (1000 * 60)).toInteger()
    65                 def seconds = (timeMillis / 1000).toInteger()
    66                 def millis = (timeMillis % 1000).toInteger()
    67 
    68                 return new Duration(days, hours, minutes, seconds, millis)
    69         }
    70 
    7156        def getDuration() {
    72                 return getDuration(startTime, endTime)
     57                return new RelTime(startTime, endTime);
    7358        }
    7459
     
    7762         * @return String
    7863         */
    79         static def getPrettyDuration(duration) {
    80                 def handleNumerus = {number, string ->
    81                         return number.toString() + (number == 1 ? string : string + 's')
    82                 }
    83                 if (duration.getYears() > 0) return handleNumerus(duration.getYears(), " year")
    84                 if (duration.getMonths() > 0) return handleNumerus(duration.getMonths(), " month")
    85                 if (duration.getDays() > 0) return handleNumerus(duration.getDays(), " day")
    86                 if (duration.getHours() > 0) return handleNumerus(duration.getHours(), " hour")
    87                 if (duration.getMinutes() > 0) return handleNumerus(duration.getMinutes(), " minute")
    88                 return handleNumerus(duration.getSeconds(), " second")
     64        static def getPrettyDuration(RelTime duration) {
     65            return duration.toPrettyRoundedString();
    8966        }
    9067
    9168        def getPrettyDuration() {
    92                 getPrettyDuration(getDuration())
    93         }
    94 
    95         static def getPrettyDuration(date1, date2) {
    96                 return getPrettyDuration(getDuration(date1, date2))
     69            getPrettyDuration(getDuration())
    9770        }
    9871
    9972        def getDurationString() {
    100                 def d = getDuration()
    101                 return "${d.days} days, ${d.hours} hrs, ${d.minutes} min, ${d.seconds} sec."
     73            def d = getDuration()
     74            return getDuration().toPrettyString();
    10275        }
    10376
    10477        def getShortDuration() {
    105                 def d = getDuration()
    106                 def days = d.days
    107                 def hours = d.hours - (24 * days)
    108                 def minutes = d.minutes - (24 * 60 * days) - (60 * hours)
    109                 return "${days}d ${hours}:${minutes}"
     78            def d = getDuration()
     79            return getDuration().toString();
    11080        }
    11181
Note: See TracChangeset for help on using the changeset viewer.