@Override public long countEventsToday() throws ExternalServiceException { LocalDateTime baseDate = LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS); LocalDateTime todayStart = baseDate.withHour(0).withMinute(0).withSecond(0); LocalDateTime todayEnd = baseDate.withHour(23).withMinute(59).withSecond(59); long eventCount = eventDao.countEventsInTimeframe(todayStart, todayEnd); return eventCount; }
@Override public long countEventsThisWeek() throws ExternalServiceException { LocalDateTime baseDate = LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS); int dayOfWeek = baseDate.getDayOfWeek().getValue(); // We have to substract this number of days from today to get monday int weekStartOffset = dayOfWeek - 1; // We have to add this number of days to today to get sunday int weekEndOffset = 7 - dayOfWeek; LocalDateTime weekStart = baseDate.withHour(0).withMinute(0).withSecond(0).minusDays(weekStartOffset); LocalDateTime weekEnd = baseDate.withHour(23).withMinute(59).withSecond(59).plusDays(weekEndOffset); long eventCount = eventDao.countEventsInTimeframe(weekStart, weekEnd); return eventCount; }
@Override public long countEventsInTimeframe(LocalDateTime from, LocalDateTime to) throws ExternalServiceException { return eventDao.countEventsInTimeframe(from, to); }