Sha256: f6d2474d1449278ceb260f5f5ce3e5c561ab1e992c68911ee4ef4aec547b2555

Contents?: true

Size: 1.51 KB

Versions: 104

Compression:

Stored size: 1.51 KB

Contents

import java.time.LocalDate;
import java.time.DayOfWeek;


class Meetup {
    private final LocalDate startOfMonth;

    Meetup(int monthOfYear, int year) {
        startOfMonth = LocalDate.of(year, monthOfYear, 1);
    }

    LocalDate day(DayOfWeek dayOfWeek, MeetupSchedule schedule) {
        LocalDate current = cycleToNext(dayOfWeek, startOfMonth);
        switch (schedule) {
            case FIRST:
                break;
            case SECOND:
                current = current.plusWeeks(1);
                break;
            case THIRD:
                current = current.plusWeeks(2);
                break;
            case FOURTH:
                current = current.plusWeeks(3);
                break;
            case TEENTH:
                while (current.getDayOfMonth() < 13) {
                    current = current.plusWeeks(1);
                }
                break;
            case LAST:
                current = cycleToPrev(dayOfWeek, startOfMonth.plusMonths(1).minusDays(1));
                break;
            default:
                return null;
        }
        return current;
    }

    private LocalDate cycleToPrev(DayOfWeek dayOfWeek, LocalDate current) {
        while (current.getDayOfWeek() != dayOfWeek) {
            current = current.minusDays(1);
        }
        return current;
    }

    private LocalDate cycleToNext(DayOfWeek dayOfWeek, LocalDate current) {
        while (current.getDayOfWeek() != dayOfWeek) {
            current = current.plusDays(1);
        }
        return current;
    }
}

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.138 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.137 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.136 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.135 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.134 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.133 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.132 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.131 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.130 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.129 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.128 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.127 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.126 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.125 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.124 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.123 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.122 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.121 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.120 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java