@Override
  public List<Event> getEventsInTimeframe(LocalDateTime from, LocalDateTime to)
      throws ExternalServiceException {
    List<Event> eventsList = eventDao.getEventsInTimeframe(from, to);

    return eventsList;
  }
  @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 Map<Integer, Long> countEventsTodayPerHour() 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);

    Map<Integer, Long> eventMap = eventDao.countEventsPerHourInTimeframe(todayStart, todayEnd);

    return eventMap;
  }
  @Override
  public List<Event> getEventsYesterday() throws ExternalServiceException {
    LocalDateTime baseDate = LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS);

    LocalDateTime yesterdayStart = baseDate.withHour(0).withMinute(0).withSecond(0).minusDays(1);
    LocalDateTime yesterdayEnd = baseDate.withHour(23).withMinute(59).withSecond(59).minusDays(1);

    List<Event> eventsYesterday = eventDao.getEventsInTimeframe(yesterdayStart, yesterdayEnd);

    return eventsYesterday;
  }
  @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);
 }
 @Override
 public List<Event> getEventPage(LocalDateTime start, LocalDateTime end, int pageId)
     throws ExternalServiceException {
   return eventDao.getPagedEventsInTimeframe(start, end, pageId);
 }