Reputation: 1332
I have a simple NEST query with DateRanges predicate:
DateTimeOffset dt;
...
.DateRange(r => r
.Field("Time")
.LessThanOrEquals(dt)
According to this question, simply converting DateTimeOffset
to DateTime
might cause data loss. LessThanOrEquals
and other predicate methods accept object of the Nest.DateMath
type, which has the following operators:
public static implicit operator DateMath(DateTime dateTime);
public static implicit operator DateMath(string dateMath);
In addition DateRangeQueryDescriptor
has an additional method:
public DateRangeQueryDescriptor<T> TimeZone(string timeZone);
but I'm not sure how to use it.
QUESTION:
How can I use a DateTimeOffset
object as a value for DateRange
predicate in NEST
and be sure that the dates sent to Elastic are the correct ones?
Upvotes: 3
Views: 1598
Reputation: 1332
Apparently, I was wrong.
According to this and this, all dates are stored or must be stored as UTC, thus the range parameters should be passed as UTC as well.
Internally, dates are converted to UTC (if the time-zone is specified) and stored as a long number representing milliseconds-since-the-epoch.
Upvotes: 3