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);
}
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;
}
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());
}
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);
}
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);
}
Aggregations