mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
#2165 - Joda LocalDate West of UTC converts incorrectly (Fix: change from epoc millis conversion to y/m/d conversion)
This commit is contained in:
1 parent
d567872813
commit
9e3d6c6a08
2 files changed
+21
-2
No files matched your search
@@ -37,9 +37,10 @@ public class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
return LocalDate.fromDateFields(date);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Date convertToDate(LocalDate value) {
|
||||
return new java.sql.Date(convertToMillis(value));
|
||||
return new Date(value .getYear() - 1900, value .getMonthOfYear() - 1, value .getDayOfMonth());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,7 +54,7 @@ public class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
@Override
|
||||
public LocalDate toBeanType(Object value) {
|
||||
if (value instanceof java.util.Date) {
|
||||
return convertFromMillis(((java.util.Date) value).getTime());
|
||||
return LocalDate.fromDateFields((java.util.Date)value);
|
||||
}
|
||||
return (LocalDate) value;
|
||||
}
|
||||
|
||||
+18
@@ -6,6 +6,7 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -24,12 +25,29 @@ public class ScalarTypeJodaLocalDateTest {
|
||||
assertThat(localDate).isEqualTo(localDate1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertToDate_convertFromDate_westOfUtc() {
|
||||
final TimeZone originaDefaultTimezone = TimeZone.getDefault();
|
||||
try {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
||||
|
||||
convertDate(new LocalDate());
|
||||
convertDate(new LocalDate(1899, 12, 1));
|
||||
convertDate(new LocalDate(1900, 1, 1));
|
||||
convertDate(new LocalDate(2021, 2, 8));
|
||||
|
||||
} finally {
|
||||
TimeZone.setDefault(originaDefaultTimezone);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertToDate_convertFromDate() {
|
||||
|
||||
convertDate(new LocalDate());
|
||||
convertDate(new LocalDate(1899, 12, 1));
|
||||
convertDate(new LocalDate(1900, 1, 1));
|
||||
convertDate(new LocalDate(2021, 2, 8));
|
||||
}
|
||||
|
||||
private void convertDate(LocalDate localDate) {
|
||||
|
||||
Reference in new issue
Block a user