mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1684 - Fix JSON marshalling on LocalDate, sql.Date etc - explicit UTC
Make explicit use of UTC
This commit is contained in:
1 parent
25e6d05542
commit
c46ac04c0a
10 files changed
+34
-32
No files matched your search
@@ -97,12 +97,10 @@ public abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator writer, T value) throws IOException {
|
||||
switch(mode) {
|
||||
case ISO8601:
|
||||
writer.writeString(toIsoFormat(value));
|
||||
break;
|
||||
default:
|
||||
writer.writeNumber(convertToMillis(value));
|
||||
if (mode == JsonConfig.Date.ISO8601) {
|
||||
writer.writeString(toIsoFormat(value));
|
||||
} else {
|
||||
writer.writeNumber(convertToMillis(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
import java.sql.Date;
|
||||
@@ -28,7 +29,7 @@ public class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
|
||||
@Override
|
||||
public long convertToMillis(LocalDate value) {
|
||||
return value.toDateTimeAtStartOfDay().getMillis();
|
||||
return value.toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
@@ -23,9 +23,14 @@ public class ScalarTypeLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate convertFromMillis(long systemTimeMillis) {
|
||||
return new Timestamp(systemTimeMillis).toLocalDateTime().toLocalDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(LocalDate value) {
|
||||
ZonedDateTime zonedDateTime = value.atStartOfDay(ZoneId.systemDefault());
|
||||
ZonedDateTime zonedDateTime = value.atStartOfDay(ZoneOffset.UTC);
|
||||
return zonedDateTime.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
@@ -55,9 +60,4 @@ public class ScalarTypeLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
return (LocalDate) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate convertFromMillis(long systemTimeMillis) {
|
||||
return new Timestamp(systemTimeMillis).toLocalDateTime().toLocalDate();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
@@ -25,7 +25,7 @@ public class ScalarTypeYearMonthDate extends ScalarTypeBaseDate<YearMonth> {
|
||||
}
|
||||
|
||||
protected LocalDate toLocalDate(YearMonth yearMonth) {
|
||||
return LocalDate.of(yearMonth.getYear(), yearMonth.getMonth(), 1);
|
||||
return yearMonth.atDay(1);
|
||||
}
|
||||
|
||||
protected YearMonth fromLocalDate(LocalDate localDate) {
|
||||
@@ -39,8 +39,7 @@ public class ScalarTypeYearMonthDate extends ScalarTypeBaseDate<YearMonth> {
|
||||
|
||||
@Override
|
||||
public long convertToMillis(YearMonth value) {
|
||||
LocalDate localDate = toLocalDate(value);
|
||||
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
|
||||
ZonedDateTime zonedDateTime = value.atDay(1).atStartOfDay(ZoneOffset.UTC);
|
||||
return zonedDateTime.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user