You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by GitBox <gi...@apache.org> on 2022/06/25 06:37:16 UTC

[GitHub] [lucenenet] NightOwl888 commented on issue #639: Custom Filter

NightOwl888 commented on issue #639:
URL: https://github.com/apache/lucenenet/issues/639#issuecomment-1166205112

   Time zone support has been added in #551 and #580 which has been included since 4.8.0-beta00016.
   
   It isn't clear from your question whether you are using [`DateTools`](https://lucenenet.apache.org/docs/4.8.0-beta00016/api/core/Lucene.Net.Documents.DateTools.html) to make the conversions, but there are built-in options for storing dates in the index:
   
   1. As a number representing milliseconds since the Unix Epoch (Milliseconds since Jan 1, 1970 12:00:00 AM UTC.).
   2. As a number representing the number or .NET Ticks.
   3. As a string in the format `yyyyMMddHHmmssSSS`.
   
   `DateTools`also allows you to reduce the resolution of the date in certain cases, for example, when the seconds or time component is not important for the search.
   
   As for the time zone, it only really matters if you store the date as a string because numeric dates do not include time zone info, they are always stored as UTC. When you search, your query needs to be built with UTC dates. This can be done using the [classic](https://lucenenet.apache.org/docs/4.8.0-beta00016/api/queryparser/Lucene.Net.QueryParsers.Classic.html) or [flexible query parser](https://lucenenet.apache.org/docs/4.8.0-beta00016/api/queryparser/overview.html#flexible).
   
   The most common way of dealing with time zones in .NET is to create `DateTime` instances using `DateTimeKind.Local` or `DateTimeKind.Utc`, both of which can be converted to the other. However, if you don't specify what the date is, it will be created with `DateTimeKind.Unspecified` and will assumed to be local time whether or not you intended that.
   
   https://docs.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones
   
   Using the built-in logic assumes that `DateTimeKind.Local` is the time zone you are converting to, and it should work for most scenarios (I suspect web apps adjust it automatically based on the user's time zone, although I haven't tested that scenario). However, both [`DateTools`](https://lucenenet.apache.org/docs/4.8.0-beta00016/api/core/Lucene.Net.Documents.DateTools.html#Lucene_Net_Documents_DateTools_DateToString_System_DateTime_System_TimeZoneInfo_Lucene_Net_Documents_DateResolution_) and [flexible query parser](https://lucenenet.apache.org/docs/4.8.0-beta00016/api/queryparser/Lucene.Net.QueryParsers.Flexible.Standard.ICommonQueryParserConfiguration.html#Lucene_Net_QueryParsers_Flexible_Standard_ICommonQueryParserConfiguration_TimeZone) support setting the current time zone explicitly for scenarios where your computer's local time zone is set to one time zone and you want to search using a different time zone.  Of course, using `DateTools`, the time zone info (and DST by exte
 nsion) doesn't matter unless you are storing the dates in the index as a string. 
   
   If you store the dates in the index as numbers, the only place time zone matters is when you are building the query to search the index, in which case you will need to convert the date from local time zone to UTC before performing the search. And when you do that, .NET will take care of the DST part automatically as part of the time zone conversion from local time.
   
   
   
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org