Search in sources :

Example 1 with ValueDate

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 };
}
Also used : ValueTime(org.h2.value.ValueTime) ValueTimestamp(org.h2.value.ValueTimestamp) ValueTimestampTimeZone(org.h2.value.ValueTimestampTimeZone) ValueDate(org.h2.value.ValueDate) ValueTimeTimeZone(org.h2.value.ValueTimeTimeZone)

Example 2 with ValueDate

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);
}
Also used : ValueTime(org.h2.value.ValueTime) BigInteger(java.math.BigInteger) ValueDate(org.h2.value.ValueDate) ValueTimeTimeZone(org.h2.value.ValueTimeTimeZone) ValueInterval(org.h2.value.ValueInterval)

Example 3 with ValueDate

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));
    }
}
Also used : ValueTime(org.h2.value.ValueTime) ValueTimestamp(org.h2.value.ValueTimestamp) ValueTimestampTimeZone(org.h2.value.ValueTimestampTimeZone) ValueDate(org.h2.value.ValueDate)

Example 4 with ValueDate

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();
    }
}
Also used : ValueTime(org.h2.value.ValueTime) TimeZone(java.util.TimeZone) ValueTimestampTimeZone(org.h2.value.ValueTimestampTimeZone) ValueTimestamp(org.h2.value.ValueTimestamp) ValueDate(org.h2.value.ValueDate)

Example 5 with ValueDate

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 };
}
Also used : ValueTime(org.h2.value.ValueTime) ValueTimestamp(org.h2.value.ValueTimestamp) ValueTimestampTimeZone(org.h2.value.ValueTimestampTimeZone) ValueDate(org.h2.value.ValueDate) ValueTimeTimeZone(org.h2.value.ValueTimeTimeZone)

Aggregations

ValueDate (org.h2.value.ValueDate)23 ValueTime (org.h2.value.ValueTime)18 ValueTimestampTimeZone (org.h2.value.ValueTimestampTimeZone)16 ValueTimestamp (org.h2.value.ValueTimestamp)15 BigDecimal (java.math.BigDecimal)10 ValueTimeTimeZone (org.h2.value.ValueTimeTimeZone)10 BigInteger (java.math.BigInteger)9 ValueDate (org.gridgain.internal.h2.value.ValueDate)9 ValueTime (org.gridgain.internal.h2.value.ValueTime)9 Value (org.gridgain.internal.h2.value.Value)8 ValueTimestamp (org.gridgain.internal.h2.value.ValueTimestamp)8 ValueTimestampTimeZone (org.gridgain.internal.h2.value.ValueTimestampTimeZone)8 ValueInterval (org.gridgain.internal.h2.value.ValueInterval)6 TypeInfo (org.gridgain.internal.h2.value.TypeInfo)4 ValueInterval (org.h2.value.ValueInterval)4 ResultInterface (org.gridgain.internal.h2.result.ResultInterface)3 ValueLobDb (org.gridgain.internal.h2.value.ValueLobDb)3 ValueString (org.gridgain.internal.h2.value.ValueString)3 Value (org.h2.value.Value)3 Date (java.sql.Date)2