Example usage for org.joda.time LocalDate LocalDate

List of usage examples for org.joda.time LocalDate LocalDate

Introduction

In this page you can find the example usage for org.joda.time LocalDate LocalDate.

Prototype

public LocalDate(int year, int monthOfYear, int dayOfMonth, Chronology chronology) 

Source Link

Document

Constructs an instance set to the specified date and time using the specified chronology, whose zone is ignored.

Usage

From source file:Classes.HijriTime.java

License:Open Source License

public String getHijriTime() {////get final translated hijri date
    this.dayFormatter = new DecimalFormat("00");
    this.yearFormatter = new DecimalFormat("0000");

    Chronology iSOChronology = ISOChronology.getInstanceUTC();//get ISOChronology instance
    Chronology islamicChronology = IslamicChronology.getInstanceUTC();//get IslamicChronology instance

    LocalDate localDateISOChronology = new LocalDate(year, month, day, iSOChronology);//get local date
    LocalDate HijriDate = new LocalDate(localDateISOChronology.toDate(), islamicChronology);//get hijri date

    return hijriDaysNames[calendar.get(Calendar.DAY_OF_WEEK)] + " "
            + dayFormatter.format(HijriDate.getDayOfMonth()) + " "
            + hijriMonthsNames[HijriDate.getMonthOfYear()] + " " + yearFormatter.format(HijriDate.getYear());
}

From source file:com.helger.datetime.holiday.parser.impl.RelativeToEasterSundayParser.java

License:Apache License

/**
 * Returns the easter Sunday within the julian chronology.
 * //from  w  w w  .j a v  a2  s.co m
 * @param nYear
 *        The year to retrieve Julian Easter Sunday date
 * @return julian easter Sunday
 */
public static LocalDate getJulianEasterSunday(final int nYear) {
    int a, b, c, d, e;
    int x, nMonth, nDay;
    a = nYear % 4;
    b = nYear % 7;
    c = nYear % 19;
    d = (19 * c + 15) % 30;
    e = (2 * a + 4 * b - d + 34) % 7;
    x = d + e + 114;
    nMonth = x / 31;
    nDay = (x % 31) + 1;
    return new LocalDate(nYear, (nMonth == 3 ? DateTimeConstants.MARCH : DateTimeConstants.APRIL), nDay,
            JulianChronology.getInstance());
}

From source file:com.helger.datetime.holiday.parser.impl.RelativeToEasterSundayParser.java

License:Apache License

/**
 * Returns the easter Sunday within the gregorian chronology.
 * /*from  ww  w  .ja  v  a2  s .c o m*/
 * @param nYear
 *        The year to retrieve Gregorian Easter Sunday date
 * @return gregorian easter Sunday.
 */
public static LocalDate getGregorianEasterSunday(final int nYear) {
    int a, b, c, d, e, f, g, h, i, j, k, l;
    int x, nMonth, nDay;
    a = nYear % 19;
    b = nYear / 100;
    c = nYear % 100;
    d = b / 4;
    e = b % 4;
    f = (b + 8) / 25;
    g = (b - f + 1) / 3;
    h = (19 * a + b - d - g + 15) % 30;
    i = c / 4;
    j = c % 4;
    k = (32 + 2 * e + 2 * i - h - j) % 7;
    l = (a + 11 * h + 22 * k) / 451;
    x = h + k - 7 * l + 114;
    nMonth = x / 31;
    nDay = (x % 31) + 1;
    return new LocalDate(nYear, (nMonth == 3 ? DateTimeConstants.MARCH : DateTimeConstants.APRIL), nDay,
            GregorianChronology.getInstance(PDTConfig.getDefaultDateTimeZone()));
}

From source file:com.helger.datetime.PDTFactory.java

License:Apache License

@Nonnull
public static LocalDate createLocalDate(final int nYears, final int nMonths, final int nDays) {
    return new LocalDate(nYears, nMonths, nDays, getLocalChronology());
}

From source file:com.jjlharrison.jollyday.util.CalendarUtil.java

License:Apache License

/**
 * Creates the date within the provided chronology.
 *
 * @param year/*from  w w  w  . j  a  v  a  2 s. c om*/
 *            a int.
 * @param month
 *            a int.
 * @param day
 *            a int.
 * @param chronology
 *            the chronology to use
 * @return date the {@link LocalDate}
 */
public LocalDate create(int year, int month, int day, Chronology chronology) {
    return new LocalDate(year, month, day, chronology);
}

From source file:com.jjlharrison.jollyday.util.CalendarUtil.java

License:Apache License

/**
 * Searches for the occurrences of a month/day in one chronology within one
 * gregorian year./*from  ww w.jav  a 2 s .  co m*/
 *
 * @param targetMonth
 * @param targetDay
 * @param gregorianYear
 * @param targetChrono
 * @return the list of gregorian dates.
 */
private Set<LocalDate> getDatesFromChronologyWithinGregorianYear(int targetMonth, int targetDay,
        int gregorianYear, Chronology targetChrono) {
    Set<LocalDate> holidays = new HashSet<LocalDate>();
    LocalDate firstGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.JANUARY, 1,
            ISOChronology.getInstance());
    LocalDate lastGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.DECEMBER, 31,
            ISOChronology.getInstance());

    LocalDate firstTargetDate = new LocalDate(firstGregorianDate.toDateTimeAtStartOfDay().getMillis(),
            targetChrono);
    LocalDate lastTargetDate = new LocalDate(lastGregorianDate.toDateTimeAtStartOfDay().getMillis(),
            targetChrono);

    Interval interv = new Interval(firstTargetDate.toDateTimeAtStartOfDay(),
            lastTargetDate.plusDays(1).toDateTimeAtStartOfDay());

    int targetYear = firstTargetDate.getYear();

    for (; targetYear <= lastTargetDate.getYear();) {
        LocalDate d = new LocalDate(targetYear, targetMonth, targetDay, targetChrono);
        if (interv.contains(d.toDateTimeAtStartOfDay())) {
            holidays.add(convertToISODate(d));
        }
        targetYear++;
    }
    return holidays;
}

From source file:com.ning.billing.invoice.generator.InvoiceDateUtils.java

License:Apache License

public static LocalDate calculateBillingCycleDateOnOrAfter(final LocalDate date,
        final int billingCycleDayLocal) {
    final int lastDayOfMonth = date.dayOfMonth().getMaximumValue();

    final LocalDate fixedDate;
    if (billingCycleDayLocal > lastDayOfMonth) {
        fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), lastDayOfMonth, date.getChronology());
    } else {/* www. j  a v  a  2  s .  com*/
        fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), billingCycleDayLocal,
                date.getChronology());
    }

    LocalDate proposedDate = fixedDate;
    while (proposedDate.isBefore(date)) {
        proposedDate = proposedDate.plusMonths(1);
    }
    return proposedDate;
}