mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-31 09:12:11 +00:00
parent
e49f140233
commit
0afa37c8ea
@ -3,6 +3,9 @@ package org.springframework.data.elasticsearch.core.convert;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
@ -52,21 +55,25 @@ class ElasticsearchDateConverterTests {
|
||||
|
||||
@Test // DATAES-792
|
||||
void shouldConvertLegacyDateToString() {
|
||||
Date date = new GregorianCalendar(2020, 3, 19, 21, 44).getTime();
|
||||
GregorianCalendar calendar = GregorianCalendar
|
||||
.from(ZonedDateTime.of(LocalDateTime.of(2020, 04, 19, 19, 44), ZoneId.of("UTC")));
|
||||
Date legacyDate = calendar.getTime();
|
||||
ElasticsearchDateConverter converter = ElasticsearchDateConverter.of(DateFormat.basic_date_time);
|
||||
|
||||
String formatted = converter.format(date);
|
||||
String formatted = converter.format(legacyDate);
|
||||
|
||||
assertThat(formatted).isEqualTo("20200419T194400.000Z");
|
||||
}
|
||||
|
||||
@Test // DATAES-792
|
||||
void shouldParseLegacyDateFromString() {
|
||||
Date date = new GregorianCalendar(2020, 3, 19, 21, 44).getTime();
|
||||
GregorianCalendar calendar = GregorianCalendar
|
||||
.from(ZonedDateTime.of(LocalDateTime.of(2020, 04, 19, 19, 44), ZoneId.of("UTC")));
|
||||
Date legacyDate = calendar.getTime();
|
||||
ElasticsearchDateConverter converter = ElasticsearchDateConverter.of(DateFormat.basic_date_time);
|
||||
|
||||
Date parsed = converter.parse("20200419T194400.000Z");
|
||||
|
||||
assertThat(parsed).isEqualTo(date);
|
||||
assertThat(parsed).isEqualTo(legacyDate);
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,11 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||
@ -114,7 +117,9 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
|
||||
void shouldConvertFromLegacyDate() {
|
||||
SimpleElasticsearchPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DatesProperty.class);
|
||||
ElasticsearchPersistentProperty persistentProperty = persistentEntity.getRequiredPersistentProperty("legacyDate");
|
||||
Date legacyDate = new GregorianCalendar(2020, 3, 19, 21, 44).getTime();
|
||||
GregorianCalendar calendar = GregorianCalendar
|
||||
.from(ZonedDateTime.of(LocalDateTime.of(2020, 4, 19, 19, 44), ZoneId.of("UTC")));
|
||||
Date legacyDate = calendar.getTime();
|
||||
|
||||
String converted = persistentProperty.getPropertyConverter().write(legacyDate);
|
||||
|
||||
@ -129,7 +134,10 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
|
||||
Object converted = persistentProperty.getPropertyConverter().read("20200419T194400.000Z");
|
||||
|
||||
assertThat(converted).isInstanceOf(Date.class);
|
||||
assertThat(converted).isEqualTo(new GregorianCalendar(2020, 3, 19, 21, 44).getTime());
|
||||
GregorianCalendar calendar = GregorianCalendar
|
||||
.from(ZonedDateTime.of(LocalDateTime.of(2020, 4, 19, 19, 44), ZoneId.of("UTC")));
|
||||
Date legacyDate = calendar.getTime();
|
||||
assertThat(converted).isEqualTo(legacyDate);
|
||||
}
|
||||
|
||||
static class InvalidScoreProperty {
|
||||
|
Loading…
x
Reference in New Issue
Block a user