Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-2269 Added ES support for offset/zoned date/time
- Loading branch information
Showing
9 changed files
with
271 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...nate/search/elasticsearch/bridge/builtin/time/impl/ElasticsearchOffsetDateTimeBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.bridge.builtin.time.impl; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
import java.time.format.DateTimeParseException; | ||
import java.time.format.ResolverStyle; | ||
import java.util.Locale; | ||
|
||
/** | ||
* Converts a {@link OffsetDateTime} to a {@link String} in ISO-8601 extended format (9 digits for the year instead of 4). | ||
* | ||
* <p>Be aware that this format is <strong>not</strong> the same as {@link DateTimeFormatter#ISO_OFFSET_DATE_TIME} | ||
* (mainly because of the second fraction field, which is at least 3 characters long), nor as Elasticsearch's | ||
* "strict_date_time" format (since years with more than 4 digits are allowed). | ||
* | ||
* @author Yoann Rodiere | ||
*/ | ||
public class ElasticsearchOffsetDateTimeBridge extends ElasticsearchTemporalAccessorStringBridge<OffsetDateTime> { | ||
|
||
static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() | ||
.append( ElasticsearchLocalDateTimeBridge.FORMATTER ) | ||
.appendOffsetId() | ||
.toFormatter( Locale.ROOT ) | ||
.withResolverStyle( ResolverStyle.STRICT ); | ||
|
||
public static final ElasticsearchOffsetDateTimeBridge INSTANCE = new ElasticsearchOffsetDateTimeBridge(); | ||
|
||
private ElasticsearchOffsetDateTimeBridge() { | ||
super( FORMATTER, OffsetDateTime.class ); | ||
} | ||
|
||
@Override | ||
OffsetDateTime parse(DateTimeFormatter formatter, String stringValue) throws DateTimeParseException { | ||
return OffsetDateTime.parse( stringValue, formatter ); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ibernate/search/elasticsearch/bridge/builtin/time/impl/ElasticsearchOffsetTimeBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.bridge.builtin.time.impl; | ||
|
||
import java.time.OffsetTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
import java.time.format.DateTimeParseException; | ||
import java.time.format.ResolverStyle; | ||
import java.util.Locale; | ||
|
||
/** | ||
* Converts a {@link OffsetTime} to a {@link String} in Elasticsearch's "strict_time" format. | ||
* | ||
* <p>Be aware that this format is <strong>not</strong> the same as {@link DateTimeFormatter#ISO_OFFSET_TIME} | ||
* (mainly because of the second fraction field, which is at least 3 characters long). | ||
* | ||
* @author Yoann Rodiere | ||
*/ | ||
public class ElasticsearchOffsetTimeBridge extends ElasticsearchTemporalAccessorStringBridge<OffsetTime> { | ||
|
||
private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() | ||
.append( ElasticsearchLocalTimeBridge.FORMATTER ) | ||
.appendOffsetId() | ||
.toFormatter( Locale.ROOT ) | ||
.withResolverStyle( ResolverStyle.STRICT ); | ||
|
||
public static final ElasticsearchOffsetTimeBridge INSTANCE = new ElasticsearchOffsetTimeBridge(); | ||
|
||
private ElasticsearchOffsetTimeBridge() { | ||
super( FORMATTER, OffsetTime.class ); | ||
} | ||
|
||
@Override | ||
OffsetTime parse(DateTimeFormatter formatter, String stringValue) throws DateTimeParseException { | ||
return OffsetTime.parse( stringValue, formatter ); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...rnate/search/elasticsearch/bridge/builtin/time/impl/ElasticsearchZonedDateTimeBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.bridge.builtin.time.impl; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
import java.time.format.DateTimeParseException; | ||
import java.time.format.ResolverStyle; | ||
import java.util.Locale; | ||
|
||
import org.hibernate.search.util.impl.TimeHelper; | ||
|
||
/** | ||
* Converts a {@link ZonedDateTime} to a {@link String} in ISO-8601 extended format (9 digits for the year instead of 4). | ||
* | ||
* <p>Be aware that this format is <strong>not</strong> the same as {@link DateTimeFormatter#ISO_ZONED_DATE_TIME} | ||
* (mainly because of the second fraction field, which is at least 3 characters long), nor as Elasticsearch's | ||
* "strict_date_time" format (since years with more than 4 digits are allowed, and both the zone ID and offset are displayed). | ||
* | ||
* @author Yoann Rodiere | ||
*/ | ||
public class ElasticsearchZonedDateTimeBridge extends ElasticsearchTemporalAccessorStringBridge<ZonedDateTime> { | ||
|
||
private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() | ||
.append( ElasticsearchOffsetDateTimeBridge.FORMATTER ) | ||
.appendLiteral( '[' ) | ||
.parseCaseSensitive() | ||
.appendZoneRegionId() | ||
.appendLiteral( ']' ) | ||
.toFormatter( Locale.ROOT ) | ||
.withResolverStyle( ResolverStyle.STRICT ); | ||
|
||
public static final ElasticsearchZonedDateTimeBridge INSTANCE = new ElasticsearchZonedDateTimeBridge(); | ||
|
||
private ElasticsearchZonedDateTimeBridge() { | ||
super( FORMATTER, ZonedDateTime.class ); | ||
} | ||
|
||
@Override | ||
ZonedDateTime parse(DateTimeFormatter formatter, String stringValue) throws DateTimeParseException { | ||
return TimeHelper.parseZoneDateTime( stringValue, formatter ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters