source: trunk/grails-app/domain/dbnp/studycapturing/Event.groovy @ 124

Last change on this file since 124 was 124, checked in by jahn, 11 years ago

The Term class has been seperately created in dbnp.studycapturing.data and dbnp.studycapturing.data. Since there is no big difference, I retracted the later domain class. This requried adjustment of some imports in the controllers.

File size: 1.3 KB
Line 
1package dbnp.studycapturing
2
3import groovy.time.*
4
5
6/**
7 * The Event class describes an actual event, as it has happened to a certain subject. Often, the same event occurs
8 * to multiple subjects at the same time. That is why the actual description of the event is factored out into a more
9 * general EventDescription class. Events that also lead to sample(s) should be instantiated as SamplingEvents.
10 */
11class Event {
12
13    Subject subject
14    EventDescription eventDescription
15    Date startTime
16    Date endTime
17
18
19    // static constraints = { }
20    def getDuration() {
21        //endTime - startTime  // this is not documented and does not work either
22                               // so, it's useless.
23                               // thus, do this manually as follows
24
25        def timeMillis = (endTime.getTime() - startTime.getTime()).abs()
26        def days    = (timeMillis/(1000*60*60*24)).toInteger()
27        def hours   = (timeMillis/(1000*60*60)).toInteger()
28        def minutes = (timeMillis/(1000*60)).toInteger()
29        def seconds = (timeMillis/1000).toInteger()
30        def millis  = (timeMillis%1000).toInteger()
31
32        return new Duration(days,hours,minutes,seconds,millis)
33    }
34
35
36    def getDurationString()
37    {
38        def d = getDuration()
39        return  "${d.days} days, ${d.hours} hrs, ${d.minutes} min, ${d.seconds} sec."
40    }
41
42
43}
Note: See TracBrowser for help on using the repository browser.