Search in sources :

Example 6 with ISOChronology

use of org.joda.time.chrono.ISOChronology in project presto by prestodb.

the class DateTimeUtils method printTimestampWithTimeZone.

public static String printTimestampWithTimeZone(long timestampWithTimeZone) {
    ISOChronology chronology = unpackChronology(timestampWithTimeZone);
    long millis = unpackMillisUtc(timestampWithTimeZone);
    return TIMESTAMP_WITH_TIME_ZONE_FORMATTER.withChronology(chronology).print(millis);
}
Also used : ISOChronology(org.joda.time.chrono.ISOChronology)

Example 7 with ISOChronology

use of org.joda.time.chrono.ISOChronology in project joda-time by JodaOrg.

the class ReadableInstantConverter method getChronology.

//-----------------------------------------------------------------------
/**
     * Gets the chronology, which is taken from the ReadableInstant.
     * If the chronology on the instant is null, the ISOChronology in the
     * specified time zone is used.
     * If the chronology on the instant is not in the specified zone, it is
     * adapted.
     * 
     * @param object  the ReadableInstant to convert, must not be null
     * @param zone  the specified zone to use, null means default zone
     * @return the chronology, never null
     */
public Chronology getChronology(Object object, DateTimeZone zone) {
    Chronology chrono = ((ReadableInstant) object).getChronology();
    if (chrono == null) {
        return ISOChronology.getInstance(zone);
    }
    DateTimeZone chronoZone = chrono.getZone();
    if (chronoZone != zone) {
        chrono = chrono.withZone(zone);
        if (chrono == null) {
            return ISOChronology.getInstance(zone);
        }
    }
    return chrono;
}
Also used : ReadableInstant(org.joda.time.ReadableInstant) Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology) DateTimeZone(org.joda.time.DateTimeZone)

Example 8 with ISOChronology

use of org.joda.time.chrono.ISOChronology in project joda-time by JodaOrg.

the class TestChronology method testToString.

//-----------------------------------------------------------------------
public void testToString() {
    DateTimeZone paris = DateTimeZone.forID("Europe/Paris");
    ISOChronology isoParis = ISOChronology.getInstance(paris);
    assertEquals("ISOChronology[Europe/Paris]", isoParis.toString());
    assertEquals("GJChronology[Europe/Paris]", GJChronology.getInstance(paris).toString());
    assertEquals("GregorianChronology[Europe/Paris]", GregorianChronology.getInstance(paris).toString());
    assertEquals("JulianChronology[Europe/Paris]", JulianChronology.getInstance(paris).toString());
    assertEquals("BuddhistChronology[Europe/Paris]", BuddhistChronology.getInstance(paris).toString());
    assertEquals("CopticChronology[Europe/Paris]", CopticChronology.getInstance(paris).toString());
    assertEquals("EthiopicChronology[Europe/Paris]", EthiopicChronology.getInstance(paris).toString());
    assertEquals("IslamicChronology[Europe/Paris]", IslamicChronology.getInstance(paris).toString());
    assertEquals("LenientChronology[ISOChronology[Europe/Paris]]", LenientChronology.getInstance(isoParis).toString());
    assertEquals("StrictChronology[ISOChronology[Europe/Paris]]", StrictChronology.getInstance(isoParis).toString());
    assertEquals("LimitChronology[ISOChronology[Europe/Paris], NoLimit, NoLimit]", LimitChronology.getInstance(isoParis, null, null).toString());
    assertEquals("ZonedChronology[ISOChronology[UTC], Europe/Paris]", ZonedChronology.getInstance(isoParis, paris).toString());
}
Also used : ISOChronology(org.joda.time.chrono.ISOChronology)

Example 9 with ISOChronology

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

the class UniformGranularityTest method testPeriodSegmentGranularity.

@Test
public void testPeriodSegmentGranularity() {
    final GranularitySpec spec = new UniformGranularitySpec(new PeriodGranularity(new Period("P1D"), null, DateTimeZone.forID("America/Los_Angeles")), null, Lists.newArrayList(new Interval("2012-01-08T00-08:00/2012-01-11T00-08:00"), new Interval("2012-01-07T00-08:00/2012-01-08T00-08:00"), new Interval("2012-01-03T00-08:00/2012-01-04T00-08:00"), new Interval("2012-01-01T00-08:00/2012-01-03T00-08:00"), new Interval("2012-09-01T00-07:00/2012-09-03T00-07:00")));
    Assert.assertTrue(spec.bucketIntervals().isPresent());
    final Optional<SortedSet<Interval>> sortedSetOptional = spec.bucketIntervals();
    final SortedSet<Interval> intervals = sortedSetOptional.get();
    ArrayList<Long> actualIntervals = new ArrayList<>();
    for (Interval interval : intervals) {
        actualIntervals.add(interval.toDurationMillis());
    }
    final ISOChronology chrono = ISOChronology.getInstance(DateTimeZone.forID("America/Los_Angeles"));
    final ArrayList<Long> expectedIntervals = Lists.newArrayList(new Interval("2012-01-01/2012-01-02", chrono).toDurationMillis(), new Interval("2012-01-02/2012-01-03", chrono).toDurationMillis(), new Interval("2012-01-03/2012-01-04", chrono).toDurationMillis(), new Interval("2012-01-07/2012-01-08", chrono).toDurationMillis(), new Interval("2012-01-08/2012-01-09", chrono).toDurationMillis(), new Interval("2012-01-09/2012-01-10", chrono).toDurationMillis(), new Interval("2012-01-10/2012-01-11", chrono).toDurationMillis(), new Interval("2012-09-01/2012-09-02", chrono).toDurationMillis(), new Interval("2012-09-02/2012-09-03", chrono).toDurationMillis());
    Assert.assertEquals(expectedIntervals, actualIntervals);
}
Also used : ISOChronology(org.joda.time.chrono.ISOChronology) PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) SortedSet(java.util.SortedSet) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 10 with ISOChronology

use of org.joda.time.chrono.ISOChronology in project presto by prestodb.

the class TimestampWithTimeZoneOperators method castToDate.

@ScalarFunction("date")
@ScalarOperator(CAST)
@SqlType(StandardTypes.DATE)
public static long castToDate(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long value) {
    // round down the current timestamp to days
    ISOChronology chronology = unpackChronology(value);
    long date = chronology.dayOfYear().roundFloor(unpackMillisUtc(value));
    // date is currently midnight in timezone of the original value
    // convert to UTC
    long millis = date + chronology.getZone().getOffset(date);
    return TimeUnit.MILLISECONDS.toDays(millis);
}
Also used : ISOChronology(org.joda.time.chrono.ISOChronology) ScalarOperator(com.facebook.presto.spi.function.ScalarOperator) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

ISOChronology (org.joda.time.chrono.ISOChronology)11 SqlType (com.facebook.presto.spi.function.SqlType)6 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)4 ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)4 Description (com.facebook.presto.spi.function.Description)2 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)1 PeriodGranularity (io.druid.java.util.common.granularity.PeriodGranularity)1 ArrayList (java.util.ArrayList)1 SortedSet (java.util.SortedSet)1 Chronology (org.joda.time.Chronology)1 DateTime (org.joda.time.DateTime)1 DateTimeZone (org.joda.time.DateTimeZone)1 Interval (org.joda.time.Interval)1 Period (org.joda.time.Period)1 ReadableInstant (org.joda.time.ReadableInstant)1 Test (org.junit.Test)1