Top Description Inners Fields Constructors Methods
com.amazon.ion

public final Class Timestamp

extends Object
implements Comparable<Timestamp>, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.lang.Comparable
Static Imports
com.amazon.ion.impl._Private_Utils.safeEquals, com.amazon.ion.util.IonTextUtils.printCodePointAsString

An immutable representation of a point in time. Ion defines a simple representation of time based on Coordinated Universal Time (UTC). In practice the use of time could be more accurately described as UTC-SLS (UTC Smoothed Leap Seconds) as there is no representation for the leap second discontinuities that UTC has added.

Timestamps preserve precision, meaning the fields that are included, and the significant digits of any fractional second. Only common break points in the values are supported. Any unspecified fields are handled as the start of the new year/month/day.

Equality and Comparison

As with IonValue classes, the equals methods on this class perform a strict equivalence that observes the precision and local offset of each timestamp. This means that it's possible to have two Timestamp instances that represent the same point in time but are not equals.

On the other hand, the compareTo methods perform point in time comparison, ignoring precision and local offset. Thus the natural comparison method of this class is not consistent with equals. See the documentation of Comparable for further discussion.

To illustrate this distinction, consider the following timestamps. None are equals to each other, but any pair will return a zero result from compareTo.

See Also
equals(Timestamp), compareTo(Timestamp)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Timestamp.Precision

The precision of the Timestamp.

Field Summary

Modifier and TypeField and Description
private byte
private BigDecimal
private byte
private byte
private byte
private Integer
_offset

Minutes offset from UTC; zero means UTC proper, null means that the offset is unknown.

private Timestamp.Precision
_precision

The precision of the Timestamp.

private byte
private short
private static final boolean
private static final boolean
private static final boolean
private static final boolean
public static final int
DEFAULT_MAXIMUM_DIGITS_TEXT

The default maximum number of digits in the fractional component that will be written when a text representation of a timestamp is requested.

pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int[]
pack-priv static final int
pack-priv static final BigDecimal
MAXIMUM_ALLOWED_TIMESTAMP_IN_MILLIS_DECIMAL

10000T in millis, upper bound exclusive.

pack-priv static final long
MAXIMUM_TIMESTAMP_IN_EPOCH_SECONDS

10000T in epoch seconds, upper bound exclusive.

pack-priv static final long
MAXIMUM_TIMESTAMP_IN_MILLIS

10000T in millis, upper bound exclusive.

pack-priv static final long
MINIMUM_TIMESTAMP_IN_EPOCH_SECONDS

0001-01-01T00:00:00.0Z epoch seconds.

pack-priv static final long
MINIMUM_TIMESTAMP_IN_MILLIS

0001-01-01T00:00:00.0Z in millis.

pack-priv static final BigDecimal
MINIMUM_TIMESTAMP_IN_MILLIS_DECIMAL

0001-01-01T00:00:00.0Z in millis.

private static final int
private static final BigDecimal
private static final int
private static final int
private static final int
private static final int
private static final int[]
pack-priv static final String
public static final Integer
UNKNOWN_OFFSET

Unknown local offset from UTC.

public static final Integer
UTC_OFFSET

Local offset of zero hours from UTC.

Constructor Summary

AccessConstructor and Description
private
Timestamp(int zyear)

Creates a new Timestamp, precise to the year, with unknown local offset.

private
Timestamp(int zyear, int zmonth)

Creates a new Timestamp, precise to the month, with unknown local offset.

public
Timestamp(int zyear, int zmonth, int zday)
Deprecated Use forDay(int, int, int) instead.

Creates a new Timestamp, precise to the day, with unknown local offset.

public
Timestamp(int year, int month, int day, int hour, int minute, Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset
offset
)

Creates a new Timestamp, precise to the minute, with a given local offset.

public
Timestamp(int year, int month, int day, int hour, int minute, int second, Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset.
offset
)

Creates a new Timestamp, precise to the second, with a given local offset.

public
Timestamp(int year, int month, int day, int hour, int minute, int second, BigDecimal
the fractional seconds; must not be null; if negative, its absolute value is used
frac
,
Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset
offset
)

Creates a new Timestamp, precise to the second or fractional second, with a given local offset.

private
Timestamp(Timestamp.Precision p, int zyear, int zmonth, int zday, int zhour, int zminute, int zsecond, BigDecimal
must be >= 0 and < 1
frac
,
Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset
offset
,
boolean shouldApplyOffset, boolean shouldCheckFraction)

Creates a new Timestamp from the individual time components.

public
Timestamp(Calendar cal)
Deprecated Use forCalendar(Calendar) instead.

Creates a new Timestamp from a Calendar, preserving the Calendar's precision and local offset from UTC.

private
Timestamp(Calendar cal, Timestamp.Precision precision, BigDecimal fraction, Integer offset)

private
Timestamp(BigDecimal millis, Timestamp.Precision precision, Integer localOffset)

public
Timestamp(BigDecimal
number of milliseconds (including any fractional milliseconds) from the epoch (1970-01-01T00:00:00.000Z); must not be null
millis
,
Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset
localOffset
)
Deprecated Use forMillis(BigDecimal, Integer) instead.

Creates a new Timestamp that represents the point in time that is millis milliseconds (including any fractional milliseconds) from the epoch, with a given local offset.

public
Timestamp(long
number of milliseconds from the epoch (1970-01-01T00:00:00.000Z)
millis
,
Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset.
localOffset
)
Deprecated Use forMillis(long, Integer) instead.

Creates a new Timestamp that represents the point in time that is millis milliseconds from the epoch, with a given local offset.

Method Summary

Modifier and TypeMethod and Description
public final Timestamp
addDay(int
a number of days.
amount
)

Returns a timestamp relative to this one by the given number of days.

public final Timestamp
addHour(int
a number of hours.
amount
)

Returns a timestamp relative to this one by the given number of hours.

public final Timestamp
addMillis(long
a number of milliseconds.
amount
)

Returns a timestamp relative to this one by the given number of milliseconds.

private Timestamp

Returns:

a new Timestamp.
addMillisForPrecision
(long
the number of milliseconds to add.
amount
,
Timestamp.Precision
the precision that the Timestamp will be extended to, if it does not already include that precision.
precision
,
boolean
true if and only if the `amount` includes milliseconds precision. If true, the resulting timestamp's fraction will have precision at least to the millisecond.
millisecondsPrecision
)

Adds the given number of milliseconds, extending (if necessary) the resulting Timestamp to the given precision.

public final Timestamp
addMinute(int
a number of minutes.
amount
)

Returns a timestamp relative to this one by the given number of minutes.

public final Timestamp
addMonth(int
a number of months.
amount
)

Returns a timestamp relative to this one by the given number of months.

private Timestamp

Returns:

a new Timestamp.
addMonthForPrecision
(int
the number of months to add.
amount
,
Timestamp.Precision
the precision that the Timestamp will be extended to, if it does not already include that precision.
precision
)

Adds the given number of months, extending (if necessary) the resulting Timestamp to the given precision.

public final Timestamp
addSecond(int
a number of seconds.
amount
)

Returns a timestamp relative to this one by the given number of seconds.

public final Timestamp
addYear(int
a number of years.
amount
)

Returns a timestamp relative to this one by the given number of years.

public final Timestamp
adjustDay(int
a number of days.
amount
)

Returns a timestamp relative to this one by the given number of days.

public final Timestamp
adjustHour(int
a number of hours.
amount
)

Returns a timestamp relative to this one by the given number of hours.

public final Timestamp
adjustMillis(long
a number of milliseconds.
amount
)

Returns a timestamp relative to this one by the given number of milliseconds.

public final Timestamp
adjustMinute(int
a number of minutes.
amount
)

Returns a timestamp relative to this one by the given number of minutes.

public final Timestamp
adjustMonth(int
a number of months.
amount
)

Returns a timestamp relative to this one by the given number of months.

public final Timestamp
adjustSecond(int
a number of seconds.
amount
)

Returns a timestamp relative to this one by the given number of seconds.

public final Timestamp
adjustYear(int
a number of years.
amount
)

Returns a timestamp relative to this one by the given number of years.

private void
apply_offset(int
the local offset, in minutes from UTC.
offset
)

Applies the local time zone offset from UTC to the applicable time field values.

public Calendar

Returns:

a new Calendar instance, in its local time.
calendarValue
()

Converts the value of this Timestamp as a Calendar, in its local time.

private static byte
checkAndCastDay(int day, int year, int month)

private static byte
checkAndCastHour(int hour)

private static byte
checkAndCastMinute(int minute)

private static byte
checkAndCastMonth(int month)

private static byte
checkAndCastSecond(int second)

private static short
checkAndCastYear(int year)

private static Timestamp.Precision
private void
clearUnusedPrecision()

Clears any fields more precise than this Timestamp's precision supports.

public Timestamp
clone()

Overrides java.lang.Object.clone.

Creates a copy of this Timestamp.

public int

Returns:

-1, 0, or 1 if this Timestamp is less than, equal to, or greater than t respectively
compareTo
(Timestamp
the other Timestamp to compare this Timestamp to
t
)

Implements java.lang.Comparable.compareTo.

Performs a comparison of the two points in time represented by two Timestamps.

public static Timestamp
createFromUtcFields(Timestamp.Precision
the desired timestamp precision. The result may have a different precision if the input data isn't precise enough.
p
,
int zyear, int zmonth, int zday, int zhour, int zminute, int zsecond, BigDecimal frac, Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset.
offset
)
Deprecated

Creates a new Timestamp from the individual time components.

public Date

Returns:

a new Date instance, in UTC
dateValue
()

Converts the value of this Timestamp into a Date, representing the time in UTC.

public boolean
equals(Object
the reference object with which to compare.
t
)

Overrides java.lang.Object.equals.

Compares this Timestamp to the specified Object.

public boolean
equals(Timestamp t)

Compares this Timestamp to another Timestamp object.

private static IllegalArgumentException
fail(CharSequence input, String reason)

private static IllegalArgumentException
private BigDecimal
public static Timestamp

Returns:

a Timestamp instance, with precision determined by the smallest field set in the Calendar; or null if calendar is null
forCalendar
(Calendar calendar)

Converts a Calendar to a Timestamp, preserving the calendar's time zone as the equivalent local offset when it has at least minutes precision.

public static Timestamp

Returns:

a new Timestamp instance, in UTC, precise to the millisecond; null if date is null
forDateZ
(Date date)

Converts a Date to a Timestamp in UTC representing the same point in time.

public static Timestamp
forDay(int yearZ, int monthZ, int dayZ)

Returns a Timestamp, precise to the day, with unknown local offset.

public static Timestamp
forEpochSecond(long
The number of seconds from the unix epoch (1970-01-01T00:00:00.000Z) UTC.
seconds
,
int
The number of nanoseconds for the fractional component. Must be between 0 and 999,999,999.
nanoOffset
,
Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset.
localOffset
)

Returns a Timestamp that represents the point in time that is seconds from the unix epoch (1970-01-01T00:00:00.000Z), with the nanoOffset applied and a given local offset.

public static Timestamp
forMillis(long
the number of milliseconds from the epoch (1970-01-01T00:00:00.000Z) in UTC.
millis
,
Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset.
localOffset
)

Returns a Timestamp that represents the point in time that is millis milliseconds from the epoch, with a given local offset.

public static Timestamp
forMillis(BigDecimal
number of milliseconds (including any fractional milliseconds) from the epoch (1970-01-01T00:00:00.000Z); must not be null
millis
,
Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset
localOffset
)

The same as forMillis(long, Integer) but the millisecond component is specified using a BigDecimal and therefore may include fractional milliseconds.

public static Timestamp
forMinute(int year, int month, int day, int hour, int minute, Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset
offset
)

Returns a Timestamp, precise to the minute, with a given local offset.

public static Timestamp
forMonth(int yearZ, int monthZ)

Returns a Timestamp, precise to the month, with unknown local offset.

public static Timestamp
forSecond(int year, int month, int day, int hour, int minute, int second, Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset
offset
)

Returns a Timestamp, precise to the second, with a given local offset.

public static Timestamp
forSecond(int year, int month, int day, int hour, int minute, BigDecimal
must be at least zero and less than 60. Must not be null.
second
,
Integer
the local offset from UTC, measured in minutes; may be null to represent an unknown local offset
offset
)

Returns a Timestamp, precise to the second, with a given local offset.

public static Timestamp

Returns:

a new Timestamp instance, in UTC, precise to the nanosecond null if sqlTimestamp is null
forSqlTimestampZ
(java.sql.Timestamp
assumed to have nanoseconds precision
sqlTimestamp
)

Converts a java.sql.Timestamp to a Timestamp in UTC representing the same point in time.

public static Timestamp
forYear(int yearZ)

Returns a Timestamp, precise to the year, with unknown local offset.

public int

Returns:

a number within the range [1, 31], in its local time; 1 is returned if the Timestamp isn't precise to the day
getDay
()

Returns the day (within the month) of this Timestamp, in its local time.

public BigDecimal

Returns:

number of milliseconds (including any fractional milliseconds) from the epoch (1970-01-01T00:00:00.000Z)
getDecimalMillis
()

Returns a BigDecimal representing the Timestamp's point in time that is the number of milliseconds (including any fractional milliseconds) from the epoch.

public BigDecimal

Returns:

a number within the range [0, 60); 0 is returned if the Timestamp isn't precise to the second
getDecimalSecond
()

Returns the seconds of this Timestamp.

public BigDecimal

Returns:

a BigDecimal within the range [0, 1); null is returned if the Timestamp isn't precise to the fractional second
getFractionalSecond
()
Deprecated

Returns the fractional second of this Timestamp.

public int

Returns:

a number within the range [0, 23], in its local time; 0 is returned if the Timestamp isn't precise to the hour
getHour
()

Returns the hour of this Timestamp, in its local time.

public Integer

Returns:

null if the local offset is unknown (i.e. -00:00)
getLocalOffset
()

Returns the offset of this Timestamp, measured in minutes, for the local timezone in UTC.

public long

Returns:

number of milliseconds (ignoring any fractional milliseconds) from the epoch (1970-01-01T00:00:00.000Z)
getMillis
()

Returns a number representing the Timestamp's point in time that is the number of milliseconds (ignoring any fractional milliseconds) from the epoch.

public int

Returns:

a number within the range [0, 59], in its local time; 0 is returned if the Timestamp isn't precise to the minute
getMinute
()

Returns the minute of this Timestamp, in its local time.

public int

Returns:

a number within the range [1, 12], whereby 1 refers to January and 12 refers to December, in its local time; 1 is returned if the Timestamp isn't precise to the month
getMonth
()

Returns the month of this Timestamp, in its local time.

public Timestamp.Precision
getPrecision()

Returns the precision of this Timestamp.

public int

Returns:

a number within the range [0, 59]; 0 is returned if the Timestamp isn't precise to the second
getSecond
()

Returns the seconds of this Timestamp, truncated to an integer.

public int

Returns:

a number within the range [1, 9999], in its local time
getYear
()

Returns the year of this Timestamp, in its local time.

public int

Returns:

a number within the range [1, 31], in UTC; 1 is returned if the Timestamp isn't precise to the day
getZDay
()

Returns the day of this Timestamp, in UTC.

public BigDecimal

Returns:

a number within the range [0, 60); 0 is returned if the Timestamp isn't precise to the second
getZDecimalSecond
()

Returns the seconds of this Timestamp.

public BigDecimal

Returns:

a BigDecimal within the range [0, 1); null is returned if the Timestamp isn't precise to the fractional second
getZFractionalSecond
()
Deprecated Use getZDecimalSecond() instead.

Returns the fractional second of this Timestamp.

public int

Returns:

a number within the range [0, 23], in UTC; 0 is returned if the Timestamp isn't precise to the hour
getZHour
()

Returns the hour of this Timestamp, in UTC.

public int

Returns:

a number within the range [0, 59], in UTC; 0 is returned if the Timestamp isn't precise to the minute
getZMinute
()

Returns the minute of this Timestamp, in UTC.

public int

Returns:

a number within the range [1, 12], whereby 1 refers to January and 12 refers to December, in UTC; 1 is returned if the Timestamp isn't precise to the month
getZMonth
()

Returns the month of this Timestamp, in UTC.

public int

Returns:

a number within the range [0, 59]; 0 is returned if the Timestamp isn't precise to the second
getZSecond
()

Returns the second of this Timestamp.

public int

Returns:

a number within the range [1, 9999], in UTC
getZYear
()

Returns the year of this Timestamp, in UTC.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code consistent with equals(Object).

private boolean
isIntegralZero(final BigDecimal decimal)

private static boolean
private static byte
last_day_in_month(int year, int month)

private Timestamp

Returns:

a new Timestamp in its local time
make_localtime
()

Applies the local offset from UTC to each of the applicable time field values and returns the new Timestamp.

public static Timestamp

Returns:

a new Timestamp instance representing the current time.
now
()

Returns a Timestamp representing the current time (based on the JVM clock), with an unknown local offset.

public static Timestamp

Returns:

a new Timestamp instance, in UTC, representing the current time.
nowZ
()

Returns a Timestamp in UTC representing the current time (based on the the JVM clock).

public void
printZ(Appendable
not null
out
)

Prints to an Appendable the string representation (in Ion format) of this Timestamp in UTC.

private static int
read_digits(CharSequence in, int start, int length, int terminator, String field)

private static byte
requireByte(int value, String location)

private static void
requirePrecisionWithinLimit(Timestamp
a Timestamp with a non-null fraction.
value
,
int
the maximum number of digits allowed.
maximumDigits
)

Throws if the text representation of the timestamp would require more than the given number of digits in its fractional component.

private static short
requireShort(int value, String location)

private void
set_fields_from_calendar(Calendar
must have at least one field set.
cal
,
Timestamp.Precision precision, boolean setLocalOffset)

Copies data from a Calendar into this timestamp.

private void
set_fields_from_millis(long millis)

This method uses deprecated methods from java.util.Date instead of Calendar so that this code can be used (more easily) on the mobile Java platform (which has Date but does not have Calendar).

private static void
public String
toString()

Overrides java.lang.Object.toString.

Returns the string representation (in Ion format) of this Timestamp in its local time.

pack-priv String
toString(int maximumDigits)

Returns the string representation (in Ion format) of this Timestamp in its local time.

public String
toZString()

Returns the string representation (in Ion format) of this Timestamp in UTC.

public static Timestamp

Returns:

null if the CharSequence is "null.timestamp"
valueOf
(CharSequence
a sequence of characters that is the Ion representation of a Timestamp
ionFormattedTimestamp
)

Returns a new Timestamp that represents the point in time, precision and local offset defined in Ion format by the CharSequence.

public Timestamp
withLocalOffset(Integer offset)

Returns a timestamp at the same point in time, but with the given local offset.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait