Sha256: a839e373feab541b7fa36ff705c061952376d77234b6a913f3d41fb97e939a2a

Contents?: true

Size: 1.52 KB

Versions: 280

Compression:

Stored size: 1.52 KB

Contents

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


public class Meetup {
    private final LocalDate startOfMonth;

    public 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

280 entries across 280 versions & 1 rubygems

Version Path
trackler-2.2.1.74 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.73 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.72 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.71 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.70 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.69 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.68 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.67 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.66 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.65 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.64 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.63 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.62 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.61 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.60 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.59 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.58 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.57 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.56 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java
trackler-2.2.1.55 tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java