Example usage for org.joda.time.chrono GregorianChronology getInstance

List of usage examples for org.joda.time.chrono GregorianChronology getInstance

Introduction

In this page you can find the example usage for org.joda.time.chrono GregorianChronology getInstance.

Prototype

public static GregorianChronology getInstance() 

Source Link

Document

Gets an instance of the GregorianChronology in the default time zone.

Usage

From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java

License:Apache License

/**
 * Given a year, month, and day, find the number of occurrences of that day in the month
 *
 * @param year  the year/*from  w  w w  .ja va 2s  . c o  m*/
 * @param month the month
 * @param day   the day
 * @return the number of occurrences of the day in the month
 */
public int numOccurrences(int year, int month, int day) {
    DateTimeFormatter parser = ISODateTimeFormat.date();
    DateTime date = parser.parseDateTime(year + "-" + month + "-" + "01");
    Calendar cal = Calendar.getInstance();
    cal.setTime(date.toDate());
    GregorianChronology calendar = GregorianChronology.getInstance();
    DateTimeField field = calendar.dayOfMonth();

    int days = 0;
    int count = 0;
    int num = field.getMaximumValue(new LocalDate(year, month, day, calendar));
    while (days < num) {
        if (cal.get(Calendar.DAY_OF_WEEK) == day) {
            count++;
        }
        date = date.plusDays(1);
        cal.setTime(date.toDate());

        days++;
    }
    return count;
}

From source file:org.odk.collect.android.fragments.dialogs.CustomDatePickerDialog.java

License:Apache License

private LocalDateTime getDateAsGregorian(LocalDateTime date) {
    return DateTimeUtils.skipDaylightSavingGapIfExists(date).toDateTime()
            .withChronology(GregorianChronology.getInstance()).toLocalDateTime();
}