@Override public Object getEmbeddedObject() throws IOException { if (currentToken != JsonToken.VALUE_EMBEDDED_OBJECT) { return null; } IonType currentType = reader.getType(); switch (currentType) { case BLOB: case CLOB: return ByteBuffer.wrap(reader.newBytes()); case TIMESTAMP: return reader.timestampValue().dateValue(); default: throw new SdkClientException(String.format("Cannot return embedded object for Ion type %s", currentType)); } }
@Override public StructuredJsonGenerator writeValue(Date date, TimestampFormat timestampFormat) { try { writer.writeTimestamp(Timestamp.forDateZ(date)); } catch (IOException e) { throw new SdkClientException(e); } return this; }
private final void fn_from_timestamp_to_string() { _string_value = _timestamp_value.toString(); add_value_type(AS_TYPE.string_value); } private final void fn_from_long_to_int() {
/** * Applies the local offset from UTC to each of the applicable time field * values and returns the new Timestamp. In short, this makes the Timestamp * represent local time. * * @return a new Timestamp in its local time */ private Timestamp make_localtime() { int offset = _offset != null ? _offset.intValue() : 0; Timestamp localtime = clone(); // explicitly apply the local offset to the time field values localtime.apply_offset(-offset); assert localtime._offset == _offset; return localtime; }
/** * Returns a timestamp at the same point in time, but with the given local * offset. If this timestamp has precision coarser than minutes, then it * is returned unchanged since such timestamps always have an unknown * offset. */ public Timestamp withLocalOffset(Integer offset) { Precision precision = getPrecision(); if (precision.alwaysUnknownOffset() || safeEquals(offset, getLocalOffset())) { return this; } return new Timestamp((Calendar) _calendar.clone(), precision, _fraction, offset); }
/** * Adds the given amount to the given {@link Calendar} field and returns a new Timestamp * with precision set to the maximum of the current precision and the given precision. * @param field the field. * @param amount an amount. * @param precision the precision corresponding to the given field. * @return a new Timestamp instance. */ private Timestamp calendarAdd(int field, int amount, Precision precision) { if (amount == 0 && _precision == precision) return this; Timestamp timestamp = make_localtime(); timestamp._calendar.add(field, amount); checkCalendarYear(timestamp._calendar); if (_offset != null) { timestamp.apply_offset(_offset); timestamp._offset = _offset; } timestamp._precision = _precision.includes(precision) ? timestamp._precision : precision; return timestamp; }
_second = checkAndCastSecond(zsecond); case MINUTE: _minute = checkAndCastMinute(zminute); _hour = checkAndCastHour(zhour); _month = checkAndCastMonth(zmonth); case YEAR: _year = checkAndCastYear(zyear); _day = checkAndCastDay(zday, zyear, zmonth); _precision = checkFraction(p, _fraction); apply_offset(offset);
_calendar.set(Calendar.SECOND, checkAndCastSecond(zsecond)); case MINUTE: _calendar.set(Calendar.MINUTE, checkAndCastMinute(zminute)); _calendar.set(Calendar.HOUR_OF_DAY, checkAndCastHour(zhour)); _calendar.set(Calendar.MONTH, checkAndCastMonth(zmonth) - 1); case YEAR: _calendar.set(Calendar.YEAR, checkAndCastYear(zyear)); checkCalendarDay(zday); _calendar.set(Calendar.DAY_OF_MONTH, zday); _precision = checkFraction(p, _fraction); apply_offset(offset);
/** * Returns a Timestamp, precise to the month, with unknown local offset. * A default {@link GregorianCalendar} will be used to perform any * arithmetic operations on the resulting Timestamp. * <p> * This is equivalent to the corresponding Ion value {@code YYYY-MMT}. */ public static Timestamp forMonth(int yearZ, int monthZ) { return new Timestamp(yearZ, monthZ); }
/** * Returns a timestamp relative to this one by the given number of * milliseconds. * * @param amount a (positive or negative) number of milliseconds. */ public final Timestamp addMillis(long amount) { if (amount == 0) return this; // This strips off the local offset, expressing our fields as if they // were UTC. BigDecimal millis = make_localtime().getDecimalMillis(); millis = millis.add(BigDecimal.valueOf(amount)); Timestamp ts = new Timestamp(millis, _precision, _offset); // Anything with courser-than-millis precision will have been extended // to 3 decimal places due to use of getDecimalMillis(). Fix that. ts._fraction = _fraction; if (_offset != null && _offset != 0) { ts.apply_offset(_offset); } return ts; }
throw fail(in); if (!isValidFollowChar(in.charAt(LEN_OF_NULL_IMAGE))) { throw fail(in); throw fail(in); throw fail(in, "year is too short (must be at least yyyyT)"); year = read_digits(in, 0, 4, -1, "year"); throw fail(in, "expected \"-\" between year and month, found " + printCodePointAsString(c)); throw fail(in, "month is too short (must be yyyy-mmT)"); month = read_digits(in, END_OF_YEAR + 1, 2, -1, "month"); throw fail(in, "expected \"-\" between month and day, found " + printCodePointAsString(c)); throw fail(in, "too short for yyyy-mm-dd"); day = read_digits(in, END_OF_MONTH + 1, 2, -1, "day"); if (length == END_OF_DAY) break; c = in.charAt(END_OF_DAY); if (c != 'T') {
public void writeTimestamp(Timestamp value) throws IOException { if (value == null) { writeNull(IonType.TIMESTAMP); return; } startValue(); if (_options._timestamp_as_millis) { long millis = value.getMillis(); _output.appendAscii(Long.toString(millis)); } else if (_options._timestamp_as_string) { // Timestamp is ASCII-safe so this is easy _output.appendAscii('"'); _output.appendAscii(value.toString()); _output.appendAscii('"'); } else { _output.appendAscii(value.toString()); } closeValue(); }
/** * Returns a timestamp relative to this one by the given number of years. * The day field may be adjusted to account for leap days. For example, * adding one year to {@code 2012-02-29} results in {@code 2013-02-28}. * * @param amount a (positive or negative) number of hours. */ public final Timestamp addYear(int amount) { if (amount == 0) return this; Calendar cal = calendarValue(); cal.add(Calendar.YEAR, amount); return new Timestamp(cal, _precision, _fraction, _offset); }
BigDecimal millis = BigDecimal.valueOf(_calendar.get(Calendar.MILLISECOND)); this._fraction = millis.movePointLeft(3); // convert to fraction checkFraction(precision, this._fraction); this.apply_offset(_offset); checkCalendarYear(_calendar);
/** * Returns a timestamp relative to this one by the given number of minutes. * * @param amount a (positive or negative) number of minutes. */ public final Timestamp addMinute(int amount) { long delta = (long) amount * 60 * 1000; return addMillis(delta); }
private Timestamp(Calendar cal, Precision precision, BigDecimal fraction, Integer offset) { set_fields_from_calendar(cal, precision, false); _fraction = fraction; if (offset != null) { _offset = offset; apply_offset(offset); } }
Timestamp localtime = new Timestamp(_precision, _year, _month, APPLY_OFFSET_NO); localtime.apply_offset(-offset);
Timestamp ts = addMillis(amount); ts._precision = _precision; ts.clearUnusedPrecision(); if (_precision.includes(Precision.SECOND)) {
_second = checkAndCastSecond(zsecond); case MINUTE: _minute = checkAndCastMinute(zminute); _hour = checkAndCastHour(zhour); _month = checkAndCastMonth(zmonth); case YEAR: _year = checkAndCastYear(zyear); _day = checkAndCastDay(zday, zyear, zmonth); _precision = checkFraction(p, _fraction); apply_offset(offset);
/** * Returns a Timestamp, precise to the year, with unknown local offset. * A default {@link GregorianCalendar} will be used to perform any * arithmetic operations on the resulting Timestamp. * <p> * This is equivalent to the corresponding Ion value {@code YYYYT}. */ public static Timestamp forYear(int yearZ) { return new Timestamp(yearZ); }