when using dates in scripts, initialize the dates (DateTime) with UTC

This commit is contained in:
kimchy 2010-12-19 05:01:59 +02:00
parent 96a2950ab5
commit 8dfc3acba0
3 changed files with 6 additions and 3 deletions

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.field.data.longs;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.FieldCache;
import org.elasticsearch.common.joda.time.DateTimeZone;
import org.elasticsearch.common.joda.time.MutableDateTime; import org.elasticsearch.common.joda.time.MutableDateTime;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.common.trove.TLongArrayList; import org.elasticsearch.common.trove.TLongArrayList;
@ -40,7 +41,7 @@ public abstract class LongFieldData extends NumericFieldData<LongDocFieldData> {
private ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime>> dateTimeCache = new ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime>>() { private ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime>> dateTimeCache = new ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime>>() {
@Override protected ThreadLocals.CleanableValue<MutableDateTime> initialValue() { @Override protected ThreadLocals.CleanableValue<MutableDateTime> initialValue() {
return new ThreadLocals.CleanableValue<MutableDateTime>(new MutableDateTime()); return new ThreadLocals.CleanableValue<MutableDateTime>(new MutableDateTime(DateTimeZone.UTC));
} }
}; };

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.longs; package org.elasticsearch.index.field.data.longs;
import org.elasticsearch.common.joda.time.DateTimeZone;
import org.elasticsearch.common.joda.time.MutableDateTime; import org.elasticsearch.common.joda.time.MutableDateTime;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
@ -46,7 +47,7 @@ public class MultiValueLongFieldData extends LongFieldData {
for (int i = 0; i < value.length; i++) { for (int i = 0; i < value.length; i++) {
value[i] = new MutableDateTime[i]; value[i] = new MutableDateTime[i];
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
value[i][j] = new MutableDateTime(); value[i][j] = new MutableDateTime(DateTimeZone.UTC);
} }
} }
return new ThreadLocals.CleanableValue<MutableDateTime[][]>(value); return new ThreadLocals.CleanableValue<MutableDateTime[][]>(value);

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.longs; package org.elasticsearch.index.field.data.longs;
import org.elasticsearch.common.joda.time.DateTimeZone;
import org.elasticsearch.common.joda.time.MutableDateTime; import org.elasticsearch.common.joda.time.MutableDateTime;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
@ -37,7 +38,7 @@ public class SingleValueLongFieldData extends LongFieldData {
private ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime[]>> datesValuesCache = new ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime[]>>() { private ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime[]>> datesValuesCache = new ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime[]>>() {
@Override protected ThreadLocals.CleanableValue<MutableDateTime[]> initialValue() { @Override protected ThreadLocals.CleanableValue<MutableDateTime[]> initialValue() {
MutableDateTime[] date = new MutableDateTime[1]; MutableDateTime[] date = new MutableDateTime[1];
date[0] = new MutableDateTime(); date[0] = new MutableDateTime(DateTimeZone.UTC);
return new ThreadLocals.CleanableValue<MutableDateTime[]>(date); return new ThreadLocals.CleanableValue<MutableDateTime[]>(date);
} }
}; };