public class SFTimestamp extends SFInstant implements Comparable<SFTimestamp>
| Modifier and Type | Class and Description |
|---|---|
static class |
SFTimestamp.TimestampOperationNotAvailableException
Thrown when a Snowflake timestamp cannot be manipulated in Java due to
size limitations.
|
| Modifier and Type | Field and Description |
|---|---|
static SFTimestamp |
MAX_VALID_VALUE |
static SFTimestamp |
MIN_VALID_VALUE |
DAY_OF_WEEK_ISO, GMT, POWERS_OF_TEN, WEEK_ISO, YEAR_OF_WEEK, YEAR_OF_WEEK_ISO| Constructor and Description |
|---|
SFTimestamp()
Empty constructor, will create a timestamp at this instant
|
SFTimestamp(SFDate date)
Constructs an SFTimestamp from SFDate.
|
SFTimestamp(SFTimestamp sft)
Copy constructor.
|
SFTimestamp(Timestamp ts)
Constructs an SFTimestamp from a java Timestamp.
|
SFTimestamp(Timestamp ts,
TimeZone tz)
Constructs an SFTimestamp from a java Timestamp and java TimeZone.
|
| Modifier and Type | Method and Description |
|---|---|
SFTimestamp |
adjustScale(int scale)
Adjusts fractional second accuracy if necessary.
|
SFTimestamp |
changeTimeZone(TimeZone timeZone)
Returns a new SFTimestamp object, with specified timeZone set in it.
|
int |
compareTo(SFTimestamp other)
Compares with other SFTimestamp
|
static TimeZone |
convertTimezoneIndexToTimeZone(int timezoneIndex)
Convert a timezone index to timezone.
|
boolean |
equals(Object o) |
boolean |
equals(SFTimestamp other)
Checks if equals with other SFTimestamp
|
int |
extract(int field,
Integer optWeekStart,
Integer optWoyPolicy)
Extract a particular component of a date.
|
static SFTimestamp |
fromBinary(BigDecimal binary,
int scale,
TimeZone tz)
Constructs an SFTimestamp from a binary representation
|
static SFTimestamp |
fromDate(Date date,
int nanos,
TimeZone tz)
Constructs an SF timestamp from a Date and a number of nanoseconds.
|
static SFTimestamp |
fromMilliseconds(long ms,
TimeZone tz)
Constructs an SF timestamp from a given number of UTC milliseconds
and an originating timezone.
|
static SFTimestamp |
fromNanoseconds(BigDecimal ns)
Constructs an SF timestamp from a given number of UTC nanoseconds,
using the GMT timezone.
|
static SFTimestamp |
fromNanoseconds(BigDecimal ns,
TimeZone tz)
Constructs an SF timestamp from a given number of UTC nanoseconds,
using the specified timezone
|
static SFTimestamp |
fromNanoseconds(long ns,
TimeZone tz)
Constructs an SF timestamp from a given number of UTC nanoseconds
and an originating timezone.
|
static SFTimestamp |
fromSFDate(SFDate sfd,
TimeZone tz)
Constructs an SF timestamp from an SF date,
|
int |
getNanos()
Returns the fractional seconds component of this timestamp, i.e.
|
BigDecimal |
getNanosSinceEpoch() |
BigInteger |
getSeconds()
Returns the integral seconds component of this timestamp.
|
long |
getTime()
Returns epoch time in milliseconds as a long.
|
BigInteger |
getTimeInMsBigInt()
Returns the epoch time in milliseconds.
|
Timestamp |
getTimestamp()
Convert this to a Java timestamp.
|
TimeZone |
getTimeZone()
Returns Timezone
|
int |
getTimeZoneOffsetMillis()
Calculates the offset of this timestamp's time zone at this timestamp's
time instant.
|
int |
hashCode() |
SFTimestamp |
moveToTimeZone(TimeZone newTimeZone)
Moves the timestamp to another time zone without changing its displayed value.
|
SFTimestamp |
moveToTimeZone(TimeZone newTimeZone,
boolean cCompatibility)
Moves the timestamp to another time zone without changing its displayed value.
|
BigInteger |
toBinary(int scale,
boolean includeTimeZone)
Constructs a binary representation of this timestamp.
|
String |
toString() |
String |
toUTCString()
Returns UTC string
|
public static final SFTimestamp MIN_VALID_VALUE
public static final SFTimestamp MAX_VALID_VALUE
public SFTimestamp(Timestamp ts, TimeZone tz)
ts - timestamptz - timezonepublic SFTimestamp(Timestamp ts)
ts - Java timestamppublic SFTimestamp(SFDate date)
date - SFDate instancepublic SFTimestamp()
public SFTimestamp(SFTimestamp sft)
original is needed, use of this
constructor is unnecessary since SFTimestamps are immutable.sft - source SFTimestamp instancepublic static SFTimestamp fromMilliseconds(long ms, TimeZone tz)
ms - millisecondstz - timezonepublic static SFTimestamp fromNanoseconds(long ns, TimeZone tz)
ns - nanosecondstz - timezonepublic static SFTimestamp fromNanoseconds(BigDecimal ns, TimeZone tz)
ns - nanoseconds in BigDecimaltz - timezonepublic static SFTimestamp fromNanoseconds(BigDecimal ns)
ns - nanoseconds in BigDecimalpublic static TimeZone convertTimezoneIndexToTimeZone(int timezoneIndex)
timezoneIndex - timezone index where 1440 is UTCpublic static SFTimestamp fromBinary(BigDecimal binary, int scale, TimeZone tz)
binary - Physical representation, consists of UTC fractions
(scaled decimals) and optional timezone indexscale - Scale of fractional secondstz - If specified, TimeZone to use.
If null, we'll assume the timezone is embedded in the numberpublic static SFTimestamp fromDate(Date date, int nanos, TimeZone tz)
date - date instancenanos - nanosecondstz - timezonepublic static SFTimestamp fromSFDate(SFDate sfd, TimeZone tz)
sfd - SFDate representing a date.
Note - it's always UTC milliseconds.tz - timezonepublic BigDecimal getNanosSinceEpoch()
public Timestamp getTimestamp() throws SFTimestamp.TimestampOperationNotAvailableException
SFTimestamp.TimestampOperationNotAvailableException - if this timestamp doesn't fit
in a Java timestamppublic TimeZone getTimeZone()
public SFTimestamp changeTimeZone(TimeZone timeZone)
timeZone - the timezone for this timestamppublic SFTimestamp moveToTimeZone(TimeZone newTimeZone) throws SFTimestamp.TimestampOperationNotAvailableException
newTimeZone - a target TimezoneSFTimestamp.TimestampOperationNotAvailableException - if this timestamp doesn't fit
into a Java timestamppublic SFTimestamp moveToTimeZone(TimeZone newTimeZone, boolean cCompatibility) throws SFTimestamp.TimestampOperationNotAvailableException
newTimeZone - a target TimezonecCompatibility - corrects incompatibilities between Java and C libraries for timestamps
that are ambiguous (e.g. '2016-11-06 01:30') or illegal (e.g. '2016-03-13
02:30') due to DST rules.SFTimestamp.TimestampOperationNotAvailableException - if this timestamp doesn't fit
into a Java timestamppublic SFTimestamp adjustScale(int scale)
scale - scalepublic String toUTCString()
public int compareTo(SFTimestamp other)
compareTo in interface Comparable<SFTimestamp>other - target SFTimestamppublic boolean equals(SFTimestamp other)
other - target SFTimestamppublic long getTime()
throws SFTimestamp.TimestampOperationNotAvailableException
SFTimestamp.TimestampOperationNotAvailableException - if this timestamp doesn't fit
into a Java timestamppublic BigInteger getTimeInMsBigInt()
public BigInteger getSeconds()
public int getNanos()
public int getTimeZoneOffsetMillis()
public BigInteger toBinary(int scale, boolean includeTimeZone)
scale - scale of fractional secondsincludeTimeZone - encode the time zone in the lower-order bitspublic int extract(int field,
Integer optWeekStart,
Integer optWoyPolicy)
throws SFTimestamp.TimestampOperationNotAvailableException
extract in class SFInstantfield - field id as specified in the Calendar class.
TODO: we don't support e.g. nanosecond nor timezones for nowSFTimestamp.TimestampOperationNotAvailableException - if this timestamp doesn't fit
into a Java timestampCopyright © 2020. All rights reserved.