Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Feb 10th, 2012  |  syntax: Groovy  |  size: 1.34 KB  |  hits: 140  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import org.joda.time.DateTime
  2. import static org.joda.time.DateTimeConstants.MONDAY
  3. import static org.joda.time.DateTimeConstants.WEDNESDAY
  4. import static org.joda.time.DateTimeConstants.FRIDAY
  5.  
  6. // Re. the blog post: location, description, recuruntil, recurcount missing from last domain class example
  7.  
  8. // Creating dates for our test events
  9. def now = new DateTime()
  10. def tomorrow = now.plusDays(1)
  11.  
  12. // Creating a weekly event that occurs every MWF
  13. def event = new Event(title: 'Repeating MWF Event').with {
  14.     startTime = now.toDate()
  15.     endTime = now.plusHours(1).toDate()
  16.     location = "Regular location"
  17.     recurType = EventRecurType.WEEKLY
  18.     [MONDAY, WEDNESDAY, FRIDAY]*.toInteger().each { addToRecurDaysOfWeek(it) }
  19.     addToExcludeDays(now.withDayOfWeek(MONDAY).plusWeeks(1).toDate())
  20.     isRecurring = true
  21.     save(flush: true)
  22. }
  23.  
  24. // Non-repeating single event that replaces the one excluded next Monday
  25. def event2 = new Event(title: event.title).with {
  26.     sourceEvent = event
  27.     startTime = event.startTime
  28.     endTime = event.endTime
  29.     location = "New one-time location"
  30.     isRecurring = false
  31.     save()
  32. }
  33.  
  34. // Plain old non-repeating event
  35. def event3 = new Event(title: 'Just a normal event').with {
  36.     startTime = tomorrow.toDate()
  37.     endTime = tomorrow.plusMinutes(30).toDate()
  38.     isRecurring = false
  39.     save()
  40. }