Search in sources :

Example 66 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class TestDateTimeFormatter method testParseLocalDate_monthDay_withDefaultYear_feb29.

public void testParseLocalDate_monthDay_withDefaultYear_feb29() {
    Chronology chrono = GJChronology.getInstanceUTC();
    DateTimeFormatter f = DateTimeFormat.forPattern("M d").withChronology(chrono).withLocale(Locale.UK).withDefaultYear(2012);
    assertEquals(new LocalDate(2012, 2, 29, chrono), f.parseLocalDate("2 29"));
}
Also used : Chronology(org.joda.time.Chronology) GJChronology(org.joda.time.chrono.GJChronology) ISOChronology(org.joda.time.chrono.ISOChronology) BuddhistChronology(org.joda.time.chrono.BuddhistChronology) LocalDate(org.joda.time.LocalDate)

Example 67 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class TestCopticChronology method testLeap_5_13.

public void testLeap_5_13() {
    Chronology chrono = CopticChronology.getInstance();
    DateTime dt = new DateTime(3, 13, 5, 0, 0, chrono);
    assertEquals(true, dt.year().isLeap());
    assertEquals(true, dt.monthOfYear().isLeap());
    assertEquals(false, dt.dayOfMonth().isLeap());
    assertEquals(false, dt.dayOfYear().isLeap());
}
Also used : Chronology(org.joda.time.Chronology) DateTime(org.joda.time.DateTime)

Example 68 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class TestCopticChronology method testLeap_6_13.

public void testLeap_6_13() {
    Chronology chrono = CopticChronology.getInstance();
    DateTime dt = new DateTime(3, 13, 6, 0, 0, chrono);
    assertEquals(true, dt.year().isLeap());
    assertEquals(true, dt.monthOfYear().isLeap());
    assertEquals(true, dt.dayOfMonth().isLeap());
    assertEquals(true, dt.dayOfYear().isLeap());
}
Also used : Chronology(org.joda.time.Chronology) DateTime(org.joda.time.DateTime)

Example 69 with Chronology

use of org.joda.time.Chronology in project druid by druid-io.

the class ExprUtils method toPeriodGranularity.

static PeriodGranularity toPeriodGranularity(final Expr periodArg, @Nullable final Expr originArg, @Nullable final Expr timeZoneArg, final Expr.ObjectBinding bindings) {
    final Period period = new Period(periodArg.eval(bindings).asString());
    final DateTime origin;
    final DateTimeZone timeZone;
    if (timeZoneArg == null) {
        timeZone = null;
    } else {
        final String value = timeZoneArg.eval(bindings).asString();
        timeZone = value != null ? DateTimes.inferTzFromString(value) : null;
    }
    if (originArg == null) {
        origin = null;
    } else {
        Chronology chronology = timeZone == null ? ISOChronology.getInstanceUTC() : ISOChronology.getInstance(timeZone);
        final Object value = originArg.eval(bindings).value();
        if (value instanceof String && NullHandling.isNullOrEquivalent((String) value)) {
            // We get a blank string here, when sql compatible null handling is enabled
            // and expression contains empty string for for origin
            // e.g timestamp_floor(\"__time\",'PT1M','','UTC')
            origin = null;
        } else {
            origin = value != null ? new DateTime(value, chronology) : null;
        }
    }
    return new PeriodGranularity(period, origin, timeZone);
}
Also used : PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology) DateTime(org.joda.time.DateTime) DateTimeZone(org.joda.time.DateTimeZone)

Aggregations

Chronology (org.joda.time.Chronology)69 DateTime (org.joda.time.DateTime)32 ISOChronology (org.joda.time.chrono.ISOChronology)30 GJChronology (org.joda.time.chrono.GJChronology)18 BuddhistChronology (org.joda.time.chrono.BuddhistChronology)17 LocalDate (org.joda.time.LocalDate)14 DateTimeZone (org.joda.time.DateTimeZone)13 MutableDateTime (org.joda.time.MutableDateTime)7 LocalDateTime (org.joda.time.LocalDateTime)4 ReadableDateTime (org.joda.time.ReadableDateTime)4 JulianChronology (org.joda.time.chrono.JulianChronology)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Serializable (java.io.Serializable)2 Date (java.util.Date)2 Duration (org.joda.time.Duration)2 Period (org.joda.time.Period)2 ReadableDuration (org.joda.time.ReadableDuration)2 ReadableInstant (org.joda.time.ReadableInstant)2 ReadablePartial (org.joda.time.ReadablePartial)2 Calendar (java.util.Calendar)1