Changeset 497 for trunk/grails-app/domain/dbnp/studycapturing/Event.groovy
- Timestamp:
- May 28, 2010, 4:19:06 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/Event.groovy
r496 r497 14 14 */ 15 15 class Event extends TemplateEntity implements Serializable { 16 DatestartTime17 DateendTime16 long startTime 17 long endTime 18 18 19 19 /** … … 48 48 new TemplateField( 49 49 name: 'startTime', 50 type: TemplateFieldType. DATE),50 type: TemplateFieldType.RELTIME), 51 51 new TemplateField( 52 52 name: 'endTime', 53 type: TemplateFieldType. DATE)53 type: TemplateFieldType.RELTIME) 54 54 ] 55 55 56 /**57 * get the event duration58 * @return Duration59 */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 71 56 def getDuration() { 72 return getDuration(startTime, endTime)57 return new RelTime(startTime, endTime); 73 58 } 74 59 … … 77 62 * @return String 78 63 */ 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(); 89 66 } 90 67 91 68 def getPrettyDuration() { 92 getPrettyDuration(getDuration()) 93 } 94 95 static def getPrettyDuration(date1, date2) { 96 return getPrettyDuration(getDuration(date1, date2)) 69 getPrettyDuration(getDuration()) 97 70 } 98 71 99 72 def getDurationString() { 100 101 return "${d.days} days, ${d.hours} hrs, ${d.minutes} min, ${d.seconds} sec." 73 def d = getDuration() 74 return getDuration().toPrettyString(); 102 75 } 103 76 104 77 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(); 110 80 } 111 81
Note: See TracChangeset
for help on using the changeset viewer.