Skip to content

Commit

Permalink
Merge pull request #4 from choonchernlim/feature/all-day-bug
Browse files Browse the repository at this point in the history
0.4.1
  • Loading branch information
choonchernlim authored Mar 8, 2017
2 parents e367c3c + 0790dd8 commit edf14b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.4.1 - 2017-03-08

* Fixed problem where all-day Exchange event from previous day gets created every time CalSync runs.

## 0.4.0 - 2016-12-16

* `exchange.sleep.on.connection.error` = Whether to suppress thrown Exchange connection error or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import microsoft.exchange.webservices.data.core.service.folder.CalendarFolder
import microsoft.exchange.webservices.data.credential.WebCredentials
import microsoft.exchange.webservices.data.search.CalendarView
import org.joda.time.DateTime
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
* Exchange client class.
*/
@PackageScope
class ExchangeClient {
private static Logger LOGGER = LoggerFactory.getLogger(ExchangeClient)
// private static Logger LOGGER = LoggerFactory.getLogger(ExchangeClient)

final ExchangeService service

Expand Down Expand Up @@ -46,6 +44,23 @@ class ExchangeClient {
return CalendarFolder.bind(service, WellKnownFolderName.Calendar).
findAppointments(new CalendarView(startDateTime.toDate(), endDateTime.toDate())).
getItems()?.
findAll { appointment ->
// Exchange sets all-day event appointment from given day midnight to the next day midnight,
// which may get picked up because it matches the given `endDateTime` even though it is an
// all-day event appointment for the day before.
//
// To fix this, only include appointments with start datetime between the given
// date range.
if (appointment.isAllDayEvent) {
def appointmentStartDateTime = new DateTime(appointment.start)

return !appointmentStartDateTime.isBefore(startDateTime) &&
!appointmentStartDateTime.isAfter(endDateTime)
}
else {
return appointment
}
}?.
collect { appointment ->
appointment.load(PropertySet.firstClassProperties)
Mapper.toExchangeEvent(appointment)
Expand Down

0 comments on commit edf14b2

Please sign in to comment.