Search in sources :

Example 1 with TimePeriod

use of com.alexstyl.specialdates.date.TimePeriod in project Memento-Calendar by alexstyl.

the class BankHolidayProvider method calculateBankHolidaysBetween.

public List<BankHoliday> calculateBankHolidaysBetween(TimePeriod timePeriod) {
    if (isWithinTheSameYear(timePeriod)) {
        return calculateBankHolidaysFor(timePeriod);
    } else {
        ArrayList<BankHoliday> allBankholidays = new ArrayList<>();
        TimePeriod firstHalf = getfirstHalfOf(timePeriod);
        List<BankHoliday> firstHalfBankHolidays = calculateBankHolidaysFor(firstHalf);
        allBankholidays.addAll(firstHalfBankHolidays);
        TimePeriod secondHalf = getSecondHalfOf(timePeriod);
        List<BankHoliday> secondHalfBankHolidays = calculateBankHolidaysFor(secondHalf);
        allBankholidays.addAll(secondHalfBankHolidays);
        return allBankholidays;
    }
}
Also used : TimePeriod(com.alexstyl.specialdates.date.TimePeriod) ArrayList(java.util.ArrayList)

Example 2 with TimePeriod

use of com.alexstyl.specialdates.date.TimePeriod in project Memento-Calendar by alexstyl.

the class TimePeriodTest method dateOutsideOfPeriod.

@Test
public void dateOutsideOfPeriod() {
    TimePeriod range = TimePeriod.Companion.between(Date.Companion.startOfYear(2016), Date.Companion.startOfYear(2017));
    assertThat(range.containsDate(Date.Companion.on(1, FEBRUARY, 1990))).isFalse();
}
Also used : TimePeriod(com.alexstyl.specialdates.date.TimePeriod) Test(org.junit.Test)

Example 3 with TimePeriod

use of com.alexstyl.specialdates.date.TimePeriod in project Memento-Calendar by alexstyl.

the class TimePeriodTest method dateBetweenPeriod.

@Test
public void dateBetweenPeriod() {
    TimePeriod range = TimePeriod.Companion.between(Date.Companion.startOfYear(2016), Date.Companion.startOfYear(2017));
    assertThat(range.containsDate(Date.Companion.on(1, FEBRUARY, 2016))).isTrue();
}
Also used : TimePeriod(com.alexstyl.specialdates.date.TimePeriod) Test(org.junit.Test)

Example 4 with TimePeriod

use of com.alexstyl.specialdates.date.TimePeriod in project Memento-Calendar by alexstyl.

the class PeopleEventsSearch method searchForContacts.

List<ContactWithEvents> searchForContacts(String searchQuery, int counter) {
    if (counter <= 0) {
        return new ArrayList<>();
    }
    searchQuery = searchQuery.trim();
    HashMapList<Contact, ContactEvent> events = new HashMapList<>();
    TimePeriod between = TimePeriod.Companion.aYearFromNow();
    List<ContactEvent> contactEventsOnDate = peopleEventsProvider.fetchEventsBetween(between);
    int size = 0;
    for (ContactEvent contactEvent : contactEventsOnDate) {
        Contact contact = contactEvent.getContact();
        if (nameMatcher.match(contact.getDisplayName(), searchQuery)) {
            events.addValue(contact, contactEvent);
            size++;
        }
        if (size >= counter) {
            break;
        }
    }
    List<ContactWithEvents> contactWithEvents = new ArrayList<>();
    for (Contact contact : events.keys()) {
        List<ContactEvent> list = events.get(contact);
        contactWithEvents.add(new ContactWithEvents(contact, list));
    }
    return contactWithEvents;
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) TimePeriod(com.alexstyl.specialdates.date.TimePeriod) ArrayList(java.util.ArrayList) HashMapList(com.alexstyl.specialdates.util.HashMapList) Contact(com.alexstyl.specialdates.contact.Contact)

Aggregations

TimePeriod (com.alexstyl.specialdates.date.TimePeriod)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Contact (com.alexstyl.specialdates.contact.Contact)1 ContactEvent (com.alexstyl.specialdates.date.ContactEvent)1 HashMapList (com.alexstyl.specialdates.util.HashMapList)1