Package io.debezium.time
Class ZonedTimestamp
java.lang.Object
io.debezium.time.ZonedTimestamp
A utility for converting various Java time representations into the
STRING
representation of
the time and date in a particular time zone, and for defining a Kafka Connect Schema
for zoned timestamp values.
The ISO date-time format includes the date, time (including fractional parts), and offset from UTC, such as '2011-12-03T10:15:30+01:00'.
- Author:
- Randall Hauch
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final DateTimeFormatter
The ISO date-time format includes the date, time (including fractional parts), and offset from UTC, such as '2011-12-03T10:15:30.030431+01:00'.static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.kafka.connect.data.SchemaBuilder
builder()
Returns aSchemaBuilder
for aZonedTimestamp
.private static DateTimeFormatter
getDateTimeFormatter
(Integer fractionalWidth) Returns aDateTimeFormatter
that ensures that exactly fractionalWidth number of digits are present in the nanosecond part of the datetime.static org.apache.kafka.connect.data.Schema
schema()
Returns a Schema for aZonedTimestamp
but with all other default Schema settings.static String
toIsoString
(Object value, ZoneId defaultZone, TemporalAdjuster adjuster, Integer fractionalWidth) Get the ISO 8601 formatted representation of the givenLocalDateTime
,LocalDate
,LocalTime
,Date
,Date
,Time
,Timestamp
,OffsetTime
, orOffsetDateTime
, ignoring any date portions of the supplied value.static String
toIsoString
(Date date, ZoneId zoneId, TemporalAdjuster adjuster) Get the ISO 8601 formatted representation of the givenDate
, which contains a date but no time or timezone information.static String
toIsoString
(Time time, ZoneId zoneId, TemporalAdjuster adjuster) Get the ISO 8601 formatted representation of the givenTime
, which contains time but no date or timezone information.static String
toIsoString
(Timestamp timestamp, ZoneId zoneId, TemporalAdjuster adjuster) Get the ISO 8601 formatted representation of the givenTimestamp
, which contains a date and time but has no timezone information.static String
toIsoString
(OffsetDateTime timestamp, TemporalAdjuster adjuster) Get the ISO 8601 formatted representation of the givenOffsetDateTime
.static String
toIsoString
(OffsetTime timestamp, TemporalAdjuster adjuster) Get the ISO 8601 formatted representation of the givenOffsetTime
.static String
toIsoString
(ZonedDateTime timestamp, TemporalAdjuster adjuster, Integer fractionalWidth) Get the ISO 8601 formatted representation of the givenZonedDateTime
.static String
toIsoString
(Date timestamp, ZoneId zoneId, TemporalAdjuster adjuster) Get the ISO 8601 formatted representation of the givenDate
or one of its JDBC subclasses, using the supplied timezone information.
-
Field Details
-
FORMATTER
The ISO date-time format includes the date, time (including fractional parts), and offset from UTC, such as '2011-12-03T10:15:30.030431+01:00'. -
SCHEMA_NAME
- See Also:
-
-
Constructor Details
-
ZonedTimestamp
private ZonedTimestamp()
-
-
Method Details
-
getDateTimeFormatter
Returns aDateTimeFormatter
that ensures that exactly fractionalWidth number of digits are present in the nanosecond part of the datetime. If fractionWidth is null, thenDateTimeFormatter.ISO_OFFSET_DATE_TIME
formatter is used, which can have anywhere from 0-9 digits in the nanosecond part.- Parameters:
fractionalWidth
- the optional component that specifies the exact number of digits to be present in a zoneddatetime formatted string.- Returns:
DateTimeFormatter
containing exactly fractionalWidth number of digits in nanosecond part of the datetime. If null,DateTimeFormatter.ISO_OFFSET_DATE_TIME
formatter is used, which can have anywhere from 0-9 digits in the nanosecond part.
-
builder
public static org.apache.kafka.connect.data.SchemaBuilder builder()Returns aSchemaBuilder
for aZonedTimestamp
. You can use the resulting SchemaBuilder to set additional schema settings such as required/optional, default value, and documentation.- Returns:
- the schema builder
-
schema
public static org.apache.kafka.connect.data.Schema schema()Returns a Schema for aZonedTimestamp
but with all other default Schema settings.- Returns:
- the schema
- See Also:
-
toIsoString
public static String toIsoString(Object value, ZoneId defaultZone, TemporalAdjuster adjuster, Integer fractionalWidth) Get the ISO 8601 formatted representation of the givenLocalDateTime
,LocalDate
,LocalTime
,Date
,Date
,Time
,Timestamp
,OffsetTime
, orOffsetDateTime
, ignoring any date portions of the supplied value.- Parameters:
value
- the local or SQL date, time, or timestamp value; may not be nulldefaultZone
- the time zone that should be used by default if the value does not have timezone information; may not be nulladjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessaryfractionalWidth
- the optional component that specifies the exact number of digits to be present in a zoneddatetime formatted string.- Returns:
- the microseconds past midnight
- Throws:
IllegalArgumentException
- if the value is not an instance of the acceptable types
-
toIsoString
Get the ISO 8601 formatted representation of the givenOffsetDateTime
.- Parameters:
timestamp
- the timestamp valueadjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessary- Returns:
- the ISO 8601 formatted string
-
toIsoString
public static String toIsoString(ZonedDateTime timestamp, TemporalAdjuster adjuster, Integer fractionalWidth) Get the ISO 8601 formatted representation of the givenZonedDateTime
.- Parameters:
timestamp
- the timestamp valueadjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessaryfractionalWidth
- the optional component that specifies the exact number of digits to be present in a zoneddatetime formatted string.- Returns:
- the ISO 8601 formatted string
-
toIsoString
Get the ISO 8601 formatted representation of the givenOffsetTime
.- Parameters:
timestamp
- the timestamp valueadjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessary- Returns:
- the ISO 8601 formatted string
-
toIsoString
Get the ISO 8601 formatted representation of the givenDate
or one of its JDBC subclasses, using the supplied timezone information.- Parameters:
timestamp
- the timestamp valuezoneId
- the timezone identifier or offset where the timestamp is definedadjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessary- Returns:
- the ISO 8601 formatted string
-
toIsoString
Get the ISO 8601 formatted representation of the givenTimestamp
, which contains a date and time but has no timezone information.- Parameters:
timestamp
- the JDBC timestamp valuezoneId
- the timezone identifier or offset where the timestamp is definedadjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessary- Returns:
- the ISO 8601 formatted string
-
toIsoString
Get the ISO 8601 formatted representation of the givenDate
, which contains a date but no time or timezone information.- Parameters:
date
- the date valuezoneId
- the timezone identifier or offset where the date is definedadjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessary- Returns:
- the ISO 8601 formatted string
-
toIsoString
Get the ISO 8601 formatted representation of the givenTime
, which contains time but no date or timezone information.- Parameters:
time
- the JDBC time valuezoneId
- the timezone identifier or offset where the time is definedadjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessary- Returns:
- the ISO 8601 formatted string
-