use of org.gridgain.internal.h2.value.ValueDate in project apollo by salesforce.
the class DateTimeUtils method dateAndTimeFromValue.
/**
* Extracts date value and nanos of day from the specified value.
*
* @param value
* value to extract fields from
* @param provider
* the cast information provider
* @return array with date value and nanos of day
*/
public static long[] dateAndTimeFromValue(Value value, CastDataProvider provider) {
long dateValue = EPOCH_DATE_VALUE;
long timeNanos = 0;
if (value instanceof ValueTimestamp) {
ValueTimestamp v = (ValueTimestamp) value;
dateValue = v.getDateValue();
timeNanos = v.getTimeNanos();
} else if (value instanceof ValueDate) {
dateValue = ((ValueDate) value).getDateValue();
} else if (value instanceof ValueTime) {
timeNanos = ((ValueTime) value).getNanos();
} else if (value instanceof ValueTimestampTimeZone) {
ValueTimestampTimeZone v = (ValueTimestampTimeZone) value;
dateValue = v.getDateValue();
timeNanos = v.getTimeNanos();
} else if (value instanceof ValueTimeTimeZone) {
timeNanos = ((ValueTimeTimeZone) value).getNanos();
} else {
ValueTimestamp v = (ValueTimestamp) value.convertTo(TypeInfo.TYPE_TIMESTAMP, provider);
dateValue = v.getDateValue();
timeNanos = v.getTimeNanos();
}
return new long[] { dateValue, timeNanos };
}
use of org.gridgain.internal.h2.value.ValueDate in project SpringStudy by myounghaklee.
the class IntervalOperation method getDateTimeWithInterval.
private Value getDateTimeWithInterval(SessionLocal session, Value l, Value r, int lType, int rType) {
switch(lType) {
case Value.TIME:
if (DataType.isYearMonthIntervalType(rType)) {
throw DbException.getInternalError("type=" + rType);
}
return ValueTime.fromNanos(getTimeWithInterval(r, ((ValueTime) l).getNanos()));
case Value.TIME_TZ:
{
if (DataType.isYearMonthIntervalType(rType)) {
throw DbException.getInternalError("type=" + rType);
}
ValueTimeTimeZone t = (ValueTimeTimeZone) l;
return ValueTimeTimeZone.fromNanos(getTimeWithInterval(r, t.getNanos()), t.getTimeZoneOffsetSeconds());
}
case Value.DATE:
case Value.TIMESTAMP:
case Value.TIMESTAMP_TZ:
if (DataType.isYearMonthIntervalType(rType)) {
long m = IntervalUtils.intervalToAbsolute((ValueInterval) r).longValue();
if (opType == IntervalOpType.DATETIME_MINUS_INTERVAL) {
m = -m;
}
return DateTimeFunction.dateadd(session, DateTimeFunction.MONTH, m, l);
} else {
BigInteger a2 = IntervalUtils.intervalToAbsolute((ValueInterval) r);
if (lType == Value.DATE) {
BigInteger a1 = BigInteger.valueOf(absoluteDayFromDateValue(((ValueDate) l).getDateValue()));
a2 = a2.divide(NANOS_PER_DAY_BI);
BigInteger n = opType == IntervalOpType.DATETIME_PLUS_INTERVAL ? a1.add(a2) : a1.subtract(a2);
return ValueDate.fromDateValue(dateValueFromAbsoluteDay(n.longValue()));
} else {
long[] a = dateAndTimeFromValue(l, session);
long absoluteDay = absoluteDayFromDateValue(a[0]);
long timeNanos = a[1];
BigInteger[] dr = a2.divideAndRemainder(NANOS_PER_DAY_BI);
if (opType == IntervalOpType.DATETIME_PLUS_INTERVAL) {
absoluteDay += dr[0].longValue();
timeNanos += dr[1].longValue();
} else {
absoluteDay -= dr[0].longValue();
timeNanos -= dr[1].longValue();
}
if (timeNanos >= NANOS_PER_DAY) {
timeNanos -= NANOS_PER_DAY;
absoluteDay++;
} else if (timeNanos < 0) {
timeNanos += NANOS_PER_DAY;
absoluteDay--;
}
return dateTimeToValue(l, dateValueFromAbsoluteDay(absoluteDay), timeNanos);
}
}
}
throw DbException.getInternalError("type=" + opType);
}
use of org.gridgain.internal.h2.value.ValueDate in project SpringStudy by myounghaklee.
the class TestTimeStampWithTimeZone method testConversionsImpl.
private void testConversionsImpl(String timeStr, boolean testReverse, CastDataProvider provider) {
ValueTimestamp ts = ValueTimestamp.parse(timeStr, null);
ValueDate d = ts.convertToDate(provider);
ValueTime t = (ValueTime) ts.convertTo(TypeInfo.TYPE_TIME, provider);
ValueTimestampTimeZone tstz = ValueTimestampTimeZone.parse(timeStr, null);
assertEquals(ts, tstz.convertTo(TypeInfo.TYPE_TIMESTAMP, provider));
assertEquals(d, tstz.convertToDate(provider));
assertEquals(t, tstz.convertTo(TypeInfo.TYPE_TIME, provider));
assertEquals(LegacyDateTimeUtils.toTimestamp(provider, null, ts), LegacyDateTimeUtils.toTimestamp(provider, null, tstz));
if (testReverse) {
assertEquals(0, tstz.compareTo(ts.convertTo(TypeInfo.TYPE_TIMESTAMP_TZ, provider), null, null));
assertEquals(d.convertTo(TypeInfo.TYPE_TIMESTAMP, provider).convertTo(TypeInfo.TYPE_TIMESTAMP_TZ, provider), d.convertTo(TypeInfo.TYPE_TIMESTAMP_TZ, provider));
assertEquals(t.convertTo(TypeInfo.TYPE_TIMESTAMP, provider).convertTo(TypeInfo.TYPE_TIMESTAMP_TZ, provider), t.convertTo(TypeInfo.TYPE_TIMESTAMP_TZ, provider));
}
}
use of org.gridgain.internal.h2.value.ValueDate in project SpringStudy by myounghaklee.
the class TestDate method testDateTimeUtils.
private void testDateTimeUtils() {
TimeZone old = TimeZone.getDefault();
/*
* java.util.TimeZone doesn't support LMT, so perform this test with
* fixed time zone offset
*/
TimeZone.setDefault(TimeZone.getTimeZone("GMT+01"));
DateTimeUtils.resetCalendar();
try {
ValueTimestamp ts1 = ValueTimestamp.parse("-999-08-07 13:14:15.16", null);
ValueTimestamp ts2 = ValueTimestamp.parse("19999-08-07 13:14:15.16", null);
ValueTime t1 = (ValueTime) ts1.convertTo(TypeInfo.TYPE_TIME);
ValueTime t2 = (ValueTime) ts2.convertTo(TypeInfo.TYPE_TIME);
ValueDate d1 = ts1.convertToDate(null);
ValueDate d2 = ts2.convertToDate(null);
assertEquals("-0999-08-07 13:14:15.16", ts1.getString());
assertEquals("-0999-08-07", d1.getString());
assertEquals("13:14:15.16", t1.getString());
assertEquals("19999-08-07 13:14:15.16", ts2.getString());
assertEquals("19999-08-07", d2.getString());
assertEquals("13:14:15.16", t2.getString());
TimeZone timeZone = TimeZone.getDefault();
ValueTimestamp ts1a = LegacyDateTimeUtils.fromTimestamp(null, timeZone, LegacyDateTimeUtils.toTimestamp(null, null, ts1));
ValueTimestamp ts2a = LegacyDateTimeUtils.fromTimestamp(null, timeZone, LegacyDateTimeUtils.toTimestamp(null, null, ts2));
assertEquals("-0999-08-07 13:14:15.16", ts1a.getString());
assertEquals("19999-08-07 13:14:15.16", ts2a.getString());
} finally {
TimeZone.setDefault(old);
DateTimeUtils.resetCalendar();
}
}
use of org.gridgain.internal.h2.value.ValueDate in project SpringStudy by myounghaklee.
the class DateTimeUtils method dateAndTimeFromValue.
/**
* Extracts date value and nanos of day from the specified value.
*
* @param value
* value to extract fields from
* @param provider
* the cast information provider
* @return array with date value and nanos of day
*/
public static long[] dateAndTimeFromValue(Value value, CastDataProvider provider) {
long dateValue = EPOCH_DATE_VALUE;
long timeNanos = 0;
if (value instanceof ValueTimestamp) {
ValueTimestamp v = (ValueTimestamp) value;
dateValue = v.getDateValue();
timeNanos = v.getTimeNanos();
} else if (value instanceof ValueDate) {
dateValue = ((ValueDate) value).getDateValue();
} else if (value instanceof ValueTime) {
timeNanos = ((ValueTime) value).getNanos();
} else if (value instanceof ValueTimestampTimeZone) {
ValueTimestampTimeZone v = (ValueTimestampTimeZone) value;
dateValue = v.getDateValue();
timeNanos = v.getTimeNanos();
} else if (value instanceof ValueTimeTimeZone) {
timeNanos = ((ValueTimeTimeZone) value).getNanos();
} else {
ValueTimestamp v = (ValueTimestamp) value.convertTo(TypeInfo.TYPE_TIMESTAMP, provider);
dateValue = v.getDateValue();
timeNanos = v.getTimeNanos();
}
return new long[] { dateValue, timeNanos };
}
Aggregations