/** * Returns a Timestamp, precise to the day, 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-MM-DD}. * */ public static Timestamp forDay(int yearZ, int monthZ, int dayZ) { return new Timestamp(yearZ, monthZ, dayZ); }
/** * 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, 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); }
/** * Converts a {@link Calendar} to a Timestamp, preserving the calendar's * time zone as the equivalent local offset when it has at least minutes * precision. The given Calendar will be used to perform any arithmetic * operations on the resulting Timestamp. * * @return a Timestamp instance, with precision determined by the smallest * field set in the {@code Calendar}; * or {@code null} if {@code calendar} is {@code null} * */ public static Timestamp forCalendar(Calendar calendar) { if (calendar == null) return null; return new Timestamp(calendar); }
/** * Returns a Timestamp, precise to the minute, with a given 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-MM-DDThh:mm+-oo:oo}, where {@code oo:oo} represents the * hour and minutes of the local offset from UTC. * * @param offset * the local offset from UTC, measured in minutes; * may be {@code null} to represent an unknown local offset * */ public static Timestamp forMinute(int year, int month, int day, int hour, int minute, Integer offset) { return new Timestamp(year, month, day, hour, minute, offset); }
/** * Returns a Timestamp, precise to the second, with a given 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-MM-DDThh:mm:ss+-oo:oo}, where {@code oo:oo} represents the * hour and minutes of the local offset from UTC. * * @param offset * the local offset from UTC, measured in minutes; * may be {@code null} to represent an unknown local offset * */ public static Timestamp forSecond(int year, int month, int day, int hour, int minute, int second, Integer offset) { return new Timestamp(year, month, day, hour, minute, second, offset); }
/** * Returns a Timestamp that represents the point in time that is * {@code millis} milliseconds from the epoch, with a given local offset. * A default {@link GregorianCalendar} will be used to perform any * arithmetic operations on the resulting Timestamp. * <p> * <strong>NOTE:</strong> this means that providing a number of milliseconds * that was produced using a different calendar system may result in a Timestamp * that represents a different point in time than the one that originally * produced the milliseconds. In this case, {@link #forCalendar(Calendar)} should * be used instead. * <p> * The resulting Timestamp will be precise to the millisecond. * * @param millis * the number of milliseconds from the epoch (1970-01-01T00:00:00.000Z). * @param localOffset * the local offset from UTC, measured in minutes; * may be {@code null} to represent an unknown local offset. * */ public static Timestamp forMillis(long millis, Integer localOffset) { return new Timestamp(millis, localOffset); }
/** * Creates a copy of this Timestamp. The resulting Timestamp will * represent the same point in time, have the same precision and local * offset, and use the same calendar system for date arithmetic. * <p> * {@inheritDoc} */ @Override public Timestamp clone() { return new Timestamp((Calendar) _calendar.clone(), _precision, _fraction, _offset); }
/** * Returns a Timestamp representing the current time (based on the JVM * clock), with an unknown local offset. A default {@link GregorianCalendar} * will be used to perform any arithmetic operations on the resulting Timestamp. * <p> * The resulting Timestamp will be precise to the millisecond. * * @return * a new Timestamp instance representing the current time. */ public static Timestamp now() { long millis = System.currentTimeMillis(); return new Timestamp(millis, UNKNOWN_OFFSET); }
/** * Returns a Timestamp in UTC representing the current time (based on the * the JVM clock). A default {@link GregorianCalendar} will be used to perform * any arithmetic operations on the resulting Timestamp. * <p> * The resulting Timestamp will be precise to the millisecond. * * @return * a new Timestamp instance, in UTC, representing the current * time. * */ public static Timestamp nowZ() { long millis = System.currentTimeMillis(); return new Timestamp(millis, UTC_OFFSET); }
/** * Converts a {@link Date} to a Timestamp in UTC representing the same * point in time. A default {@link GregorianCalendar} will be used to perform * any arithmetic operations on the resulting Timestamp. * <p> * The resulting Timestamp will be precise to the millisecond. * * @return * a new Timestamp instance, in UTC, precise to the millisecond; * {@code null} if {@code date} is {@code null} * */ public static Timestamp forDateZ(Date date) { if (date == null) return null; long millis = date.getTime(); return new Timestamp(millis, UTC_OFFSET); }
return new Timestamp(millis, localOffset);
/** * Returns a Timestamp, precise to the second, with a given 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-MM-DDThh:mm:ss.sss+-oo:oo}, where {@code oo:oo} represents * the hour and minutes of the local offset from UTC. * * @param second must be at least zero and less than 60. * Must not be null. * * @param offset * the local offset from UTC, measured in minutes; * may be {@code null} to represent an unknown local offset * */ public static Timestamp forSecond(int year, int month, int day, int hour, int minute, BigDecimal second, Integer offset) { // Tease apart the whole and fractional seconds. // Storing them separately is silly. int s = second.intValue(); BigDecimal frac = second.subtract(BigDecimal.valueOf(s)); return new Timestamp(Precision.SECOND, year, month, day, hour, minute, s, frac, offset, APPLY_OFFSET_YES); }
Integer offset) return new Timestamp(p, zyear, zmonth, zday, zhour, zminute, zsecond, frac, offset, APPLY_OFFSET_NO);
/** * Converts a {@link java.sql.Timestamp} to a Timestamp in UTC representing * the same point in time. A default {@link GregorianCalendar} will be used to perform * any arithmetic operations on the resulting Timestamp. * <p> * The resulting Timestamp will be precise to the nanosecond. * * @param sqlTimestamp assumed to have nanoseconds precision * * @return * a new Timestamp instance, in UTC, precise to the * nanosecond * {@code null} if {@code sqlTimestamp} is {@code null} * */ public static Timestamp forSqlTimestampZ(java.sql.Timestamp sqlTimestamp) { if (sqlTimestamp == null) return null; long millis = sqlTimestamp.getTime(); Timestamp ts = new Timestamp(millis, UTC_OFFSET); int nanos = sqlTimestamp.getNanos(); BigDecimal frac = BigDecimal.valueOf(nanos).movePointLeft(9); ts._fraction = frac; return ts; }
/** * 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); }
/** * Returns a Timestamp, precise to the month, with unknown local offset. * <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, precise to the year, with unknown local offset. * <p> * This is equivalent to the corresponding Ion value {@code YYYYT}. */ public static Timestamp forYear(int yearZ) { return new Timestamp(yearZ); }
/** * Returns a Timestamp, precise to the year, with unknown local offset. * <p> * This is equivalent to the corresponding Ion value {@code YYYYT}. */ public static Timestamp forYear(int yearZ) { return new Timestamp(yearZ); }
new Timestamp(precision, year, month, day, hour, minute, seconds, fraction, offset, APPLY_OFFSET_YES); return ts;