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(DateTimeZone zone) 

Source Link

Document

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

Usage

From source file:com.arpnetworking.kairosdb.aggregators.MovingWindowAggregator.java

License:Apache License

private DateTimeField timeUnitToTimeField(final TimeUnit timeUnit) {
    final Chronology chronology = GregorianChronology.getInstance(_timeZone);
    switch (timeUnit) {
    case YEARS:/*from  w  w  w.  j a  v a  2  s  .co  m*/
        return chronology.year();
    case MONTHS:
        return chronology.monthOfYear();
    case WEEKS:
        return chronology.weekOfWeekyear();
    case DAYS:
        return chronology.dayOfMonth();
    case HOURS:
        return chronology.hourOfDay();
    case MINUTES:
        return chronology.minuteOfHour();
    case SECONDS:
        return chronology.secondOfDay();
    default:
        return chronology.millisOfSecond();
    }
}

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

License:Apache License

/**
 * Returns the easter Sunday within the gregorian chronology.
 * /*  w  w w  . ja v a2s  .  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:de.openali.odysseus.chart.ext.base.axisrenderer.DateTimeTickCalculator.java

License:Open Source License

private long getFirstRollValue(final IDateTimeAxisField axisField, final long start, final long end) {
    final DateTimeZone jodaTZ = DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone());
    final DateTimeField field = axisField.getFieldType().getField(GregorianChronology.getInstance(jodaTZ));
    final long firstRoll = field.roundFloor(start);
    if (firstRoll + end - start <= start)
        // out of range, precision too small so we return without adjustment
        // maybe try roundCeil instead
        return start;
    final int fieldValue = field.get(firstRoll);
    if (fieldValue == 0)
        return firstRoll;

    final int[] beginners = axisField.getBeginners();
    for (int i = 1; i < beginners.length; i++) {
        if (fieldValue < beginners[i]) {
            return field.add(firstRoll, beginners[i - 1] - fieldValue);
        }//  ww w  .j ava 2 s  .  c  o m
    }

    return field.add(firstRoll, -fieldValue);
}

From source file:de.openali.odysseus.chart.ext.base.axisrenderer.DateTimeTickCalculator.java

License:Open Source License

/**
 * Calculates the ticks shown for the given Axis
 *///  ww w  .  ja v a2s  .c  o m
@SuppressWarnings("rawtypes")
@Override
public Double[] calcTicks(final GC gc, final IAxis axis, final Number minDisplayInterval,
        final Point ticklabelSize) {
    final IDataRange<Number> numRange = axis.getNumericRange();
    if (numRange == null || numRange.getMin() == null || numRange.getMax() == null)
        return new Double[] {};

    final long start = numRange.getMin().longValue();
    final long end = numRange.getMax().longValue();

    final IDateTimeAxisField axisField = m_fieldTypeProvider.getDateTimeAxisField(numRange);

    final DateTimeZone jodaTZ = DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone());
    final DurationField field = axisField.getFieldType().getDurationType()
            .getField(GregorianChronology.getInstance(jodaTZ));

    final int tickCount = Math.max(1, field.getDifference(end, start));
    final int maximumTickCount = axis.getScreenHeight() / (ticklabelSize.x + 2/* Pixel */);
    final int[] rollOvers = axisField.getRollovers();

    final int rollOver = calculateRollover(tickCount, maximumTickCount, rollOvers);

    final List<Double> ticks = new ArrayList<>();
    Long tick = getFirstRollValue(axisField, start, end);
    ticks.add(tick.doubleValue());
    while (tick < end) {
        tick = field.add(tick, rollOver);
        ticks.add(tick.doubleValue());
    }

    return ticks.toArray(new Double[ticks.size()]);
}

From source file:org.jruby.ext.date.RubyDate.java

License:LGPL

static Chronology getChronology(ThreadContext context, final long sg, final DateTimeZone zone) {
    if (sg == ITALY)
        return GJChronology.getInstance(zone);
    if (sg == JULIAN)
        return JulianChronology.getInstance(zone);
    if (sg == GREGORIAN)
        return GregorianChronology.getInstance(zone);

    Instant cutover = new Instant(DateTimeUtils.fromJulianDay(jd_to_ajd(sg)));
    try {//w  w  w. j a  v  a  2s .c o  m
        return GJChronology.getInstance(zone, cutover);
    } // java.lang.IllegalArgumentException: Cutover too early. Must be on or after 0001-01-01.
    catch (IllegalArgumentException ex) {
        debug(context, "invalid date", ex);
        throw context.runtime.newArgumentError("invalid date");
    }
}

From source file:org.jugular.jodatime.factory.ChronologyFactory.java

License:Apache License

public Chronology create(Type chronologyType, String zoneId) {
    DateTimeZone zone;//ww w . j a  va  2s . c  om
    Chronology chronology;

    if (zoneId == null || "".equals(zoneId)) {
        zone = controller.getDateTimeZone();
    } else {
        zone = DateTimeZone.forID(zoneId);
    }

    switch (chronologyType) {
    case BUDDHIST:
        chronology = BuddhistChronology.getInstance(zone);
        break;
    case COPTIC:
        chronology = CopticChronology.getInstance(zone);
        break;
    case ETHIOPIC:
        chronology = EthiopicChronology.getInstance(zone);
        break;
    case GREGORIAN:
        chronology = GregorianChronology.getInstance(zone);
        break;
    case GREGORIAN_JULIAN:
        chronology = GJChronology.getInstance(zone);
        break;
    case ISLAMIC:
        chronology = IslamicChronology.getInstance(zone);
        break;
    case ISO:
        chronology = ISOChronology.getInstance(zone);
        break;
    case JULIAN:
        chronology = JulianChronology.getInstance(zone);
        break;
    default:
        throw new AssertionError("Calender system not supported");
    }

    return chronology;

}