@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;
  }